class Delete(kuberun_command.KubeRunCommand, base.DeleteCommand): """Deletes a KubeRun service.""" detailed_help = _DETAILED_HELP flags = [ flags.NamespaceFlag(), flags.ClusterConnectionFlags(), flags.AsyncFlag() ] @classmethod def Args(cls, parser): super(Delete, cls).Args(parser) parser.add_argument('service', help='The KubeRun service to delete.') def SuccessResult(self, out, args): log.DeletedResource(args.service, 'service') def BuildKubeRunArgs(self, args): return [args.service] + super(Delete, self).BuildKubeRunArgs(args) def Run(self, args): """Delete a service.""" console_io.PromptContinue( message='Service [{service}] will be deleted.'.format( service=args.service), throw_if_unattended=True, cancel_on_no=True) return super(Delete, self).Run(args) def Command(self): return ['core', 'services', 'delete']
class Create(kuberun_command.KubeRunCommand, base.CreateCommand): """Creates a new KubeRun service.""" detailed_help = _DETAILED_HELP flags = [ flags.ClusterConnectionFlags(), flags.CommonServiceFlags(is_create=True), flags.AsyncFlag(), ] @classmethod def Args(cls, parser): super(Create, cls).Args(parser) parser.add_argument( 'service', help= 'ID of the service or fully qualified identifier for the service.') def BuildKubeRunArgs(self, args): return [args.service] + super(Create, self).BuildKubeRunArgs(args) def Command(self): return ['core', 'services', 'create'] def SuccessResult(self, out, args): return json.loads(out)
class Deploy(kuberun_command.KubeRunStreamingCommand, base.CreateCommand): """Deploy a Knative service.""" detailed_help = _DETAILED_HELP flags = [ flags.ClusterConnectionFlags(), flags.CommonServiceFlags(is_deploy=True), flags.AsyncFlag(), ] @classmethod def Args(cls, parser): super(Deploy, cls).Args(parser) parser.add_argument( 'service', help= 'ID of the service or fully qualified identifier for the service.') def BuildKubeRunArgs(self, args): return [args.service] + super(Deploy, self).BuildKubeRunArgs(args) def OperationResponseHandler(self, response, args): if response.failed: log.error(response.stderr) return None if response.stderr: log.status.Print(response.stderr) return response.stdout def Command(self): return ['core', 'services', 'deploy']
class Delete(kuberun_command.KubeRunCommand, base.DeleteCommand): """Deletes a Knative service.""" detailed_help = _DETAILED_HELP flags = [ flags.NamespaceFlag(), flags.ClusterConnectionFlags(), flags.AsyncFlag() ] @classmethod def Args(cls, parser): super(Delete, cls).Args(parser) parser.add_argument('service', help='The Knative service to delete.') def OperationResponseHandler(self, response, args): if response.failed: log.error(response.stderr) return None if response.stderr: log.status.Print(response.stderr) log.status.Print('Service is successfully deleted.') return None def BuildKubeRunArgs(self, args): return [args.service] + super(Delete, self).BuildKubeRunArgs(args) def Run(self, args): """Delete a service.""" console_io.PromptContinue( message='Service [{service}] will be deleted.'.format( service=args.service), throw_if_unattended=True, cancel_on_no=True) return super(Delete, self).Run(args) def Command(self): return ['core', 'services', 'delete']
class UpdateTraffic(kuberun_command.KubeRunCommandWithOutput): """Updates the traffic settings of a Knative service.""" detailed_help = _DETAILED_HELP flags = [ flags.ClusterConnectionFlags(), flags.NamespaceFlag(), flags.TrafficFlags(), flags.AsyncFlag() ] @classmethod def Args(cls, parser): super(UpdateTraffic, cls).Args(parser) parser.add_argument( 'service', help='Knative service for which to update the traffic settings.') resource_printer.RegisterFormatter( traffic_printer.TRAFFIC_PRINTER_FORMAT, traffic_printer.TrafficPrinter, hidden=True) parser.display_info.AddFormat(traffic_printer.TRAFFIC_PRINTER_FORMAT) def BuildKubeRunArgs(self, args): return [args.service] + super(UpdateTraffic, self).BuildKubeRunArgs(args) def Command(self): return ['core', 'services', 'update-traffic'] def FormatOutput(self, out, args): if out: svc = service.Service(json.loads(out)) return traffic_pair.GetTrafficTargetPairs(svc.spec_traffic, svc.status_traffic, svc.latest_ready_revision, svc.url) else: raise exceptions.Error('Failed to update traffic for service [{}]'.format( args.service))