Skip to content
Snippets Groups Projects
Commit 4b192844 authored by Seblu's avatar Seblu
Browse files

improve vm commands

parent 2d9d4da8
No related branches found
No related tags found
No related merge requests found
......@@ -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>"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment