Loading cccli/command/vm.py +12 −29 Original line number Diff line number Diff line Loading @@ -6,23 +6,24 @@ CloudControl VM related commands from cccli.exception import * from sjrpc.core.exceptions import * from cccli.printer import Printer, color from cccli.command.command import Command from cccli.command.command import OptionCommand from optparse import OptionParser class VmCommand(Command): class VmCommand(OptionCommand): '''Command for vm style''' def _vm_action(self, argv, filters=None): try: oparser = OptionParser(prog=argv[0]) oparser.add_option("--raw", action="store_true", dest="raw", def __init__(self, cli, argv0): OptionCommand.__init__(self, cli, argv0) self.option.set_usage("%prog [options] <tql>") self.option.add_option("--raw", action="store_true", dest="raw", help="Don't append filter on request") oparser.add_option("--direct", action="store_true", dest="direct", self.option.add_option("--direct", action="store_true", dest="direct", help="Directly send tql to server (don't list before)") oparser.add_option("--force", action="store_true", dest="force", self.option.add_option("--tg", action="store_true", dest="noask", help="Don't ask confirmation (Dangerous)") (options, args) = oparser.parse_args(argv[1:]) def _vm_action(self, argv, filters=None): try: (options, args) = self.option.parse_args(argv[1:]) except SystemExit: return if len(args) == 0: Loading Loading @@ -78,9 +79,6 @@ class Command_start(VmCommand): def __call__(self, argv): self._vm_action(argv, "&role=vm&status=stopped") def usage(self): return "Usage: start [--raw] [--direct] [--force] [--help] <tql>" class Command_stop(VmCommand): '''Stop a running vm''' Loading @@ -88,9 +86,6 @@ class Command_stop(VmCommand): def __call__(self, argv): self._vm_action(argv, "&role=vm&status=running") def usage(self): return "Usage: stop [--raw] [--direct] [--force] [--help] <tql>" class Command_destroy(VmCommand): '''Force a vm to stop''' Loading @@ -98,18 +93,12 @@ class Command_destroy(VmCommand): def __call__(self, argv): self._vm_action(argv, "&role=vm&status!=stopped") def usage(self): return "Usage: destroy [--raw] [--direct] [--force] [--help] <tql>" class Command_restart(VmCommand): '''Restart a vm''' def __call__(self, argv): self._vm_action(argv, "&role=vm&status=running") def usage(self): return "Usage: restart [--raw] [--direct] [--force] [--help] <tql>" class Command_pause(VmCommand): '''Pause a running vm''' Loading @@ -117,15 +106,9 @@ class Command_pause(VmCommand): def __call__(self, argv): self._vm_action(argv, "&role=vm&status=running") def usage(self): return "Usage: pause [--raw] [--direct] [--force] [--help] <tql>" class Command_resume(VmCommand): '''Resume a paused vm''' def __call__(self, argv): self._vm_action(argv, "&role=vm&status=stalled") def usage(self): return "Usage: resume [--raw] [--direct] [--force] [--help] <tql>" Loading
cccli/command/vm.py +12 −29 Original line number Diff line number Diff line Loading @@ -6,23 +6,24 @@ CloudControl VM related commands from cccli.exception import * from sjrpc.core.exceptions import * from cccli.printer import Printer, color from cccli.command.command import Command from cccli.command.command import OptionCommand from optparse import OptionParser class VmCommand(Command): class VmCommand(OptionCommand): '''Command for vm style''' def _vm_action(self, argv, filters=None): try: oparser = OptionParser(prog=argv[0]) oparser.add_option("--raw", action="store_true", dest="raw", def __init__(self, cli, argv0): OptionCommand.__init__(self, cli, argv0) self.option.set_usage("%prog [options] <tql>") self.option.add_option("--raw", action="store_true", dest="raw", help="Don't append filter on request") oparser.add_option("--direct", action="store_true", dest="direct", self.option.add_option("--direct", action="store_true", dest="direct", help="Directly send tql to server (don't list before)") oparser.add_option("--force", action="store_true", dest="force", self.option.add_option("--tg", action="store_true", dest="noask", help="Don't ask confirmation (Dangerous)") (options, args) = oparser.parse_args(argv[1:]) def _vm_action(self, argv, filters=None): try: (options, args) = self.option.parse_args(argv[1:]) except SystemExit: return if len(args) == 0: Loading Loading @@ -78,9 +79,6 @@ class Command_start(VmCommand): def __call__(self, argv): self._vm_action(argv, "&role=vm&status=stopped") def usage(self): return "Usage: start [--raw] [--direct] [--force] [--help] <tql>" class Command_stop(VmCommand): '''Stop a running vm''' Loading @@ -88,9 +86,6 @@ class Command_stop(VmCommand): def __call__(self, argv): self._vm_action(argv, "&role=vm&status=running") def usage(self): return "Usage: stop [--raw] [--direct] [--force] [--help] <tql>" class Command_destroy(VmCommand): '''Force a vm to stop''' Loading @@ -98,18 +93,12 @@ class Command_destroy(VmCommand): def __call__(self, argv): self._vm_action(argv, "&role=vm&status!=stopped") def usage(self): return "Usage: destroy [--raw] [--direct] [--force] [--help] <tql>" class Command_restart(VmCommand): '''Restart a vm''' def __call__(self, argv): self._vm_action(argv, "&role=vm&status=running") def usage(self): return "Usage: restart [--raw] [--direct] [--force] [--help] <tql>" class Command_pause(VmCommand): '''Pause a running vm''' Loading @@ -117,15 +106,9 @@ class Command_pause(VmCommand): def __call__(self, argv): self._vm_action(argv, "&role=vm&status=running") def usage(self): return "Usage: pause [--raw] [--direct] [--force] [--help] <tql>" class Command_resume(VmCommand): '''Resume a paused vm''' def __call__(self, argv): self._vm_action(argv, "&role=vm&status=stalled") def usage(self): return "Usage: resume [--raw] [--direct] [--force] [--help] <tql>"