Esempio n. 1
0
    def Run(self, args):
        """This is what gets called when the user runs this command."""
        args.CONCEPTS.parsed_args.release = release_util.RenderPattern(
            args.CONCEPTS.parsed_args.release)
        release_ref = args.CONCEPTS.release.Parse()
        client = release.ReleaseClient()
        # Create the release create request.
        release_config = release_util.CreateReleaseConfig(
            args.source, args.gcs_source_staging_dir, args.ignore_file,
            args.images, args.build_artifacts, args.description,
            args.skaffold_version, args.skaffold_file,
            release_ref.AsDict()['locationsId'])
        deploy_util.SetMetadata(client.messages, release_config,
                                deploy_util.ResourceType.RELEASE,
                                args.annotations, args.labels)
        operation = client.Create(release_ref, release_config)
        operation_ref = resources.REGISTRY.ParseRelativeName(
            operation.name,
            collection='clouddeploy.projects.locations.operations')
        client_util.OperationsClient().WaitForOperation(
            operation, operation_ref)

        log.status.Print('Created Cloud Deploy release {}.'.format(
            release_ref.Name()))

        release_obj = release.ReleaseClient().Get(release_ref.RelativeName())
        rollout_resource = promote_util.Promote(release_ref, release_obj,
                                                args.to_target, True)
        return release_obj, rollout_resource
Esempio n. 2
0
    def __init__(self, client=None, messages=None):
        """Initialize a deploy.DeployClient.

    Args:
      client: base_api.BaseApiClient, the client class for Cloud Deploy.
      messages: module containing the definitions of messages for Cloud Deploy.
    """
        self.client = client or client_util.GetClientInstance()
        self.operation_client = client_util.OperationsClient()
        self.messages = messages or client_util.GetMessagesModule(client)
        self._pipeline_service = self.client.projects_locations_deliveryPipelines
    def Run(self, args):
        """Entry point of the export command.

    Args:
      args: argparse.Namespace, An object that contains the values for the
        arguments specified in the .Args() method.
    """
        target_ref = args.CONCEPTS.target.Parse()
        op = target_util.DeleteTarget(target_ref.RelativeName())
        client_util.OperationsClient().CheckOperationStatus(
            {target_ref.RelativeName(): op},
            'Deleted Cloud Deploy target: {}.')
def CreateRollout(release_ref,
                  to_target,
                  rollout_id=None,
                  annotations=None,
                  labels=None,
                  description=None):
    """Creates a rollout by calling the rollout create API and waits for the operation to finish.

  Args:
    release_ref: protorpc.messages.Message, release resource object.
    to_target: str, the target to create create the rollout in.
    rollout_id: str, rollout ID.
    annotations: dict[str,str], a dict of annotation (key,value) pairs that
      allow clients to store small amounts of arbitrary data in cloud deploy
      resources.
    labels: dict[str,str], a dict of label (key,value) pairs that can be used to
      select cloud deploy resources and to find collections of cloud deploy
      resources that satisfy certain conditions.
    description: str, rollout description.

  Raises:
      ListRolloutsError: an error occurred calling rollout list API.

  Returns:
    The rollout resource created.
  """
    final_rollout_id = rollout_id
    if not final_rollout_id:
        filter_str = ROLLOUT_IN_TARGET_FILTER_TEMPLATE.format(to_target)
        try:
            rollouts = rollout.RolloutClient().List(release_ref.RelativeName(),
                                                    filter_str)
            final_rollout_id = ComputeRolloutID(release_ref.Name(), to_target,
                                                rollouts)
        except apitools_exceptions.HttpError:
            raise cd_exceptions.ListRolloutsError(release_ref.RelativeName())

    resource_dict = release_ref.AsDict()
    rollout_ref = resources.REGISTRY.Parse(
        final_rollout_id,
        collection=_ROLLOUT_COLLECTION,
        params={
            'projectsId': resource_dict.get('projectsId'),
            'locationsId': resource_dict.get('locationsId'),
            'deliveryPipelinesId': resource_dict.get('deliveryPipelinesId'),
            'releasesId': release_ref.Name(),
        })
    rollout_obj = client_util.GetMessagesModule().Rollout(
        name=rollout_ref.RelativeName(),
        targetId=to_target,
        description=description)

    log.status.Print('Creating rollout {} in target {}'.format(
        rollout_ref.RelativeName(), to_target))
    operation = rollout.RolloutClient().Create(rollout_ref, rollout_obj,
                                               annotations, labels)
    operation_ref = resources.REGISTRY.ParseRelativeName(
        operation.name, collection='clouddeploy.projects.locations.operations')

    client_util.OperationsClient().WaitForOperation(
        operation, operation_ref,
        'Waiting for rollout creation operation to complete')
    return rollout.RolloutClient().Get(rollout_ref.RelativeName())