示例#1
0
    def Run(self, args):
        """Run 'manifests describe'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      The requested manifest.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    """
        if not args.manifest:
            try:
                deployment = self.client.deployments.Get(
                    self.messages.DeploymentmanagerDeploymentsGetRequest(
                        project=self.project, deployment=args.deployment))
            except apitools_exceptions.HttpError as error:
                raise exceptions.HttpException(error)

            manifest = dm_v2_util.ExtractManifestName(deployment)
            if manifest:
                args.manifest = manifest

        try:
            return self.client.manifests.Get(
                self.messages.DeploymentmanagerManifestsGetRequest(
                    project=self.project,
                    deployment=args.deployment,
                    manifest=args.manifest,
                ))
        except apitools_exceptions.HttpError as error:
            raise exceptions.HttpException(error, dm_v2_util.HTTP_ERROR_FORMAT)
    def Run(self, args):
        """Run 'deployments describe'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      The requested Deployment.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    """
        client = self.context['deploymentmanager-client']
        messages = self.context['deploymentmanager-messages']
        project = properties.VALUES.core.project.Get(required=True)

        try:
            deployment = client.deployments.Get(
                messages.DeploymentmanagerDeploymentsGetRequest(
                    project=project, deployment=args.deployment_name))
        except apitools_exceptions.HttpError as error:
            raise exceptions.HttpException(error, dm_v2_util.HTTP_ERROR_FORMAT)

        # Get resources belonging to the deployment to display
        project = properties.VALUES.core.project.Get(required=True)
        try:
            response = client.resources.List(
                messages.DeploymentmanagerResourcesListRequest(
                    project=project, deployment=deployment.name))
            resources = response.resources
        except apitools_exceptions.HttpError:
            # Couldn't get resources, skip adding them to the table.
            # TODO(user): Why not raise HTTP exception here?
            resources = None

        outputs = []

        manifest = dm_v2_util.ExtractManifestName(deployment)

        if manifest:
            manifest_response = client.manifests.Get(
                messages.DeploymentmanagerManifestsGetRequest(
                    project=project,
                    deployment=args.deployment_name,
                    manifest=manifest,
                ))
            outputs = dm_v2_util.FlattenLayoutOutputs(manifest_response.layout)

        return _Results(deployment, resources, outputs)
