예제 #1
0
    def Run(self, args):
        target_ref = args.CONCEPTS.target.Parse()
        # Check if target exists
        target_util.GetTarget(target_ref)

        current_release_ref, rollback_release_ref = _GetCurrentAndRollbackRelease(
            args.release, args.delivery_pipeline, target_ref)
        try:
            release_obj = release.ReleaseClient().Get(
                rollback_release_ref.RelativeName())
        except apitools_exceptions.HttpError as error:
            raise exceptions.HttpException(error)

        prompt = 'Rolling back target {} to release {}.\n\n'.format(
            target_ref.Name(), rollback_release_ref.Name())
        release_util.PrintDiff(rollback_release_ref, release_obj,
                               target_ref.Name(), prompt)

        console_io.PromptContinue(cancel_on_no=True)

        rollout_description = args.description or 'Rollback from {}'.format(
            current_release_ref.Name())
        return promote_util.Promote(rollback_release_ref,
                                    release_obj,
                                    target_ref.Name(),
                                    False,
                                    args.rollout_id,
                                    description=rollout_description)
  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()
    target_obj = target_util.GetTarget(target_ref)
    manifest = manifest_util.ProtoToManifest(target_obj, target_ref,
                                             manifest_util.TARGET_KIND_V1BETA1)

    export_util.Export(manifest, args)
def DiffSnappedPipeline(release_ref, release_obj, to_target=None):
  """Detects the differences between current delivery pipeline and target definitions, from those associated with the release being promoted.

  Changes are determined through etag value differences.

  This runs the following checks:
    - if the to_target is one of the snapped targets in the release.
    - if the snapped targets still exist.
    - if the snapped targets have been changed.
    - if the snapped pipeline still exists.
    - if the snapped pipeline has been changed.

  Args:
    release_ref: protorpc.messages.Message, release resource object.
    release_obj: apitools.base.protorpclite.messages.Message, release message.
    to_target: str, the target to promote the release to. If specified, this
      verifies if the target has been snapped in the release.

  Returns:
    the list of the resources that no longer exist.
    the list of the resources that have been changed.
    the list of the resources that aren't snapped in the release.
  """
  resource_not_found = []
  resource_changed = []
  resource_created = []
  # check if the to_target is one of the snapped targets in the release.
  if to_target:
    ref_dict = release_ref.AsDict()
    # Creates shared target by default.
    target_ref = target_util.TargetReference(
        to_target,
        ref_dict['projectsId'],
        ref_dict['locationsId'],
    )
    # Only compare the resource ID, for the case that
    # if release_ref is parsed from arguments, it will use project ID,
    # whereas, the project number is stored in the DB.

    if target_ref.Name() not in [
        target_util.TargetId(obj.name) for obj in release_obj.targetSnapshots
    ]:
      resource_created.append(target_ref.RelativeName())

  for obj in release_obj.targetSnapshots:
    target_name = obj.name
    # Check if the snapped targets still exist.
    try:
      target_obj = target_util.GetTarget(
          target_util.TargetReferenceFromName(target_name))
      # Checks if the snapped targets have been changed.
      if target_obj.etag != obj.etag:
        resource_changed.append(target_name)
    except apitools_exceptions.HttpError as error:
      log.debug('Failed to get target {}: {}'.format(target_name, error))
      log.status.Print('Unable to get target {}\n'.format(target_name))
      resource_not_found.append(target_name)

  name = release_obj.deliveryPipelineSnapshot.name
  # Checks if the pipeline exists.
  try:
    pipeline_obj = delivery_pipeline.DeliveryPipelinesClient().Get(name)
    # Checks if the pipeline has been changed.
    if pipeline_obj.etag != release_obj.deliveryPipelineSnapshot.etag:
      resource_changed.append(release_ref.Parent().RelativeName())
  except apitools_exceptions.HttpError as error:
    log.debug('Failed to get pipeline {}: {}'.format(name, error.content))
    log.status.Print('Unable to get delivery pipeline {}'.format(name))
    resource_not_found.append(name)

  return resource_created, resource_changed, resource_not_found