Ejemplo n.º 1
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.
    """
        deployment_ref = self.resources.Parse(
            args.deployment_name,
            params={'project': properties.VALUES.core.project.GetOrFail},
            collection='deploymentmanager.deployments')
        try:
            deployment = self.client.deployments.Get(
                self.messages.DeploymentmanagerDeploymentsGetRequest(
                    project=dm_base.GetProject(),
                    deployment=deployment_ref.deployment))
        except apitools_exceptions.HttpError as error:
            raise exceptions.HttpException(error,
                                           dm_api_util.HTTP_ERROR_FORMAT)

        try:
            response = self.client.resources.List(
                self.messages.DeploymentmanagerResourcesListRequest(
                    project=dm_base.GetProject(), deployment=deployment.name))
            resources = response.resources
            if self.ReleaseTrack() is base.ReleaseTrack.ALPHA:
                dm_api_util.UpdateActionResourceIntent(resources)
                if (not args.IsSpecified('format')) and (deployment.update):
                    args.format = (
                        alpha_flags.
                        PREVIEWED_DEPLOYMENT_AND_RESOURCES_AND_OUTPUTS_FORMAT)
        except apitools_exceptions.HttpError:
            # Couldn't get resources, skip adding them to the table.
            resources = None

        outputs = []

        manifest = dm_api_util.ExtractManifestName(deployment)

        if manifest:
            manifest_response = self.client.manifests.Get(
                self.messages.DeploymentmanagerManifestsGetRequest(
                    project=dm_base.GetProject(),
                    deployment=deployment_ref.deployment,
                    manifest=manifest,
                ))
            # We might be lacking a layout if the manifest failed expansion.
            if manifest_response.layout:
                outputs = dm_api_util.FlattenLayoutOutputs(
                    manifest_response.layout)

        return _Results(deployment, resources, outputs)
Ejemplo n.º 2
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 = self.client.deployments.Get(
          self.messages.DeploymentmanagerDeploymentsGetRequest(
              project=dm_base.GetProject(), deployment=args.deployment_name))
    except apitools_exceptions.HttpError as error:
      raise exceptions.HttpException(error, dm_api_util.HTTP_ERROR_FORMAT)

    try:
      response = self.client.resources.List(
          self.messages.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_api_util.ExtractManifestName(deployment)

    if manifest:
      manifest_response = self.client.manifests.Get(
          self.messages.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_api_util.FlattenLayoutOutputs(manifest_response.layout)

    return _Results(deployment, resources, outputs)
Ejemplo n.º 3
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.
    """
    manifest = args.manifest
    if not manifest:
      try:
        deployment = self.client.deployments.Get(
            self.messages.DeploymentmanagerDeploymentsGetRequest(
                project=dm_base.GetProject(),
                deployment=args.deployment
            )
        )
      except apitools_exceptions.HttpError as error:
        raise exceptions.HttpException(error)

      manifest = dm_api_util.ExtractManifestName(deployment)
      if not manifest:
        raise dm_exceptions.ManifestError(
            'The deployment [%s] does not have a current manifest. '
            'Please specify the manifest name.' % args.deployment)

    try:
      return self.client.manifests.Get(
          self.messages.DeploymentmanagerManifestsGetRequest(
              project=dm_base.GetProject(),
              deployment=args.deployment,
              manifest=manifest,
          )
      )
    except apitools_exceptions.HttpError as error:
      raise exceptions.HttpException(error, dm_api_util.HTTP_ERROR_FORMAT)
Ejemplo n.º 4
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 = dm_v2_base.GetClient().deployments.Get(
            dm_v2_base.GetMessages().DeploymentmanagerDeploymentsGetRequest(
                project=dm_base.GetProject(),
                deployment=args.deployment
            )
        )
      except apitools_exceptions.HttpError as error:
        raise exceptions.HttpException(error)

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

    try:
      return dm_v2_base.GetClient().manifests.Get(
          dm_v2_base.GetMessages().DeploymentmanagerManifestsGetRequest(
              project=dm_base.GetProject(),
              deployment=args.deployment,
              manifest=args.manifest,
          )
      )
    except apitools_exceptions.HttpError as error:
      raise exceptions.HttpException(error, dm_api_util.HTTP_ERROR_FORMAT)
Ejemplo n.º 5
0
 def testExtractManifestName_NoManifest(self):
     deployment_response = self.messages.Deployment()
     self.assertEqual(None,
                      dm_api_util.ExtractManifestName(deployment_response))
Ejemplo n.º 6
0
 def testExtractManifestName_Update(self):
     deployment_response = self.messages.Deployment(
         manifest='no/no', update={'manifest': MANIFEST_URL})
     self.assertEqual(MANIFEST_NAME,
                      dm_api_util.ExtractManifestName(deployment_response))
Ejemplo n.º 7
0
 def testExtractManifestName(self):
     deployment_response = self.messages.Deployment(manifest=MANIFEST_URL)
     self.assertEqual(MANIFEST_NAME,
                      dm_api_util.ExtractManifestName(deployment_response))