Ejemplo n.º 1
0
    def Run(self, args):
        """Run 'types delete'.

    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)
        if not args.quiet:
            prompt_message = 'Are you sure you want to delete [{0}]?'.format(
                args.name)
            if not console_io.PromptContinue(message=prompt_message,
                                             default=False):
                raise exceptions.OperationError('Deletion aborted by user.')

        request = (self.messages.DeploymentmanagerCompositeTypesDeleteRequest(
            project=composite_type_ref.project, compositeType=args.name))

        dm_write.Execute(self.client, self.messages, self.resources, request,
                         args.async_, self.client.compositeTypes.Delete,
                         LogResource)
Ejemplo n.º 2
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)
Ejemplo 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)
Ejemplo n.º 4
0
 def testCallFailed(self):
     # HttpError => HttpException happens later in the CLI.
     with self.assertRaisesRegex(apitools_exceptions.HttpError,
                                 'unsuccessful'):
         dm_write.Execute(self.client, self.messages, self.resources,
                          self.request, False, CallDmApiError, LogResource)
     self.AssertErrNotContains('Created endpoint [foo].')
Ejemplo n.º 5
0
 def testCallAsync(self):
     operation = dm_write.Execute(self.client, self.messages,
                                  self.resources, self.request, True,
                                  CallDmApiSuccess, LogResource)
     self.AssertErrContains('Create in progress for deployment [foo].')
     self.AssertOutputContains('Operation [op-123] running')
     self.assertEqual(CallDmApiSuccess('foo'), operation)
Ejemplo n.º 6
0
 def testOperationFailed(self):
     self.WithOperationPolling(operation_type='op',
                               error=self.OperationErrorFor('fail'))
     with self.assertRaisesRegex(exceptions.OperationError,
                                 re.compile(r'.*fail.*')):
         dm_write.Execute(self.client, self.messages, self.resources,
                          self.request, False, CallDmApiSuccess,
                          LogResource)
     self.AssertErrContains('Waiting for [op-123]')
     self.AssertErrNotContains('Created endpoint [foo].')
Ejemplo 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)
Ejemplo 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)
Ejemplo n.º 9
0
 def testCallSuccess(self):
     self.WithOperationPolling(operation_type='op')
     dm_write.Execute(self.client, self.messages, self.resources,
                      self.request, False, CallDmApiSuccess, LogResource)
     self.AssertErrContains('Waiting for [op-123]')
     self.AssertErrContains('Created deployment [foo].')