From 4b192844673fd235b807fae4dbe72db180579465 Mon Sep 17 00:00:00 2001 From: Seblu <sebastien.luttringer@smartjog.com> Date: Tue, 8 Feb 2011 11:48:31 +0100 Subject: [PATCH] improve vm commands --- cccli/command/vm.py | 41 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/cccli/command/vm.py b/cccli/command/vm.py index 1818008..bbc2e36 100644 --- a/cccli/command/vm.py +++ b/cccli/command/vm.py @@ -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: @@ -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''' @@ -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''' @@ -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''' @@ -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>" -- GitLab