Exemplo n.º 1
0
    def Run(self, args):
        """Run 'services enable'.

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

    Returns:
      Nothing.
    """
        project = properties.VALUES.core.project.Get(required=True)
        if len(args.service) == 1:
            op = serviceusage.EnableApiCall(project, args.service[0])
        else:
            op = serviceusage.BatchEnableApiCall(project, args.service)
        if op.done:
            return
        if args. async:
            cmd = _OP_WAIT_CMD.format(op.name)
            log.status.Print('Asynchronous operation is in progress... '
                             'Use the following command to wait for its '
                             'completion:\n {0}'.format(cmd))
            return
        op = services_util.WaitOperation(op.name, serviceusage.GetOperation)
        services_util.PrintOperation(op)
  def testEnableApiCall_PermissionDenied(self):
    """Test EnableApiCall raises correctly when server returns 403 error."""
    server_error = http_error.MakeDetailedHttpError(code=403, message='Error.')
    self.ExpectEnableApiCall(None, error=server_error)

    with self.assertRaisesRegex(
        exceptions.EnableServicePermissionDeniedException, r'Error.'):
      serviceusage.EnableApiCall(self.PROJECT_NAME, self.DEFAULT_SERVICE)
Exemplo n.º 3
0
def enable_service():
    project = properties.VALUES.core.project.Get(required=True)
    service_name = 'anthosconfigmanagement.googleapis.com'
    op = serviceusage.EnableApiCall(project, service_name)
    log.status.Print('Enabling service {0}'.format(service_name))
    if op.done:
        return
    op = services_util.WaitOperation(op.name, serviceusage.GetOperation)
    services_util.PrintOperation(op)
  def testEnableApiCall_Success(self):
    """Test EnableApiCall returns operation when successful."""
    want = self.services_messages.Operation(
        name=self.OPERATION_NAME, done=False)
    self.ExpectEnableApiCall(self.OPERATION_NAME)

    got = serviceusage.EnableApiCall(self.PROJECT_NAME, self.DEFAULT_SERVICE)

    self.assertEqual(got, want)
Exemplo n.º 5
0
def _EnableMissingServices(project):
    """Enables any required services for the project."""
    enabled_services = set(
        service.config.name
        for service in serviceusage.ListServices(project, True, 100, None))
    missing_services = list(
        sorted(set(_CONTROL_PLANE_REQUIRED_SERVICES) - enabled_services))
    if not missing_services:
        return

    formatted_services = '\n'.join(
        ['- {}'.format(s) for s in missing_services])
    _PromptIfCanPrompt('\nThis will enable the following services:\n'
                       '{}'.format(formatted_services))
    if len(missing_services) == 1:
        op = serviceusage.EnableApiCall(project, missing_services[0])
    else:
        op = serviceusage.BatchEnableApiCall(project, missing_services)
    if not op.done:
        op = services_util.WaitOperation(op.name, serviceusage.GetOperation)
    log.status.Print('Services successfully enabled.')
Exemplo n.º 6
0
def EnableService(project_id, service_name, is_async=False):
    """Enable a service without checking if it is already enabled.

  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.
    is_async: bool, if True, print the operation ID and return immediately,
           without waiting for the op to complete.

  Raises:
    exceptions.EnableServicePermissionDeniedException: when enabling the API
        fails with a 403 or 404 error code.
    api_lib_exceptions.HttpException: Another miscellaneous error with the
        servicemanagement service.
  """
    log.status.Print('Enabling service [{0}] on project [{1}]...'.format(
        service_name, project_id))

    # Enable the service
    op = serviceusage.EnableApiCall(project_id, service_name)
    if not is_async and not op.done:
        op = services_util.WaitOperation(op.name, serviceusage.GetOperation)
        services_util.PrintOperation(op)