def Run(self, cli, args): """Run this command with the given arguments. Args: cli: The cli.CLI object for this command line tool. args: The arguments for this command as a namespace. Returns: The object returned by the module's Run() function. Raises: exceptions.Error: if thrown by the Run() function. exceptions.ExitCodeNoError: if the command is returning with a non-zero exit code. """ metrics.Loaded() tool_context = {} if self._parent_group: self._parent_group.RunGroupFilter(tool_context, args) command_instance = self._common_type(cli=cli, context=tool_context) base.LogCommand(self.dotted_name, args) resources = command_instance.Run(args) resources = display.Displayer(command_instance, args, resources, display_info=self.ai.display_info).Display() metrics.Ran() if command_instance.exit_code != 0: raise exceptions.ExitCodeNoError(exit_code=command_instance.exit_code) return resources
def Run(self, args): """Update the traffic split for the service. Args: args: Args! Returns: List of traffic.TrafficTargetStatus instances reflecting the change. """ conn_context = connection_context.GetConnectionContext( args, flags.Product.RUN, self.ReleaseTrack()) service_ref = args.CONCEPTS.service.Parse() flags.ValidateResource(service_ref) changes = flags.GetServiceConfigurationChanges(args) if not changes: raise exceptions.NoConfigurationChangeError( 'No traffic configuration change requested.') changes.insert( 0, config_changes.DeleteAnnotationChange( k8s_object.BINAUTHZ_BREAKGLASS_ANNOTATION)) changes.append( config_changes.SetLaunchStageAnnotationChange(self.ReleaseTrack())) is_managed = platforms.GetPlatform() == platforms.PLATFORM_MANAGED with serverless_operations.Connect(conn_context) as client: deployment_stages = stages.UpdateTrafficStages() try: with progress_tracker.StagedProgressTracker( 'Updating traffic...', deployment_stages, failure_message='Updating traffic failed', suppress_output=args.async_) as tracker: client.UpdateTraffic(service_ref, changes, tracker, args.async_) except: serv = client.GetService(service_ref) if serv: resources = traffic_pair.GetTrafficTargetPairs( serv.spec_traffic, serv.status_traffic, is_managed, serv.status.latestReadyRevisionName, serv.status.url) display.Displayer( self, args, resources, display_info=args.GetDisplayInfo()).Display() raise if args.async_: pretty_print.Success('Updating traffic asynchronously.') else: serv = client.GetService(service_ref) resources = traffic_pair.GetTrafficTargetPairs( serv.spec_traffic, serv.status_traffic, is_managed, serv.status.latestReadyRevisionName, serv.status.url) return resources
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace, All the arguments that were provided to this command invocation. Raises: HttpException: An http error response was received while executing api request. Returns: None """ apitools_client = genomics_util.GetGenomicsClient() genomics_messages = genomics_util.GetGenomicsMessages() name = args.name if not name.startswith(_OPERATIONS_PREFIX): name = _OPERATIONS_PREFIX + name # Look up the operation so we can display it in the confirmation prompt op = apitools_client.operations.Get( genomics_messages.GenomicsOperationsGetRequest(name=name)) operation_string = StringIO() print_format = display.Displayer(self, args).GetFormat() resource_printer.Print(op, print_format, out=operation_string) if not console_io.PromptContinue( message='%s\n%s' % (operation_string.getvalue(), 'This operation will be canceled')): raise GenomicsError('Cancel aborted by user.') apitools_client.operations.Cancel( genomics_messages.GenomicsOperationsCancelRequest(name=name)) log.status.write('Canceled [{0}].\n'.format(name))
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace, All the arguments that were provided to this command invocation. Raises: HttpException: An http error response was received while executing api request. Returns: None """ client, resource = genomics_client.CreateFromName(args.name) op = client.GetOperation(resource) operation_string = io.StringIO() print_format = display.Displayer(self, args).GetFormat() resource_printer.Print(op, print_format, out=operation_string) if not console_io.PromptContinue( message='%s\n%s' % (operation_string.getvalue(), 'This operation will be canceled')): raise GenomicsError('Cancel aborted by user.') client.CancelOperation(resource) log.status.write('Canceled [{0}].\n'.format(resource.RelativeName()))
def Run(self, args): """Update the traffic split for the service. Args: args: Args! Returns: List of traffic.TrafficTargetStatus instances reflecting the change. """ # TODO(b/143898356) Begin code that should be in Args resource_printer.RegisterFormatter( traffic_printer.TRAFFIC_PRINTER_FORMAT, traffic_printer.TrafficPrinter) args.GetDisplayInfo().AddFormat('traffic') # End code that should be in Args conn_context = connection_context.GetConnectionContext( args, flags.Product.RUN, self.ReleaseTrack()) service_ref = flags.GetService(args) changes = flags.GetConfigurationChanges(args) if not changes: raise exceptions.NoConfigurationChangeError( 'No traffic configuration change requested.') is_managed = flags.GetPlatform() == flags.PLATFORM_MANAGED with serverless_operations.Connect(conn_context) as client: deployment_stages = stages.UpdateTrafficStages() try: with progress_tracker.StagedProgressTracker( 'Updating traffic...', deployment_stages, failure_message='Updating traffic failed', suppress_output=args.async_) as tracker: client.UpdateTraffic(service_ref, changes, tracker, args.async_) except: serv = client.GetService(service_ref) if serv: resources = traffic_pair.GetTrafficTargetPairs( serv.spec_traffic, serv.status_traffic, is_managed, serv.status.latestReadyRevisionName, serv.status.url) display.Displayer( self, args, resources, display_info=args.GetDisplayInfo()).Display() raise if args.async_: pretty_print.Success('Updating traffic asynchronously.') else: serv = client.GetService(service_ref) resources = traffic_pair.GetTrafficTargetPairs( serv.spec_traffic, serv.status_traffic, is_managed, serv.status.latestReadyRevisionName, serv.status.url) return resources
def Run(self, args): """Update the traffic split for the service. Args: args: Args! Returns: List of traffic.TrafficTargetStatus instances reflecting the change. """ conn_context = connection_context.GetConnectionContext(args) service_ref = flags.GetService(args) if conn_context.supports_one_platform: flags.VerifyOnePlatformFlags(args) else: flags.VerifyGKEFlags(args) changes = flags.GetConfigurationChanges(args) if not changes: raise exceptions.NoConfigurationChangeError( 'No traffic configuration change requested.') self._SetFormat(args) with serverless_operations.Connect(conn_context) as client: deployment_stages = stages.UpdateTrafficStages() try: with progress_tracker.StagedProgressTracker( 'Updating traffic...', deployment_stages, failure_message='Updating traffic failed', suppress_output=args.async_) as tracker: client.UpdateTraffic(service_ref, changes, tracker, args.async_) except: serv = client.GetService(service_ref) resources = traffic.GetTrafficTargetPairs( serv.spec.traffic, serv.status.traffic, flags.IsManaged(args), serv.status.latestReadyRevisionName) display.Displayer( self, args, resources, display_info=args.GetDisplayInfo()).Display() raise if args.async_: pretty_print.Success('Updating traffic asynchronously.') else: serv = client.GetService(service_ref) resources = traffic.GetTrafficTargetPairs( serv.spec.traffic, serv.status.traffic, flags.IsManaged(args), serv.status.latestReadyRevisionName) return resources
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace, All the arguments that were provided to this command invocation. Raises: HttpException: An http error response was received while executing api request. Returns: None """ op = None apitools_client = genomics_util.GetGenomicsClient('v2alpha1') genomics_messages = genomics_util.GetGenomicsMessages('v2alpha1') name, v2 = genomics_util.CanonicalizeOperationName(args.name) if v2: op = apitools_client.projects_operations.Get( genomics_messages.GenomicsProjectsOperationsGetRequest( name=name)) else: apitools_client = genomics_util.GetGenomicsClient() genomics_messages = genomics_util.GetGenomicsMessages() op = apitools_client.operations.Get( genomics_messages.GenomicsOperationsGetRequest(name=name)) operation_string = io.StringIO() print_format = display.Displayer(self, args).GetFormat() resource_printer.Print(op, print_format, out=operation_string) if not console_io.PromptContinue( message='%s\n%s' % (operation_string.getvalue(), 'This operation will be canceled')): raise GenomicsError('Cancel aborted by user.') if v2: apitools_client.projects_operations.Cancel( genomics_messages.GenomicsProjectsOperationsCancelRequest( name=name)) else: apitools_client.operations.Cancel( genomics_messages.GenomicsOperationsCancelRequest(name=name)) log.status.write('Canceled [{0}].\n'.format(name))
def Run(self, args): operations = bio.Operations(properties.VALUES.core.project.Get()) operation_ref = command_lib_util.ParseOperation(args.name) op = operations.Get(operation_ref) operation_string = StringIO() print_format = display.Displayer(self, args).GetFormat() resource_printer.Print(op, print_format, out=operation_string) if not console_io.PromptContinue( message='{0}\n{1}'.format(operation_string.getvalue(), 'This operation will be canceled')): raise errors.BioError('Cancel aborted by user.') operations.Cancel(operation_ref) log.status.Print('Canceled [{0}].'.format(args.name))
def Run(self, cli, args): """Run this command with the given arguments. Args: cli: The cli.CLI object for this command line tool. args: The arguments for this command as a namespace. Returns: The object returned by the module's Run() function. Raises: exceptions.Error: if thrown by the Run() function. exceptions.ExitCodeNoError: if the command is returning with a non-zero exit code. """ metrics.Loaded() tool_context = {} if self._parent_group: self._parent_group.RunGroupFilter(tool_context, args) command_instance = self._common_type(cli=cli, context=tool_context) log.debug(u'Running [{cmd}] with arguments: [{args}]'.format( cmd=self.dotted_name, args=u', '.join(u'{arg}: "{value}"'.format(arg=arg, value=value) for arg, value in sorted( args.GetSpecifiedArgs().iteritems())))) resources = command_instance.Run(args) resources = display.Displayer( command_instance, args, resources, display_info=self.ai.display_info).Display() metrics.Ran() if command_instance.exit_code != 0: raise exceptions.ExitCodeNoError( exit_code=command_instance.exit_code) return resources
def Run(self, args): # resource represents the Managed Microsoft AD operation. resource = args.CONCEPTS.name.Parse() client = util.GetClientForResource(resource) messages = util.GetMessagesForResource(resource) get_req = \ messages.ManagedidentitiesProjectsLocationsGlobalOperationsGetRequest( name=resource.RelativeName()) op = client.projects_locations_global_operations.Get(get_req) operation_string = io.StringIO() print_format = display.Displayer(self, args).GetFormat() resource_printer.Print(op, print_format, out=operation_string) if not console_io.PromptContinue( message='{}\nThis operation will be canceled'.format( operation_string.getvalue())): raise exceptions.ActiveDirectoryError('Cancel aborted by user.') cancel_req = \ messages.ManagedidentitiesProjectsLocationsGlobalOperationsCancelRequest( name=resource.RelativeName()) client.projects_locations_global_operations.Cancel(cancel_req) log.status.write('Canceled [{0}].\n'.format(resource.RelativeName()))
def GetReferencedKeyNames(self, args): """Returns the key names referenced by the filter and format expressions.""" return display.Displayer(self, args, None).GetReferencedKeyNames()