コード例 #1
0
 def testFlattenLayoutOutput_List(self):
     outputs = [{
         'name': 'foo',
         'finalValue': [1, 2]
     }, {
         'name':
         'russia',
         'finalValue': [['Tsaritsyn', 'Stalingrad', 'Volgograd'],
                        [
                            'Saint Petersburg', 'Petrograd', 'Leningrad',
                            'Saint Petersburg'
                        ]]
     }]
     expected = [{
         'name': 'foo[0]',
         'finalValue': 1
     }, {
         'name': 'foo[1]',
         'finalValue': 2
     }, {
         'name': 'russia[0]',
         'finalValue': ['Tsaritsyn', 'Stalingrad', 'Volgograd']
     }, {
         'name':
         'russia[1]',
         'finalValue':
         ['Saint Petersburg', 'Petrograd', 'Leningrad', 'Saint Petersburg']
     }]
     self.assertEqual(
         expected,
         dm_api_util.FlattenLayoutOutputs(yaml.dump({'outputs': outputs})))
コード例 #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.
    """
        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)
コード例 #3
0
 def testFlattenLayoutOutput_Simple(self):
     outputs = [{
         'name': 'foo',
         'finalValue': 'bar'
     }, {
         'name': ' Constantinople',
         'finalValue': 'Istanbul'
     }]
     self.assertEqual(
         outputs,
         dm_api_util.FlattenLayoutOutputs(yaml.dump({'outputs': outputs})))
コード例 #4
0
    def testFlattenLayoutOutput_Dict(self):
        outputs = [{'name': 'foobar', 'finalValue': {'a': 1}}]
        expected = [{'name': 'foobar[a]', 'finalValue': 1}]
        self.assertEqual(
            expected,
            dm_api_util.FlattenLayoutOutputs(yaml.dump({'outputs': outputs})))

        multiple_outputs = [{'name': 'foobar', 'finalValue': {'a': 1, 'b': 2}}]
        multiple_result = dm_api_util.FlattenLayoutOutputs(
            yaml.dump({'outputs': multiple_outputs}))
        self.assertEqual(2, len(multiple_result))

        # We have to validate this way because dictionary key iteration order
        # is undefinied.
        for item in multiple_result:
            name = item['name']
            self.assertTrue('foobar[a]' == name or 'foobar[b]' == name)

        nested = [{'name': 'a', 'finalValue': {'b': {'c': 'd'}}}]
        nested_expected = [{'name': 'a[b]', 'finalValue': {'c': 'd'}}]
        self.assertEqual(
            nested_expected,
            dm_api_util.FlattenLayoutOutputs(yaml.dump({'outputs': nested})))
コード例 #5
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)
コード例 #6
0
 def testFlattenLayout_Empty(self):
     self.assertEqual([], dm_api_util.FlattenLayoutOutputs(yaml.dump('')))
     self.assertEqual([],
                      dm_api_util.FlattenLayoutOutputs(
                          yaml.dump({'resources': []})))
コード例 #7
0
 def testFlattenLayoutOutput_ExtraField(self):
     outputs = [{'name': 'foo', 'finalValue': 'bar', 'value': 'bar'}]
     expected = [{'name': 'foo', 'finalValue': 'bar'}]
     self.assertEqual(
         expected,
         dm_api_util.FlattenLayoutOutputs(yaml.dump({'outputs': outputs})))