Skip to content
Snippets Groups Projects
host.py 1.96 KiB
Newer Older
Seblu's avatar
Seblu committed

'''
CloudControl physical host related commands
'''

from cccli.exception import *
from sjrpc.core.exceptions import *
from cccli.printer import Printer, color
from cccli.command.command import TqlCommand
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
class Command_execute(TqlCommand):
Seblu's avatar
Seblu committed
    '''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'"
Seblu's avatar
Seblu committed
    def __call__(self, argv):
        # arg parse
        self.parse_args(argv)
        if len(self.args) != 2:
Seblu's avatar
Seblu committed
            raise cmdBadArgument()
        # rpc call
        self.rpccall("execute", self.args[0], self.args[1], _callback=self._cb_print_output)
Seblu's avatar
Seblu committed

    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):
Seblu's avatar
Seblu committed
    '''Shutdown a physical host'''

    def __init__(self, cli, argv0):
        TqlCommand.__init__(self, cli, argv0)
        self.set_usage("%prog [options] <tql>")
        self.add_option("-R", "--reboot", action="store_true", dest="reboot",
                        help="Reboot after shutdown (default)")
        self.add_option("-H", "--halt", action="store_false", dest="reboot",
                        help="Halt after shutdown")
        self.add_option("-F", action="store_false", dest="graceful", default=True,
                        help="do not go through init but go down real fast")
        self.tql_filter += "&con&r~'host|hv'"

Seblu's avatar
Seblu committed
    def __call__(self, argv):
        # arg parse
        self.parse_args(argv)
        if len(self.args) != 1:
Seblu's avatar
Seblu committed
            raise cmdBadArgument()
        self.rpccall("shutdown", self.args[0], self.options.reboot,
                     self.options.graceful)