def testListServicesCall(self):
    """Test ListServices returns operation when successful."""
    want = [self.DEFAULT_SERVICE, self.DEFAULT_SERVICE_2]
    self.ExpectListServicesCall()

    got = serviceusage.ListServices(self.PROJECT_NAME, False, None, 10)
    self.assertEqual([s.config.name for s in got], want)
예제 #2
0
    def Run(self, args):
        """Run 'services list'.

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

    Returns:
      The list of services for this project.
    """
        # Default mode is --enabled, so if no flags were specified,
        # turn on the args.enabled flag.
        if not (args.enabled or args.available):
            args.enabled = True
        project = services_util.GetValidatedProject(args.project)
        return serviceusage.ListServices(project, args.enabled, args.page_size,
                                         args.limit)
예제 #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.')