def __init__(self, client=None, messages=None):
        """Initialize a release.ReleaseClient.

    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.messages = messages or client_util.GetMessagesModule(client)
        self._service = self.client.projects_locations_deliveryPipelines_releases_rollouts
Exemple #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
        self._target_service = self.client.projects_locations_deliveryPipelines_targets
def CreateReleaseConfig(source, gcs_source_staging_dir, ignore_file, images,
                        build_artifacts, description, skaffold_version,
                        skaffold_file, location):
  """Returns a build config."""
  _VerifySkaffoldFileExists(source, skaffold_file)
  messages = client_util.GetMessagesModule(client_util.GetClientInstance())
  release_config = messages.Release()
  release_config.description = description
  release_config = _SetSkaffoldConfigPath(release_config, skaffold_file)
  release_config = _SetSource(release_config, source, gcs_source_staging_dir,
                              ignore_file, skaffold_version, location)
  release_config = _SetImages(messages, release_config, images, build_artifacts)
  return release_config
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())