Exemplo n.º 1
0
 def IsDone(self, operation):
     finished = False
     try:
         finished = (operation["metadata"]["state"] == "FINISHED")
     except KeyError as err:
         raise waiter.OperationError("Malformed operation; %s\n%r" %
                                     (err, operation))
     if finished and "error" in operation:
         raise errors.RequestError("operation", {"name": operation["name"]},
                                   "await",
                                   body=json.dumps(operation))
     return finished
Exemplo n.º 2
0
    def _GetUploadUrl(self, identifiers):
        """Gets the signed URL for uploading the archive deployment.

    Args:
      identifiers: A dict of resource identifers. Must contain "organizationsId"
        and "environmentsId"

    Returns:
      A str of the upload URL.

    Raises:
      googlecloudsdk.command_lib.apigee.errors.RequestError if the "uploadUri"
        field is not included in the GetUploadUrl response.
    """
        get_upload_url_resp = apigee.ArchivesClient.GetUploadUrl(identifiers)
        if "uploadUri" not in get_upload_url_resp:
            raise errors.RequestError(resource_type="getUploadUrl",
                                      resource_identifier=identifiers,
                                      body=get_upload_url_resp,
                                      user_help="Please try again.")
        return get_upload_url_resp["uploadUri"]
Exemplo n.º 3
0
 def Run(self, args):
     """Run the deploy command."""
     identifiers = args.CONCEPTS.environment.Parse().AsDict()
     # Using as a context manager automatically cleans up the temp file on exit.
     with cmd_lib.LocalDirectoryArchive(args.source) as local_dir_archive:
         zip_file_path = local_dir_archive.Zip()
         get_upload_url_resp = apigee.ArchivesClient.GetUploadUrl(
             identifiers)
         if "uploadUri" not in get_upload_url_resp:
             raise errors.RequestError(resource_type="getUploadUrl",
                                       resource_identifier=identifiers,
                                       body=get_upload_url_resp,
                                       user_help="Please try again.")
         upload_url = get_upload_url_resp["uploadUri"]
         # HTTP PUT request to upload the local archive to GCS.
         upload_archive_resp = cmd_lib.UploadArchive(
             upload_url, zip_file_path)
         if not upload_archive_resp.ok:
             raise errors.HttpRequestError(
                 upload_archive_resp.status_code,
                 upload_archive_resp.reason, upload_archive_resp.url,
                 upload_archive_resp.request.method)
         # CreateArchiveDeployment starts an LRO.
         create_archive_deployment_resp = \
             apigee.ArchivesClient.CreateArchiveDeployment(identifiers, upload_url)
         operation = apigee.OperationsClient.SplitName(
             create_archive_deployment_resp)
         if "organization" not in operation or "uuid" not in operation:
             raise waiter.OperationError(
                 "Unknown operation response: {}".format(operation))
         if args.async_:
             return operation
         log.info("Started archives deploy operation %s", operation["name"])
         waiter.WaitFor(
             apigee.LROPoller(operation["organization"]),
             operation["uuid"],
             message="Waiting for operation [{}] to complete".format(
                 operation["uuid"]))
Exemplo n.º 4
0
 def testIncompleteEntityDefinition(self):
     error = errors.RequestError()
     self.assertIn(
         "Failed to access resource", str(error),
         "Generic request error must say something human readable.")