Beispiel #1
0
  def Run(self, args):
    client = appengine_api_client.GetApiClientForTrack(self.ReleaseTrack())
    services = client.ListServices()
    all_versions = client.ListVersions(services)
    # Sort versions to make behavior deterministic enough for unit testing.
    versions = sorted(version_util.GetMatchingVersions(all_versions,
                                                       args.versions,
                                                       args.service))

    services_to_delete = []
    for service in sorted(services):
      service_versions = len(
          [v for v in all_versions if v.service == service.id])
      versions_to_delete = len([v for v in versions if v.service == service.id])
      if service_versions == versions_to_delete and service_versions > 0:
        if service.id == 'default':
          raise VersionsDeleteError(
              'The default service (module) may not be deleted, and must '
              'comprise at least one version.'
          )
        else:
          services_to_delete.append(service)
        for version in copy.copy(versions):
          if version.service == service.id:
            versions.remove(version)

    for version in versions:
      if version.traffic_split:
        # TODO(b/32869800): collect info on all versions before raising.
        raise VersionsDeleteError(
            'Version [{version}] is currently serving {allocation:.2f}% of '
            'traffic for service [{service}].\n\n'
            'Please move all traffic away via one of the following methods:\n'
            ' - deploying a new version with the `--promote` argument\n'
            ' - running `gcloud app services set-traffic`\n'
            ' - running `gcloud app versions migrate`'.format(
                version=version.id,
                allocation=version.traffic_split * 100,
                service=version.service))

    if services_to_delete:
      word = text.Pluralize(len(services_to_delete), 'service')
      log.warning(
          'Requested deletion of all existing versions for the following {0}:'
          .format(word))
      resource_printer.Print(services_to_delete, 'list', out=log.status)
      console_io.PromptContinue(prompt_string=(
          '\nYou cannot delete all versions of a service. Would you like to '
          'delete the entire {0} instead?').format(word), cancel_on_no=True)
      service_util.DeleteServices(client, services_to_delete)

    if versions:
      fmt = 'list[title="Deleting the following versions:"]'
      resource_printer.Print(versions, fmt, out=log.status)
      console_io.PromptContinue(cancel_on_no=True)
    else:
      if not services_to_delete:
        log.warning('No matching versions found.')

    version_util.DeleteVersions(client, versions)
Beispiel #2
0
    def Run(self, args):
        api_client = appengine_api_client.GetApiClient()
        # 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(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(map(str, services))),
                                      cancel_on_no=True)
            service_util.DeleteServices(api_client, services)
Beispiel #3
0
    def Run(self, args):
        client = appengine_api_client.GetApiClient(self.Http(timeout=None))
        services = client.ListServices()
        all_versions = client.ListVersions(services)
        versions = version_util.GetMatchingVersions(all_versions,
                                                    args.versions,
                                                    args.service,
                                                    client.project)

        services_to_delete = []
        for service in services:
            if (len([v for v in all_versions
                     if v.service == service.id]) == len(
                         [v for v in versions if v.service == service.id])):
                services_to_delete.append(service)
                for version in copy.copy(versions):
                    if version.service == service.id:
                        versions.remove(version)

        for version in versions:
            if version.traffic_split:
                # TODO(user): mention `migrate` once it's implemented.
                raise VersionsDeleteError(
                    'Version [{version}] is currently serving {allocation:.2f}% of '
                    'traffic for service [{service}].\n\n'
                    'Please move all traffic away by deploying a new version with the'
                    '`--promote` argument or running `gcloud preview app services '
                    'set-traffic`.'.format(version=version.id,
                                           allocation=version.traffic_split *
                                           100,
                                           service=version.service))

        if services_to_delete:
            word = text.Pluralize(len(services_to_delete), 'service')
            log.warn(
                'Requested deletion of all existing versions for the following '
                '{0}:'.format(word))
            printer = console_io.ListPrinter('')
            printer.Print(services_to_delete, output_stream=log.status)
            console_io.PromptContinue(prompt_string=(
                '\nYou cannot delete all versions of a service. Would you like to '
                'delete the entire {0} instead?').format(word),
                                      cancel_on_no=True)
            service_util.DeleteServices(client, services_to_delete)

        if versions:
            printer = console_io.ListPrinter(
                'Deleting the following versions:')
            printer.Print(versions, output_stream=log.status)
            console_io.PromptContinue(cancel_on_no=True)
        else:
            if not services_to_delete:
                log.warn('No matching versions found.')

        version_util.DeleteVersions(client, versions)