diff --git a/cccli/command/__init__.py b/cccli/command/__init__.py index 1a62dc88ac796db4402ab2b552c89c2e12fbd68f..4a9e2fa11e121d8ad6e6c5b603a5b648b6324387 100644 --- a/cccli/command/__init__.py +++ b/cccli/command/__init__.py @@ -14,6 +14,7 @@ from cccli.command.tag import * from cccli.command.vm import * # by command module +from cccli.command.cancel import Command_cancel from cccli.command.execute import Command_execute from cccli.command.expert import Command_expert from cccli.command.jobs import Command_jobs diff --git a/cccli/command/cancel.py b/cccli/command/cancel.py new file mode 100644 index 0000000000000000000000000000000000000000..34ea57bcf625d8898b0ff344a4d9ea0c84eefbf7 --- /dev/null +++ b/cccli/command/cancel.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +#coding=utf8 + +''' +CloudControl jobs command +''' + +from cccli.exception import * +from sjrpc.core.exceptions import * +from cccli.printer import Printer, color +from cccli.command.command import OptionCommand + +class Command_cancel(OptionCommand): + '''Cancel a job''' + + def __init__(self, cli, argv0): + OptionCommand.__init__(self, cli, argv0) + self.set_usage("%prog [options] <job_id> ...") + + def __call__(self, argv): + # Parse argline + self.parse_args(argv) + # append current login if nothing asked + if len(self.args) == 0: + raise cmdBadArgument() + # ask server + for jid in self.args: + try: + self.cli.rpc.call("cancel", int(jid)) + self.printer.out("Job %s: cancelled."%jid) + except ValueError: + self.printer.error("Invalid job id: %s"%jid) + except RpcError as e: + self.printer.error("%s"%e)