def authenticate(keyfile, password, email, start, attempts)
      # OAuth authentication, using the service account
      key = ::Google::APIClient::PKCS12.load_key(keyfile, password)
      service_account = ::Google::APIClient::JWTAsserter.new(
          email,
          AUTH_URL,
          key)
      try = (Time.now - start) / SLEEPWAIT
      while try <= attempts
        begin
          @client.authorization = service_account.authorize
          @logger.debug("Authorized to use Google Compute")
          return
        rescue => e
          @logger.debug("Failed to authorize to use Google Compute")
          if try >= attempts
            raise e
          end
        end
        try += 1
      end
    end
def authenticate(keyfile, password, email, start, attempts)
      # OAuth authentication, using the service account
      key = ::Google::APIClient::PKCS12.load_key(keyfile, password)
      service_account = ::Google::APIClient::JWTAsserter.new(
          email,
          AUTH_URL,
          key)
      try = (Time.now - start) / SLEEPWAIT
      while try <= attempts
        begin
          @client.authorization = service_account.authorize
          @logger.debug("Authorized to use Google Compute")
          return
        rescue => e
          @logger.debug("Failed to authorize to use Google Compute")
          if try >= attempts
            raise e
          end
        end
        try += 1
      end
    end
Creates an authenticated connection to the Google Compute Engine API

 @param [String] keyfile The location of the Google Compute Service
 Account keyfile to use for authentication

 @param [String] password The password for the provided Google Compute
 Service Account key

 @param [String] email The email address of the Google Compute Service
 Account we are using to connect

 @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 create an authenticated
 connection to the Google Compute API, either through errors or running
 out of attempts