Esempio n. 1
0
    def Run(self, args):
        """Run 'types create'.

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

    Raises:
      HttpException: An http error response was received while executing api
          request.
    """
        composite_type_ref = composite_types.GetReference(
            self.resources, args.name)
        update_labels_dict = labels_util.GetUpdateLabelsDictFromArgs(args)
        labels = dm_labels.UpdateLabels([],
                                        self.messages.CompositeTypeLabelEntry,
                                        update_labels=update_labels_dict)
        template_contents = composite_types.TemplateContentsFor(
            self.messages, args.template)

        composite_type = self.messages.CompositeType(
            name=args.name,
            description=args.description,
            status=args.status,
            templateContents=template_contents,
            labels=labels)
        request = self.messages.DeploymentmanagerCompositeTypesInsertRequest(
            project=composite_type_ref.project, compositeType=composite_type)

        dm_write.Execute(self.client, self.messages, self.resources, request,
                         args. async, self.client.compositeTypes.Insert,
                         LogResource)
Esempio n. 2
0
    def Run(self, args):
        """Run 'type-providers create'.

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

    Raises:
      HttpException: An http error response was received while executing api
          request.
    """
        messages = dm_beta_base.GetMessages()
        type_provider_ref = dm_beta_base.GetResources().Parse(
            args.provider_name, collection='deploymentmanager.typeProviders')
        update_labels_dict = labels_util.GetUpdateLabelsDictFromArgs(args)
        labels = dm_labels.UpdateLabels([],
                                        messages.TypeProviderLabelEntry,
                                        update_labels=update_labels_dict)

        type_provider = messages.TypeProvider(
            name=type_provider_ref.typeProvider,
            description=args.description,
            descriptorUrl=args.descriptor_url,
            labels=labels)

        type_providers.AddOptions(args.api_options_file, type_provider)
        request = messages.DeploymentmanagerTypeProvidersInsertRequest(
            project=type_provider_ref.project, typeProvider=type_provider)

        dm_write.Execute(request, args. async,
                         dm_beta_base.GetClient().typeProviders.Insert,
                         LogResource)
Esempio n. 3
0
    def Run(self, args):
        """Run 'type-providers create'.

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

    Raises:
      HttpException: An http error response was received while executing api
          request.
    """
        type_provider_ref = self.resources.Parse(
            args.provider_name,
            params={'project': properties.VALUES.core.project.GetOrFail},
            collection='deploymentmanager.typeProviders')
        update_labels_dict = labels_util.GetUpdateLabelsDictFromArgs(args)
        labels = dm_labels.UpdateLabels([],
                                        self.messages.TypeProviderLabelEntry,
                                        update_labels=update_labels_dict)

        type_provider = self.messages.TypeProvider(
            name=type_provider_ref.typeProvider,
            description=args.description,
            descriptorUrl=args.descriptor_url,
            labels=labels)

        type_providers.AddOptions(self.messages, args.api_options_file,
                                  type_provider)
        request = self.messages.DeploymentmanagerTypeProvidersInsertRequest(
            project=type_provider_ref.project, typeProvider=type_provider)

        dm_write.Execute(self.client, self.messages, self.resources, request,
                         args. async, self.client.typeProviders.Insert,
                         LogResource)
Esempio n. 4
0
    def testNoOpLabels(self):
        labels = [
            self.messages.DeploymentLabelEntry(key='key2', value='update2'),
            self.messages.DeploymentLabelEntry(key='key3', value='value3')
        ]
        updated_labels = dm_labels.UpdateLabels(
            labels, self.messages.DeploymentLabelEntry)

        expected = [
            self.messages.DeploymentLabelEntry(key='key2', value='update2'),
            self.messages.DeploymentLabelEntry(key='key3', value='value3')
        ]

        self.assertEqual(expected, updated_labels)
Esempio n. 5
0
 def testCreateLabels(self):
     # create subtest
     create_labels = {
         'key1': 'value1',
         'key2': 'value2',
     }
     labels = dm_labels.UpdateLabels(None,
                                     self.messages.DeploymentLabelEntry,
                                     update_labels=create_labels)
     expected = [
         self.messages.DeploymentLabelEntry(key='key1', value='value1'),
         self.messages.DeploymentLabelEntry(key='key2', value='value2')
     ]
     self.assertEqual(expected, labels)
