Commit 363c4626 authored by Seblu's avatar Seblu
Browse files

VmCommand now use TqlCommand

parent d4060c39
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -6,13 +6,13 @@ CloudControl VM related commands
from cccli.exception import *
from sjrpc.core.exceptions import *
from cccli.printer import Printer, color
from cccli.command.command import OptionCommand
from cccli.command.command import TqlCommand

class VmCommand(OptionCommand):
class VmCommand(TqlCommand):
    '''Command for vm style'''

    def __init__(self, cli, argv0):
        OptionCommand.__init__(self, cli, argv0)
        TqlCommand.__init__(self, cli, argv0)
        self.set_usage("%prog [options] <tql>")
        self.add_option("--raw", action="store_true", dest="raw",
                        help="Don't append filter on request")
@@ -22,16 +22,17 @@ class VmCommand(OptionCommand):
                        help="Don't ask confirmation (Dangerous)")

    def _vm_action(self, argv, filters=None):
        self.parse_args()
        if len(args) == 0:
        # parse args
        self.parse_args(argv)
        if len(self.args) == 0:
            raise cmdBadArgument()
        tql = str.join("", args)
        tql = str.join("", self.args)
        # append securty options by command name
        if filters is not None and not self.options.raw:
            tql += filters
        if self.options.direct:
            try:
                objs = self.cli.rpc.call(argv[0], tql)
                objs = self.cli.rpc.call(self.args[0], tql)
            except RpcError as e:
                raise cmdError("RPCError: %s"%str(e))
        else:
@@ -43,7 +44,7 @@ class VmCommand(OptionCommand):
            # no result, goodbye
            if len(objs) == 0:
                raise cmdWarning("tql: '%s': No result."%tql)
            self.printer.out("You will %s:"%argv[0])
            self.printer.out("You will %s:"%self.args[0])
            for obj in objs:
                self.printer.out("%sid:%s%s%s"%(color["green"],color["yellow"],obj["id"],color["reset"]))
            self.printer.out("%sCount: %s%s"%(color["green"],color["reset"], len(objs)))
+1 −1
Original line number Diff line number Diff line
@@ -147,7 +147,7 @@ class Printer(object):
        h = list(self.history)
        self.history.clear()
        try:
            r = self.getline(prompt, history=False)
            r = self.getline(prompt)
        finally:
            self.history.load(h)
        return r