Пример #1
0
    def Run(self, args):
        """Run 'resources list'.

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

    Returns:
      The list of resources for the specified deployment.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    """
        request = dm_v2_base.GetMessages(
        ).DeploymentmanagerResourcesListRequest(
            project=dm_base.GetProject(),
            deployment=args.deployment,
        )
        return dm_api_util.YieldWithHttpExceptions(
            list_pager.YieldFromList(dm_v2_base.GetClient().resources,
                                     request,
                                     field='resources',
                                     limit=args.limit,
                                     batch_size=args.page_size))
Пример #2
0
  def _GetTypeProviders(self, projects, type_providers):
    for project in projects:
      request = (self.messages.
                 DeploymentmanagerTypeProvidersListRequest(
                     project=project))
      project_providers = dm_api_util.YieldWithHttpExceptions(
          list_pager.YieldFromList(TypeProviderClient(self.version),
                                   request,
                                   field='typeProviders',
                                   batch_size=self.page_size,
                                   limit=self.limit))

      type_providers[project] = [provider.name for provider in
                                 project_providers]
Пример #3
0
    def _YieldPrintableResourcesOnErrors(self, args):
        request = self.messages.DeploymentmanagerResourcesListRequest(
            project=dm_base.GetProject(),
            deployment=args.deployment,
        )

        paginated_resources = dm_api_util.YieldWithHttpExceptions(
            list_pager.YieldFromList(self.client.resources,
                                     request,
                                     field='resources',
                                     limit=args.limit,
                                     batch_size=args.page_size))
        for resource in paginated_resources:
            if resource.update:
                resource.update.intent = dm_api_util.GetActionResourceIntent(
                    resource.update.intent, resource.update.runtimePolicies)
            yield resource
Пример #4
0
  def Run(self, args):
    """Run 'operations list'.

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

    Returns:
      The list of operations for this project.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    """
    request = self.messages.DeploymentmanagerOperationsListRequest(
        project=dm_base.GetProject(),
    )
    return dm_api_util.YieldWithHttpExceptions(list_pager.YieldFromList(
        self.client.operations, request, field='operations',
        limit=args.limit, batch_size=args.page_size))
Пример #5
0
    def _YieldPrintableTypesOrErrors(self, type_providers):
        """Yield dicts of types list, provider, and (optionally) an error message.

    Args:
      type_providers: A dict of project to Type Provider names to grab Type
        Info messages for.

    Yields:
      A dict object with a list of types, a type provider reference (includes
      project) like you would use in Deployment Manager, and (optionally) an
      error message for display.

    """
        for project in type_providers.keys():
            for type_provider in type_providers[project]:
                request = (self.messages.
                           DeploymentmanagerTypeProvidersListTypesRequest(
                               project=project, typeProvider=type_provider))
                try:
                    paginated_types = dm_api_util.YieldWithHttpExceptions(
                        list_pager.YieldFromList(TypeProviderClient(
                            self.version),
                                                 request,
                                                 method='ListTypes',
                                                 field='types',
                                                 batch_size=self.page_size,
                                                 limit=self.limit))
                    types = list(paginated_types)
                    if types:
                        yield {
                            'types': types,
                            'provider': project + '/' + type_provider
                        }
                except api_exceptions.HttpException as error:
                    self.exit_code = 1
                    yield {
                        'types': [],
                        'provider': project + '/' + type_provider,
                        'error': error.message
                    }
Пример #6
0
    def Run(self, args):
        """Run 'resources list'.

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

    Returns:
      The list of resources for the specified deployment.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    """

        if args.IsSpecified('format'):
            super(ListAlpha, self).Run(args)
        elif self._isDeploymentInPreview(args):
            args.format = alpha_flags.LIST_PREVIEWED_RESOURCES_FORMAT
        else:
            args.format = alpha_flags.LIST_RESOURCES_FORMAT
        return dm_api_util.YieldWithHttpExceptions(
            self._YieldPrintableResourcesOnErrors(args))
Пример #7
0
  def Run(self, args):
    """Run 'types list'.

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

    Returns:
      The list of types for this project.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    """
    type_provider_ref = self.resources.Parse(
        args.provider if args.provider else 'NOT_A_PROVIDER',
        params={'project': properties.VALUES.core.project.GetOrFail},
        collection='deploymentmanager.typeProviders')
    self.page_size = args.page_size
    self.limit = args.limit

    if args.provider_project:
      projects = [args.provider_project]
    else:
      # Most users will be interested in the default gcp-types project types,
      # so by default we want to display those
      projects = [type_provider_ref.project, GCP_TYPES_PROJECT]

    type_providers = collections.OrderedDict()
    if not args.provider:
      self._GetTypeProviders(projects, type_providers)
    else:
      for project in projects:
        type_providers[project] = [type_provider_ref.typeProvider]

    return dm_api_util.YieldWithHttpExceptions(
        self._YieldPrintableTypesOrErrors(type_providers))