Esempio n. 6
0
 def testRemoveLabels(self):
     labels = [
         self.messages.DeploymentLabelEntry(key='key2', value='value2'),
         self.messages.DeploymentLabelEntry(key='key3', value='value3')
     ]
     remove_labels = [
         'key2',
         'key3',
         'key4',
     ]
     updated_labels = dm_labels.UpdateLabels(
         labels,
         self.messages.DeploymentLabelEntry,
         remove_labels=remove_labels)
     expected = []
     self.assertEqual(expected, updated_labels)
Esempio n. 7
0
  def Run(self, args):
    """Run 'type-providers update'.

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

    Raises:
      HttpException: An http error response was received while executing api
          request.
    """
    type_provider_ref = type_providers.GetReference(self.resources,
                                                    args.provider_name)
    project = type_provider_ref.project
    name = type_provider_ref.typeProvider
    get_request = self.messages.DeploymentmanagerTypeProvidersGetRequest(
        project=project,
        typeProvider=name)

    existing_tp = self.client.typeProviders.Get(get_request)

    labels = dm_labels.UpdateLabels(
        existing_tp.labels,
        self.messages.TypeProviderLabelEntry,
        labels_util.GetUpdateLabelsDictFromArgs(args),
        labels_util.GetRemoveLabelsListFromArgs(args))
    type_provider = self.messages.TypeProvider(name=name,
                                               description=args.description,
                                               descriptorUrl=(args.
                                                              descriptor_url),
                                               labels=labels)
    type_providers.AddOptions(self.messages,
                              args.api_options_file,
                              type_provider)

    update_request = self.messages.DeploymentmanagerTypeProvidersUpdateRequest(
        project=project,
        typeProvider=args.provider_name,
        typeProviderResource=type_provider)

    dm_write.Execute(self.client,
                     self.messages,
                     self.resources,
                     update_request,
                     args.async_,
                     self.client.typeProviders.Update,
                     LogResource)
Esempio n. 8
0
  def Run(self, args):
    """Run 'types update'.

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

    Raises:
      HttpException: An http error response was received while executing api
          request.
    """
    composite_type_ref = composite_types.GetReference(self.resources, args.name)
    get_request = self.messages.DeploymentmanagerCompositeTypesGetRequest(
        project=composite_type_ref.project,
        compositeType=args.name)
    existing_ct = self.client.compositeTypes.Get(get_request)

    labels = dm_labels.UpdateLabels(
        existing_ct.labels,
        self.messages.CompositeTypeLabelEntry,
        labels_util.GetUpdateLabelsDictFromArgs(args),
        labels_util.GetRemoveLabelsListFromArgs(args))

    composite_type = self.messages.CompositeType(
        name=args.name,
        description=args.description,
        status=args.status,
        templateContents=existing_ct.templateContents,
        labels=labels)

    update_request = self.messages.DeploymentmanagerCompositeTypesUpdateRequest(
        project=composite_type_ref.project,
        compositeType=args.name,
        compositeTypeResource=composite_type)

    dm_write.Execute(self.client,
                     self.messages,
                     self.resources,
                     update_request,
                     args.async_,
                     self.client.compositeTypes.Update,
                     LogResource)
Esempio n. 9
0
 def testUpdateLabels(self):
     labels = [
         self.messages.DeploymentLabelEntry(key='key1', value='value1'),
         self.messages.DeploymentLabelEntry(key='key2', value='value2')
     ]
     update_labels = {
         'key2': 'update2',
         'key3': 'value3',
     }
     remove_labels = [
         'key1',
     ]
     updated_labels = dm_labels.UpdateLabels(
         labels,
         self.messages.DeploymentLabelEntry,
         update_labels=update_labels,
         remove_labels=remove_labels)
     expected = [
         self.messages.DeploymentLabelEntry(key='key2', value='update2'),
         self.messages.DeploymentLabelEntry(key='key3', value='value3')
     ]
     self.assertEqual(expected, updated_labels)
Esempio n. 10
0
 def _GetUpdatedDeploymentLabels(self, args, deployment):
     update_labels = labels_util.GetUpdateLabelsDictFromArgs(args)
     remove_labels = labels_util.GetRemoveLabelsListFromArgs(args)
     return dm_labels.UpdateLabels(deployment.labels,
                                   self.messages.DeploymentLabelEntry,
                                   update_labels, remove_labels)
Esempio n. 11
0
    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)