Ejemplo n.º 1
0
  def Run(self, args):
    if args.migrate and len(args.splits) > 1:
      raise TrafficSplitError('The migrate flag can only be used with splits '
                              'to a single version.')

    api_client = appengine_api_client.GetApiClientForTrack(self.ReleaseTrack())

    all_services = api_client.ListServices()
    services = service_util.GetMatchingServices(all_services, args.services)

    allocations = service_util.ParseTrafficAllocations(
        args.splits, args.split_by)

    display_allocations = []
    for service in services:
      for version, split in six.iteritems(allocations):
        display_allocations.append('{0}/{1}/{2}: {3}'.format(
            api_client.project,
            service.id,
            version,
            split))

    fmt = 'list[title="Setting the following traffic allocation:"]'
    resource_printer.Print(display_allocations, fmt, out=log.status)
    log.status.Print(
        'NOTE: Splitting traffic by {0}.'.format(args.split_by))
    log.status.Print('Any other versions of the specified service will '
                     'receive zero traffic.')
    console_io.PromptContinue(cancel_on_no=True)

    errors = {}
    for service in services:
      try:
        operations_util.CallAndCollectOpErrors(
            api_client.SetTrafficSplit, service.id, allocations,
            args.split_by.upper(), args.migrate)
      except operations_util.MiscOperationError as err:
        errors[service.id] = str(err)
    if errors:
      printable_errors = {}
      for service, error_msg in errors.items():
        printable_errors[service] = error_msg
      raise TrafficSplitError(
          'Issue setting traffic on service(s): {0}\n\n'.format(
              ', '.join(list(printable_errors.keys()))) +
          '\n\n'.join(list(printable_errors.values())))
    def Run(self, args):
        if args.migrate and len(args.splits) > 1:
            raise TrafficSplitError(
                'The migrate flag can only be used with splits '
                'to a single version.')

        api_client = appengine_api_client.GetApiClient(self.Http(timeout=None))

        all_services = api_client.ListServices()
        services = service_util.GetMatchingServices(all_services,
                                                    args.services,
                                                    api_client.project)

        allocations = service_util.ParseTrafficAllocations(
            args.splits, args.split_by)

        display_allocations = []
        for service in services:
            for version, split in allocations.iteritems():
                display_allocations.append('{0}/{1}/{2}: {3}'.format(
                    api_client.project, service.id, version, split))

        printer = console_io.ListPrinter(
            'Setting the following traffic allocations:')
        printer.Print(display_allocations, output_stream=log.status)
        log.status.Print('Any other versions on the specified services will '
                         'receive zero traffic.')
        console_io.PromptContinue(cancel_on_no=True)

        errors = {}
        for service in services:
            try:
                api_client.SetTrafficSplit(service.id, allocations,
                                           args.split_by.upper(), args.migrate)
            except (calliope_exceptions.HttpException,
                    operations.OperationError,
                    operations.OperationTimeoutError) as err:
                errors[service.id] = str(err)
        if errors:
            printable_errors = {}
            for service, error_msg in errors.items():
                printable_errors[service] = error_msg
            raise TrafficSplitError(
                'Issue setting traffic on service(s): {0}\n\n'.format(
                    ', '.join(printable_errors.keys())) +
                '\n\n'.join(printable_errors.values()))
    def GetAllInstances(self, service=None, version=None):
        """List all instances, optionally filtering by service or version.

    Args:
      service: str, the ID of the service to filter by.
      version: str, the ID of the service to filter by.

    Returns:
      list of instance_util.Instance
    """
        services = self.ListServices()
        log.debug('All services: {0}'.format(services))
        services = service_util.GetMatchingServices(
            services, [service] if service else None)

        versions = self.ListVersions(services)
        log.debug('Versions: {0}'.format(map(str, versions)))
        versions = version_util.GetMatchingVersions(
            versions, [version] if version else None, service)

        return self.ListInstances(versions)
Ejemplo n.º 4
0
    def GetAllInstances(self, service=None, version=None, version_filter=None):
        """Generator of all instances, optionally filtering by service or version.

    Args:
      service: str, the ID of the service to filter by.
      version: str, the ID of the version to filter by.
      version_filter: filter function accepting version_util.Version

    Returns:
      generator of instance_util.Instance
    """
        services = self.ListServices()
        log.debug('All services: {0}'.format(services))
        services = service_util.GetMatchingServices(
            services, [service] if service else None)

        versions = self.ListVersions(services)
        log.debug('Versions: {0}'.format(list(map(str, versions))))
        versions = version_util.GetMatchingVersions(
            versions, [version] if version else None, service)
        versions = list(filter(version_filter, versions))

        return self.ListInstances(versions)
Ejemplo n.º 5
0
  def Run(self, args):
    api_client = appengine_api_client.GetApiClientForTrack(self.ReleaseTrack())
    # Why do this? It lets us know if we're missing services up front (fail
    # fast), and we get to control the error messages
    all_services = api_client.ListServices()

    services = service_util.GetMatchingServices(all_services, args.services)

    if args.version:
      console_io.PromptContinue(
          'Deleting version [{0}] of {1} [{2}].'.format(
              args.version, text.Pluralize(len(services), 'service'),
              ', '.join(moves.map(str, services))),
          cancel_on_no=True)
      versions = [version_util.Version(api_client.project, s.id, args.version)
                  for s in services]
      version_util.DeleteVersions(api_client, versions)
    else:
      console_io.PromptContinue(
          'Deleting {0} [{1}].'.format(
              text.Pluralize(len(services), 'service'),
              ', '.join(moves.map(str, services))),
          cancel_on_no=True)
      service_util.DeleteServices(api_client, services)