From 2d2be899783c7b325ea25ff36d3f0b0d6ffd1e0a Mon Sep 17 00:00:00 2001 From: Seblu <sebastien.luttringer@smartjog.com> Date: Fri, 25 Feb 2011 16:11:53 +0100 Subject: [PATCH] Split shutdown and execute in separate files --- cccli/command/__init__.py | 3 ++- cccli/command/execute.py | 32 ++++++++++++++++++++++++++ cccli/command/{host.py => shutdown.py} | 23 ------------------ 3 files changed, 34 insertions(+), 24 deletions(-) create mode 100644 cccli/command/execute.py rename cccli/command/{host.py => shutdown.py} (57%) diff --git a/cccli/command/__init__.py b/cccli/command/__init__.py index 5f07585..7b76b8d 100644 --- a/cccli/command/__init__.py +++ b/cccli/command/__init__.py @@ -8,15 +8,16 @@ CloudControl CLI Commands Package # bunch of command from cccli.command.account import * from cccli.command.alias import * -from cccli.command.host import * from cccli.command.right import * from cccli.command.shell import * from cccli.command.tag import * from cccli.command.vm import * # by command module +from cccli.command.execute import Command_execute from cccli.command.expert import Command_expert from cccli.command.kill import Command_kill from cccli.command.list import Command_list from cccli.command.server import Command_server +from cccli.command.shutdown import Command_shutdown from cccli.command.tagdisplay import Command_tagdisplay diff --git a/cccli/command/execute.py b/cccli/command/execute.py new file mode 100644 index 0000000..d66e78a --- /dev/null +++ b/cccli/command/execute.py @@ -0,0 +1,32 @@ + +''' +CloudControl execute command +''' + +from cccli.exception import * +from sjrpc.core.exceptions import * +from cccli.printer import Printer, color +from cccli.command.command import TqlCommand + +class Command_execute(TqlCommand): + '''Execute a command on the remote host''' + + def __init__(self, cli, argv0): + TqlCommand.__init__(self, cli, argv0) + self.set_usage("%prog [options] <tql> <command>") + self.tql_filter += "&con&r~'host|hv'" + + def __call__(self, argv): + # arg parse + self.parse_args(argv) + if len(self.args) != 2: + raise cmdBadArgument() + # rpc call + self.rpccall("execute", self.args[0], self.args[1], _callback=self._cb_print_output) + + def _cb_print_output(self, d): + '''Print output of execute by object''' + for o in d["objects"]: + self.printer.out("%sid:%s%s%s output:"%(self.tdtc("id"), self.tdc("id"), + o["id"], color["reset"])) + self.printer.out(o.get("output", ""), nl="") diff --git a/cccli/command/host.py b/cccli/command/shutdown.py similarity index 57% rename from cccli/command/host.py rename to cccli/command/shutdown.py index 80fc212..2e361bb 100644 --- a/cccli/command/host.py +++ b/cccli/command/shutdown.py @@ -8,29 +8,6 @@ from sjrpc.core.exceptions import * from cccli.printer import Printer, color from cccli.command.command import TqlCommand -class Command_execute(TqlCommand): - '''Execute a command on the remote host''' - - def __init__(self, cli, argv0): - TqlCommand.__init__(self, cli, argv0) - self.set_usage("%prog [options] <tql> <command>") - self.tql_filter += "&con&r~'host|hv'" - - def __call__(self, argv): - # arg parse - self.parse_args(argv) - if len(self.args) != 2: - raise cmdBadArgument() - # rpc call - self.rpccall("execute", self.args[0], self.args[1], _callback=self._cb_print_output) - - def _cb_print_output(self, d): - '''Print output of execute by object''' - for o in d["objects"]: - self.printer.out("%sid:%s%s%s output:"%(self.tdtc("id"), self.tdc("id"), - o["id"], color["reset"])) - self.printer.out(o.get("output", ""), nl="") - class Command_shutdown(TqlCommand): '''Shutdown a physical host''' -- GitLab