コード例 #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 = serviceusage.WaitOperation(op.name)
    services_util.PrintOperation(op)
コード例 #2
0
  def testBatchEnableApiCall_Success(self):
    """Test BatchEnableApiCall returns operation when successful."""
    want = self.services_messages.Operation(
        name=self.OPERATION_NAME, done=False)
    self.ExpectBatchEnableApiCall(self.OPERATION_NAME)

    got = serviceusage.BatchEnableApiCall(
        self.PROJECT_NAME, [self.DEFAULT_SERVICE, self.DEFAULT_SERVICE_2])

    self.assertEqual(got, want)
コード例 #3
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.')