def Display(self, args, result): """This method is called to print the result of the Run() method. Args: args: The arguments that command was run with. result: The value returned from the Run() method. """ succeeded, failed = result subscription_type = 'pull' if args.push_endpoint: subscription_type = 'push' if succeeded: success_printer = io.ListPrinter( '{0} {1} subscription(s) created successfully'.format( len(succeeded), subscription_type)) success_printer.Print([subscription.name for subscription in succeeded]) log.out.Print('for topic "{0}"'.format( util.TopicFormat(args.topic, args.topic_project))) log.out.Print( 'Acknowledgement deadline: {0} seconds'.format(args.ack_deadline)) if args.push_endpoint: log.out.Print('Push endpoint: "{0}"'.format(args.push_endpoint)) if failed: fail_printer = io.ListPrinter( '{0} subscription(s) failed'.format(len(failed))) fail_printer.Print( ['{0} (reason: {1})'.format(topic, desc) for topic, desc in failed])
def _DisplayProposedDeployment(project, app_config, version, promote): """Prints the details of the proposed deployment. Args: project: the name of the current project app_config: the application configuration to be deployed version: the version identifier of the application to be deployed promote: whether the newly deployed version will receive all traffic (this affects deployed URLs) Returns: dict (str->str), a mapping of module names to deployed module URLs This includes information on to-be-deployed modules (including module name, version number, and deployed URLs) as well as configurations. """ # TODO(user): Have modules and configs be able to print themselves. We # do this right now because we actually need to pass a yaml file to appcfg. # Until we can make a call with the correct values for project and version # it is weird to override those values in the yaml parsing code (because # it does not carry through to the actual file contents). deployed_urls = {} if app_config.Modules(): printer = console_io.ListPrinter( 'You are about to deploy the following modules:') deploy_messages = [] for module, info in app_config.Modules().iteritems(): use_ssl = deploy_command_util.UseSsl(info.parsed.handlers) version = None if promote else version if ':' in project: deploy_message = DEPLOY_MESSAGE_DOMAIN_SCOPED_TEMPLATE.format( project=project, module=module, file=info.file) else: url = deploy_command_util.GetAppHostname(project, module=info.module, version=version, use_ssl=use_ssl) deployed_urls[module] = url deploy_message = DEPLOY_MESSAGE_TEMPLATE.format( project=project, module=module, file=info.file, url=url) if not promote: default_url = deploy_command_util.GetAppHostname( project, module=info.module, use_ssl=use_ssl) deploy_message += PROMOTE_MESSAGE.format( default_url=default_url) deploy_messages.append(deploy_message) printer.Print(deploy_messages, output_stream=log.status) if app_config.Configs(): printer = console_io.ListPrinter( 'You are about to deploy the following configurations:') printer.Print([ '{0}/{1} (from [{2}])'.format(project, c.config, c.file) for c in app_config.Configs().values() ], output_stream=log.status) return deployed_urls
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)
def Run(self, args): # TODO(markpell): This fails with "module/version does not exist" even # when it exists if the scaling mode is set to auto. It would be good # to improve that error message. client = appengine_client.AppengineClient() versions = version_util.GetMatchingVersions(client.ListVersions(), args.versions, args.service, client.project) if not versions: log.warn('No matching versions found.') return printer = console_io.ListPrinter('Starting the following versions:') printer.Print(versions, output_stream=log.status) console_io.PromptContinue(cancel_on_no=True) errors = {} for version in versions: try: with console_io.ProgressTracker('Starting [{0}]'.format(version)): client.StartModule(module=version.service, version=version.version) except util.RPCError as err: errors[version] = str(err) if errors: printable_errors = {} for version, error_msg in errors.items(): short_name = '[{0}/{1}]'.format(version.service, version.version) printable_errors[short_name] = '{0}: {1}'.format(short_name, error_msg) raise VersionsStartError( 'Issues starting version(s): {0}\n\n'.format( ', '.join(printable_errors.keys())) + '\n\n'.join(printable_errors.values()))
def Run(self, args): # TODO(user): This fails with "module/version does not exist" even # when it exists if the scaling mode is set to auto. It would be good # to improve that error message. api_client = appengine_api_client.GetApiClient() services = api_client.ListServices() versions = version_util.GetMatchingVersions( api_client.ListVersions(services), args.versions, args.service) if versions: printer = console_io.ListPrinter( 'Stopping the following versions:') printer.Print(versions, output_stream=log.status) console_io.PromptContinue(cancel_on_no=True) else: log.warn('No matching versions found.') errors = [] for version in sorted(versions): try: with console_io.ProgressTracker( 'Stopping [{0}]'.format(version)): api_client.StopVersion(version.service, version.id) except (calliope_exceptions.HttpException, operations.OperationError, operations.OperationTimeoutError) as err: errors.append(str(err)) if errors: raise VersionsStopError('\n\n'.join(errors))
def Run(self, args): # TODO(user): This fails with "module/version does not exist" even # when it exists if the scaling mode is set to auto. It would be good # to improve that error message. api_client = appengine_api_client.GetApiClient() services = api_client.ListServices() versions = version_util.GetMatchingVersions( api_client.ListVersions(services), args.versions, args.service) if not versions: log.warn('No matching versions found.') return printer = console_io.ListPrinter('Starting the following versions:') printer.Print(versions, output_stream=log.status) console_io.PromptContinue(cancel_on_no=True) errors = {} for version in versions: try: with console_io.ProgressTracker('Starting [{0}]'.format(version)): api_client.StartVersion(version.service, version.id) except (calliope_exceptions.HttpException, operations.OperationError, operations.OperationTimeoutError) as err: errors[version] = str(err) if errors: printable_errors = {} for version, error_msg in errors.items(): short_name = '[{0}/{1}]'.format(version.service, version.id) printable_errors[short_name] = '{0}: {1}'.format(short_name, error_msg) raise VersionsStartError( 'Issues starting version(s): {0}\n\n'.format( ', '.join(printable_errors.keys())) + '\n\n'.join(printable_errors.values()))
def Run(self, args): # TODO(markpell): This fails with "module/version does not exist" even # when it exists if the scaling mode is set to auto. It would be good # to improve that error message. client = appengine_client.AppengineClient() versions = version_util.GetMatchingVersions(client.ListVersions(), args.versions, args.service, client.project) if versions: printer = console_io.ListPrinter( 'Stopping the following versions:') printer.Print(versions, output_stream=log.status) console_io.PromptContinue(cancel_on_no=True) else: log.warn('No matching versions found.') errors = [] for version in sorted(versions): try: with console_io.ProgressTracker( 'Stopping [{0}]'.format(version)): client.StopModule(module=version.service, version=version.version) except util.RPCError as err: errors.append(str(err)) if errors: raise VersionsStopError('\n\n'.join(errors))
def Display(self, args, result): """This method is called to print the result of the Run() method. Args: args: The arguments that command was run with. result: The value returned from the Run() method. """ topics = [topic.name for topic in result] printer = io.ListPrinter('{0} topic(s) found'.format(len(topics))) printer.Print(topics)
def Display(self, args, result): """This method is called to print the result of the Run() method. Args: args: The arguments that command was run with. result: The value returned from the Run() method. """ printer = io.ListPrinter('{0} message(s) published.'.format( len(result.messageIds))) printer.Print( ['messageId: {0}'.format(msg) for msg in result.messageIds])
def Display(self, args, result): """This method is called to print the result of the Run() method. Args: args: The arguments that command was run with. result: The value returned from the Run() method. """ succeeded, failed = result successes = len(succeeded) failures = len(failed) if successes: success_printer = io.ListPrinter( '{0} topic(s) deleted successfully'.format(successes)) success_printer.Print([topic for topic in succeeded]) if failures: fail_printer = io.ListPrinter('{0} topic(s) failed'.format(failures)) fail_printer.Print( ['{0} (reason: {1})'.format(topic, desc) for topic, desc in failed])
def Display(self, args, result): """This method is called to print the result of the Run() method. Args: args: The arguments that command was run with. result: The value returned from the Run() method. """ subscriptions = [subscription for subscription in result] printer = io.ListPrinter('{0} subscriptions(s) found'.format( len(subscriptions))) printer.Print(subscriptions)
def Run(self, args): client = appengine_client.AppengineClient() versions = version_util.GetMatchingVersions(client.ListVersions(), args.versions, args.service, client.project) for version in versions: if version.traffic_allocation: # TODO(zjn): mention `set-traffic` after b/24008284 is fixed. # TODO(zjn): mention `migrate` it's implemented. # TODO(zjn): mention `services delete` after it's implemented. raise VersionsDeleteError( 'Version [{version}] is currently serving {allocation}% of traffic ' 'for service [{service}].\n\n' 'Please move all traffic away by using the by deploying a new ' 'version with the `--promote` argument.'.format( version=version.version, allocation=version.traffic_allocation, service=version.service)) 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: log.warn('No matching versions found.') api_client = appengine_api_client.GetApiClient(self.Http(timeout=None)) errors = {} for version in sorted(versions): try: with console_io.ProgressTracker( 'Deleting [{0}]'.format(version)): api_client.DeleteVersion(version.service, version.version) except (calliope_exceptions.HttpException, operations.OperationError, operations.OperationTimeoutError) as err: errors[version] = str(err) if errors: printable_errors = {} for version, error_msg in errors.items(): short_name = '[{0}/{1}]'.format(version.service, version.version) printable_errors[short_name] = '{0}: {1}'.format( short_name, error_msg) raise VersionsDeleteError( 'Issues deleting version(s): {0}\n\n'.format(', '.join( printable_errors.keys())) + '\n\n'.join(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 Display(self, unused_args, result): if result.accounts: lp = console_io.ListPrinter('Credentialed accounts:') lp.Print([account + (' (active)' if account == result.active_account else '') for account in result.accounts]) log.err.Print(textwrap.dedent(""" To set the active account, run: $ gcloud config set account ``ACCOUNT'' """)) else: log.err.Print(textwrap.dedent("""\ No credentialed accounts. To login, run: $ gcloud auth login ``ACCOUNT'' """))
def Run(self, args): # Fail the delete operation when we're attempting to delete the # active config. active_config = named_configs.ConfigurationStore.ActiveConfig() if active_config.name in args.configuration_names: raise named_configs.NamedConfigError( 'Deleting named configuration failed because configuration ' '[{0}] is set as active. Use `gcloud config configurations ' 'activate` to change the active configuration.'.format( active_config.name)) printer = console_io.ListPrinter( 'The following configurations will be deleted:') printer.Print(args.configuration_names, output_stream=log.status) console_io.PromptContinue(default=True, cancel_on_no=True) for configuration_name in args.configuration_names: named_configs.ConfigurationStore.DeleteConfig(configuration_name) log.DeletedResource(configuration_name)
def Run(self, args): project = properties.VALUES.core.project.Get(required=True) app_config = yaml_parsing.AppConfigSet([args.index_file], project) if yaml_parsing.ConfigYamlInfo.INDEX not in app_config.Configs(): raise exceptions.InvalidArgumentException( 'index_file', 'You must provide the path to a valid index.yaml file.') info = app_config.Configs()[yaml_parsing.ConfigYamlInfo.INDEX] printer = console_io.ListPrinter( 'You are about to update the following configurations:') printer.Print( ['{0}/{1} From: [{2}]'.format(project, info.config, info.file)], output_stream=log.status) console_io.PromptContinue(default=True, throw_if_unattended=False, cancel_on_no=True) client = appengine_client.AppengineClient() client.UpdateIndexes(info.parsed)
def ConstructList(title, items): """Returns a string displaying the items and a title.""" buf = cStringIO.StringIO() printer = console_io.ListPrinter(title) printer.Print(sorted(set(items)), output_stream=buf) return buf.getvalue()
def ConstructList(title, items): buf = cStringIO.StringIO() printer = console_io.ListPrinter(title) printer.Print(items, output_stream=buf) return buf.getvalue()