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

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

    Returns:
      The list of operations for this project.
    """
    messages = services_util.GetMessagesModule()
    client = services_util.GetClientInstance()
    service = arg_parsers.GetServiceNameFromArg(args.service)

    msg_filter = 'serviceName="{0}"'.format(service)
    if args.filter:
      msg_filter += ' AND ({0})'.format(args.filter)
      args.filter = None  # We don't want Display() to handle the filter.

    msg = messages.ServicemanagementOperationsListRequest(filter=msg_filter)

    return list_pager.YieldFromList(
        client.operations,
        msg,
        limit=args.limit,
        batch_size_attribute='pageSize',
        batch_size=args.page_size,
        field='operations')
Пример #2
0
def EnableServiceApiCall(project_id, service_name):
  """Make API call to enable a specific API.

  Args:
    project_id: The ID of the project for which to enable the service.
    service_name: The name of the service to enable on the project.

  Raises:
    exceptions.EnableServicePermissionDeniedException: when enabling the API
        fails.
    api_lib_exceptions.HttpException: Another miscellaneous error with the
        enabling service.

  Returns:
    The result of the Enable operation
  """

  client = services_util.GetClientInstance()
  messages = services_util.GetMessagesModule()

  request = messages.ServicemanagementServicesEnableRequest(
      serviceName=service_name,
      enableServiceRequest=messages.EnableServiceRequest(
          consumerId='project:' + project_id
      )
  )

  try:
    return client.services.Enable(request)
  except apitools_exceptions.HttpError as e:
    _HandleStatusCode(e, exceptions.EnableServicePermissionDeniedException)
Пример #3
0
    def Run(self, args):
        """Run 'services operations describe'.

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

    Returns:
      The response from the operations.Get API call.
    """
        messages = services_util.GetMessagesModule()
        client = services_util.GetClientInstance()

        operation_id = arg_parsers.GetOperationIdFromArg(args.operation)

        request = messages.ServicemanagementOperationsGetRequest(
            operationsId=operation_id, )

        operation = client.operations.Get(request)

        if (sys.getsizeof(str(operation.response)) > MAX_RESPONSE_BYTES
                and not args.full):
            log.warning('Response portion of operation resource redacted. '
                        'Use --full to see the whole Operation.\n')
            operation.response = None

        # Set async to True because we don't need to wait for the operation
        # to complete to check the status of it.
        return services_util.GetProcessedOperationResult(operation, async=True)
Пример #4
0
def EnableServiceApiCall(project_id, service_name):
    """Make API call to enable a specific API.

  Args:
    project_id: The ID of the project for which to enable the service.
    service_name: The name of the service to enable on the project.

  Raises:
    exceptions.EnableServicePermissionDeniedException: when enabling the API
        fails.
    apitools_exceptions.HttpError: Another miscellaneous error with the enabling
        service.

  Returns:
    The result of the Enable operation
  """

    client = services_util.GetClientInstance()
    messages = services_util.GetMessagesModule()

    request = messages.ServicemanagementServicesEnableRequest(
        serviceName=service_name,
        enableServiceRequest=messages.EnableServiceRequest(
            consumerId='project:' + project_id))

    try:
        return client.services.Enable(request)
    except (apitools_exceptions.HttpForbiddenError,
            apitools_exceptions.HttpNotFoundError) as e:
        # TODO(b/36865980): When backend supports it, differentiate errors.
        exceptions.ReraiseError(
            e, exceptions.EnableServicePermissionDeniedException)
Пример #5
0
    def Run(self, args):
        """Run 'service-management operations wait'.

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

    Returns:
      If successful, the response from the operations.Get API call.
    """
        messages = services_util.GetMessagesModule()
        client = services_util.GetClientInstance()

        operation_id = arg_parsers.GetOperationIdFromArg(args.operation)

        request = messages.ServicemanagementOperationsGetRequest(
            operationsId=operation_id, )

        operation = client.operations.Get(request)

        return services_util.ProcessOperationResult(operation, async=False)
Пример #6
0
  def Run(self, args):
    """Run 'service-management disable'.

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

    Returns:
      Nothing.
    """
    messages = services_util.GetMessagesModule()
    client = services_util.GetClientInstance()

    project = properties.VALUES.core.project.Get(required=True)
    for service_name in args.service:
      service_name = arg_parsers.GetServiceNameFromArg(service_name)
      request = messages.ServicemanagementServicesDisableRequest(
          serviceName=service_name,
          disableServiceRequest=messages.DisableServiceRequest(
              consumerId='project:' + project))
      operation = client.services.Disable(request)
      services_util.ProcessOperationResult(operation, args.async)