示例#3
0
    def Run(self, args):
        """Run 'deployments describe'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      The requested Deployment.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    """
        try:
            deployment = dm_base.GetClient().deployments.Get(
                dm_base.GetMessages().DeploymentmanagerDeploymentsGetRequest(
                    project=dm_base.GetProject(),
                    deployment=args.deployment_name))
        except apitools_exceptions.HttpError as error:
            raise exceptions.HttpException(error, dm_v2_util.HTTP_ERROR_FORMAT)

        try:
            response = dm_base.GetClient().resources.List(
                dm_base.GetMessages().DeploymentmanagerResourcesListRequest(
                    project=dm_base.GetProject(), deployment=deployment.name))
            resources = response.resources
        except apitools_exceptions.HttpError:
            # Couldn't get resources, skip adding them to the table.
            resources = None

        outputs = []

        manifest = dm_v2_util.ExtractManifestName(deployment)

        if manifest:
            manifest_response = dm_base.GetClient().manifests.Get(
                dm_base.GetMessages().DeploymentmanagerManifestsGetRequest(
                    project=dm_base.GetProject(),
                    deployment=args.deployment_name,
                    manifest=manifest,
                ))
            # We might be lacking a layout if the manifest failed expansion.
            if manifest_response.layout:
                outputs = dm_v2_util.FlattenLayoutOutputs(
                    manifest_response.layout)

        return _Results(deployment, resources, outputs)
    def Run(self, args):
        """Run 'deployments update'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      If --async=true, returns Operation to poll.
      Else, returns a struct containing the list of resources and list of
        outputs in the deployment.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    """
        deployment = dm_base.GetMessages().Deployment(
            name=args.deployment_name, )

        if args.config:
            deployment.target = importer.BuildTargetConfig(
                dm_base.GetMessages(), args.config, args.properties)
        elif (self.ReleaseTrack()
              in [base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA]
              and args.manifest_id):
            deployment.target = importer.BuildTargetConfigFromManifest(
                dm_base.GetClient(), dm_base.GetMessages(),
                dm_base.GetProject(), args.deployment_name, args.manifest_id,
                args.properties)
        # Get the fingerprint from the deployment to update.
        try:
            current_deployment = dm_base.GetClient().deployments.Get(
                dm_base.GetMessages().DeploymentmanagerDeploymentsGetRequest(
                    project=dm_base.GetProject(),
                    deployment=args.deployment_name))
            # Update the labels of the deployment
            if self.ReleaseTrack() in [base.ReleaseTrack.ALPHA]:
                update_labels = labels_util.GetUpdateLabelsDictFromArgs(args)
                remove_labels = labels_util.GetRemoveLabelsListFromArgs(args)
                current_labels = current_deployment.labels

                deployment.labels = dm_labels.UpdateLabels(
                    current_labels,
                    dm_base.GetMessages().DeploymentLabelEntry, update_labels,
                    remove_labels)

                # If no config or manifest_id are specified, but try to update labels,
                # only get current manifest when it is not a preveiw request
                if not args.config and not args.manifest_id:
                    if args.update_labels or args.remove_labels:
                        if not args.preview:
                            current_manifest = dm_v2_util.ExtractManifestName(
                                current_deployment)
                            deployment.target = importer.BuildTargetConfigFromManifest(
                                dm_base.GetClient(), dm_base.GetMessages(),
                                dm_base.GetProject(), args.deployment_name,
                                current_manifest)

            # If no fingerprint is present, default to an empty fingerprint.
            # This empty default can be removed once the fingerprint change is
            # fully implemented and all deployments have fingerprints.
            deployment.fingerprint = current_deployment.fingerprint or ''
            if args.description is None:
                deployment.description = current_deployment.description
            elif not args.description or args.description.isspace():
                deployment.description = None
            else:
                deployment.description = args.description
        except apitools_exceptions.HttpError as error:
            raise exceptions.HttpException(error, dm_v2_util.HTTP_ERROR_FORMAT)

        try:
            operation = dm_base.GetClient().deployments.Update(
                dm_base.GetMessages(
                ).DeploymentmanagerDeploymentsUpdateRequest(
                    deploymentResource=deployment,
                    project=dm_base.GetProject(),
                    deployment=args.deployment_name,
                    preview=args.preview,
                    createPolicy=(dm_base.GetMessages(
                    ).DeploymentmanagerDeploymentsUpdateRequest.
                                  CreatePolicyValueValuesEnum(
                                      args.create_policy)),
                    deletePolicy=(dm_base.GetMessages(
                    ).DeploymentmanagerDeploymentsUpdateRequest.
                                  DeletePolicyValueValuesEnum(
                                      args.delete_policy)),
                ))
        except apitools_exceptions.HttpError as error:
            raise exceptions.HttpException(error, dm_v2_util.HTTP_ERROR_FORMAT)
        if args. async:
            return operation
        else:
            op_name = operation.name
            try:
                dm_write.WaitForOperation(op_name,
                                          'update',
                                          dm_base.GetProject(),
                                          timeout=OPERATION_TIMEOUT)
                log.status.Print('Update operation ' + op_name +
                                 ' completed successfully.')
            except apitools_exceptions.HttpError as error:
                raise exceptions.HttpException(error,
                                               dm_v2_util.HTTP_ERROR_FORMAT)

            return dm_v2_util.FetchResourcesAndOutputs(dm_base.GetClient(),
                                                       dm_base.GetMessages(),
                                                       dm_base.GetProject(),
                                                       args.deployment_name)