def execute req, start, attempts
      last_error = parsed = nil
      try = (Time.now - start) / SLEEPWAIT
      while try <= attempts
        begin
          result = @client.execute(req)
          parsed = JSON.parse(result.body)
          if not result.success?
            error_code = parsed["error"] ? parsed["error"]["code"] : 0
            if error_code == 404
              raise GoogleComputeError, "Resource Not Found: #{result.body}"
            elsif error_code == 400
              raise GoogleComputeError, "Bad Request: #{result.body}"
            else
              raise GoogleComputeError, "Error attempting Google Compute API execute: #{result.body}"
            end
          end
          return parsed
        # retry errors
        rescue Faraday::Error::ConnectionFailed => e
          @logger.debug "ConnectionFailed attempting Google Compute execute command"
          try += 1
          last_error = e
        end
      end
      # we only get down here if we've used up all our tries
      raise last_error
    end
def execute req, start, attempts
      last_error = parsed = nil
      try = (Time.now - start) / SLEEPWAIT
      while try <= attempts
        begin
          result = @client.execute(req)
          parsed = JSON.parse(result.body)
          if not result.success?
            error_code = parsed["error"] ? parsed["error"]["code"] : 0
            if error_code == 404
              raise GoogleComputeError, "Resource Not Found: #{result.body}"
            elsif error_code == 400
              raise GoogleComputeError, "Bad Request: #{result.body}"
            else
              raise GoogleComputeError, "Error attempting Google Compute API execute: #{result.body}"
            end
          end
          return parsed
        # retry errors
        rescue Faraday::Error::ConnectionFailed => e
          @logger.debug "ConnectionFailed attempting Google Compute execute command"
          try += 1
          last_error = e
        end
      end
      # we only get down here if we've used up all our tries
      raise last_error
    end
Executes a provided Google Compute request using a previously configured
 and authenticated Google Compute client connection

 @param [Hash] req A correctly formatted Google Compute request object

 @param [Integer] start The time when we started code execution, it is
 compared to Time.now to determine how many further code execution
 attempts remain
 @param [Integer] attempts The total amount of attempts to execute that we
 are willing to allow

 @raise [Exception] Raised if we fail to execute the request, either
 through errors or running out of attempts