Loading cccli/cli.py +6 −5 Original line number Diff line number Diff line Loading @@ -55,18 +55,19 @@ class Cli(object): self.printer.debug("Loaded history: %s"%len(self.printer.history)) # enable completion self.printer.completion.set_completer(self._command_completer) # load commands # connecting self._connect() # auth self._auth() # load commands (need to be done after connection) self.commands = Commands(self) self.printer.debug("Remote functions: %d"%len(self.commands.functions)) self.printer.debug("Loaded commands: %d"%len(self.commands)) # load alias self.aliases.load(self.settings.get("alias", None)) self.printer.debug("Loaded aliases: %d"%len(self.aliases)) # load tagdisplay self.tagdisplay.load(self.settings.get("tagdisplay", "")) # connecting self._connect() # auth self._auth() # parsing self._parse() # save history Loading cccli/command/account.py +15 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,9 @@ class Command_addaccount(TqlCommand): if _pass is not None: self.rpccall("passwd", "a=%s"%self.args[0], _pass, _direct=True) def remote_functions(self): return set(("addaccount", "passwd")) class Command_delaccount(TqlCommand): '''Delete an account''' Loading @@ -54,6 +57,9 @@ class Command_delaccount(TqlCommand): raise cmdBadArgument("<tql>") self.rpccall("delaccount", self.args[0]) def remote_functions(self): return set(("delaccount",)) class Command_close(TqlCommand): '''Disable accounts''' Loading @@ -68,6 +74,9 @@ class Command_close(TqlCommand): raise cmdBadArgument("<tql>") self.rpccall("close", self.args[0]) def remote_functions(self): return set(("close",)) class Command_declose(TqlCommand): '''Enable accounts''' Loading @@ -82,6 +91,9 @@ class Command_declose(TqlCommand): raise cmdBadArgument("<tql>") self.rpccall("declose", self.args[0]) def remote_functions(self): return set(("declose",)) class Command_passwd(TqlCommand): '''Change account password''' Loading Loading @@ -120,3 +132,6 @@ class Command_passwd(TqlCommand): raise cmdError("You don't type twice the same password. Aborted") # execute command self.rpccall("passwd", _tql, _pass) def remote_functions(self): return set(("passwd",)) cccli/command/cancel.py +6 −3 Original line number Diff line number Diff line Loading @@ -8,13 +8,13 @@ CloudControl jobs command 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 RemoteCommand class Command_cancel(OptionCommand): class Command_cancel(RemoteCommand): '''Cancel a job''' def __init__(self, cli, argv0): OptionCommand.__init__(self, cli, argv0) RemoteCommand.__init__(self, cli, argv0) self.set_usage("%prog [options] <job_id> ...") def __call__(self, argv): Loading @@ -32,3 +32,6 @@ class Command_cancel(OptionCommand): self.printer.error("Invalid job id: %s"%jid) except RpcError as e: self.printer.error("%s"%e) def remote_functions(self): return set(("cancel",)) cccli/command/command.py +44 −34 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ class Command(object): class OptionCommand(Command): '''Add options parser to Command''' '''Commands with options handling''' class OptionCommandParser(OptionParser): '''Parser of Option for OptionCommand''' Loading Loading @@ -67,12 +67,53 @@ class OptionCommand(Command): '''Proxy to OptionParser''' self.optionparser.set_usage(*args, **kwargs) class TqlCommand(OptionCommand): '''Add Tql stuff to Command''' class RemoteCommand(OptionCommand): '''Command which needs connection to server''' def __init__(self, cli, argv0): OptionCommand.__init__(self, cli, argv0) self.rpc = cli.rpc def remote_functions(self): '''Return a set of needed remote functions''' raise NotImplementedError def print_objects(self, objectlist, ignore=None, index=False): '''Trivial objectlist printing of tag''' if objectlist is None: return _order = objectlist.get("order", None) for (i,o) in enumerate(objectlist["objects"]): if index: self.printer.out("[%s] "%i, nl="") self.print_tags(o, order=_order, ignore=ignore) def print_tags(self, taglist, order=None, ignore=None): '''Display a tag with tagdisplay settings''' ignore = () if ignore is None else ignore order = () if order is None else order # copy dict to show tl = taglist.copy() # remove ignore tags for tn in ignore: tl.pop(tn, None) # list to print pls = [] # print firstly order tags for tn in order: tv = tl.pop(tn, None) if tv is not None: pls.append("%s%s:%s%s"%(self.tdtc(tn), tn, self.tdc(tn), self.tdr(tn, tv))) # print tags without order, alpha ordered for tn in sorted(tl.keys()): pls.append("%s%s:%s%s"%(self.tdtc(tn), tn, self.tdc(tn), self.tdr(tn, tl[tn]))) self.printer.out("%s%s"%(" ".join(pls), color["reset"])) class TqlCommand(RemoteCommand): '''Command which handle TQL stuff''' def __init__(self, cli, argv0): RemoteCommand.__init__(self, cli, argv0) self.set_usage("%prog [options] <tql>") # set tql filter stuff self.tql_filter = "" Loading Loading @@ -214,34 +255,3 @@ class TqlCommand(OptionCommand): self.print_objects(d, ["output"], index=False) except RpcError as e: self.printer.error("RPCError: %s"%str(e)) def print_objects(self, objectlist, ignore=None, index=False): '''Trivial objectlist printing of tag''' if objectlist is None: return _order = objectlist.get("order", None) for (i,o) in enumerate(objectlist["objects"]): if index: self.printer.out("[%s] "%i, nl="") self.print_tags(o, order=_order, ignore=ignore) def print_tags(self, taglist, order=None, ignore=None): '''Display a tag with tagdisplay settings''' ignore = () if ignore is None else ignore order = () if order is None else order # copy dict to show tl = taglist.copy() # remove ignore tags for tn in ignore: tl.pop(tn, None) # list to print pls = [] # print firstly order tags for tn in order: tv = tl.pop(tn, None) if tv is not None: pls.append("%s%s:%s%s"%(self.tdtc(tn), tn, self.tdc(tn), self.tdr(tn, tv))) # print tags without order, alpha ordered for tn in sorted(tl.keys()): pls.append("%s%s:%s%s"%(self.tdtc(tn), tn, self.tdc(tn), self.tdr(tn, tl[tn]))) self.printer.out("%s%s"%(" ".join(pls), color["reset"])) cccli/command/execute.py +3 −0 Original line number Diff line number Diff line Loading @@ -30,3 +30,6 @@ class Command_execute(TqlCommand): 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="") def remote_functions(self): return set(("execute",)) Loading
cccli/cli.py +6 −5 Original line number Diff line number Diff line Loading @@ -55,18 +55,19 @@ class Cli(object): self.printer.debug("Loaded history: %s"%len(self.printer.history)) # enable completion self.printer.completion.set_completer(self._command_completer) # load commands # connecting self._connect() # auth self._auth() # load commands (need to be done after connection) self.commands = Commands(self) self.printer.debug("Remote functions: %d"%len(self.commands.functions)) self.printer.debug("Loaded commands: %d"%len(self.commands)) # load alias self.aliases.load(self.settings.get("alias", None)) self.printer.debug("Loaded aliases: %d"%len(self.aliases)) # load tagdisplay self.tagdisplay.load(self.settings.get("tagdisplay", "")) # connecting self._connect() # auth self._auth() # parsing self._parse() # save history Loading
cccli/command/account.py +15 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,9 @@ class Command_addaccount(TqlCommand): if _pass is not None: self.rpccall("passwd", "a=%s"%self.args[0], _pass, _direct=True) def remote_functions(self): return set(("addaccount", "passwd")) class Command_delaccount(TqlCommand): '''Delete an account''' Loading @@ -54,6 +57,9 @@ class Command_delaccount(TqlCommand): raise cmdBadArgument("<tql>") self.rpccall("delaccount", self.args[0]) def remote_functions(self): return set(("delaccount",)) class Command_close(TqlCommand): '''Disable accounts''' Loading @@ -68,6 +74,9 @@ class Command_close(TqlCommand): raise cmdBadArgument("<tql>") self.rpccall("close", self.args[0]) def remote_functions(self): return set(("close",)) class Command_declose(TqlCommand): '''Enable accounts''' Loading @@ -82,6 +91,9 @@ class Command_declose(TqlCommand): raise cmdBadArgument("<tql>") self.rpccall("declose", self.args[0]) def remote_functions(self): return set(("declose",)) class Command_passwd(TqlCommand): '''Change account password''' Loading Loading @@ -120,3 +132,6 @@ class Command_passwd(TqlCommand): raise cmdError("You don't type twice the same password. Aborted") # execute command self.rpccall("passwd", _tql, _pass) def remote_functions(self): return set(("passwd",))
cccli/command/cancel.py +6 −3 Original line number Diff line number Diff line Loading @@ -8,13 +8,13 @@ CloudControl jobs command 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 RemoteCommand class Command_cancel(OptionCommand): class Command_cancel(RemoteCommand): '''Cancel a job''' def __init__(self, cli, argv0): OptionCommand.__init__(self, cli, argv0) RemoteCommand.__init__(self, cli, argv0) self.set_usage("%prog [options] <job_id> ...") def __call__(self, argv): Loading @@ -32,3 +32,6 @@ class Command_cancel(OptionCommand): self.printer.error("Invalid job id: %s"%jid) except RpcError as e: self.printer.error("%s"%e) def remote_functions(self): return set(("cancel",))
cccli/command/command.py +44 −34 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ class Command(object): class OptionCommand(Command): '''Add options parser to Command''' '''Commands with options handling''' class OptionCommandParser(OptionParser): '''Parser of Option for OptionCommand''' Loading Loading @@ -67,12 +67,53 @@ class OptionCommand(Command): '''Proxy to OptionParser''' self.optionparser.set_usage(*args, **kwargs) class TqlCommand(OptionCommand): '''Add Tql stuff to Command''' class RemoteCommand(OptionCommand): '''Command which needs connection to server''' def __init__(self, cli, argv0): OptionCommand.__init__(self, cli, argv0) self.rpc = cli.rpc def remote_functions(self): '''Return a set of needed remote functions''' raise NotImplementedError def print_objects(self, objectlist, ignore=None, index=False): '''Trivial objectlist printing of tag''' if objectlist is None: return _order = objectlist.get("order", None) for (i,o) in enumerate(objectlist["objects"]): if index: self.printer.out("[%s] "%i, nl="") self.print_tags(o, order=_order, ignore=ignore) def print_tags(self, taglist, order=None, ignore=None): '''Display a tag with tagdisplay settings''' ignore = () if ignore is None else ignore order = () if order is None else order # copy dict to show tl = taglist.copy() # remove ignore tags for tn in ignore: tl.pop(tn, None) # list to print pls = [] # print firstly order tags for tn in order: tv = tl.pop(tn, None) if tv is not None: pls.append("%s%s:%s%s"%(self.tdtc(tn), tn, self.tdc(tn), self.tdr(tn, tv))) # print tags without order, alpha ordered for tn in sorted(tl.keys()): pls.append("%s%s:%s%s"%(self.tdtc(tn), tn, self.tdc(tn), self.tdr(tn, tl[tn]))) self.printer.out("%s%s"%(" ".join(pls), color["reset"])) class TqlCommand(RemoteCommand): '''Command which handle TQL stuff''' def __init__(self, cli, argv0): RemoteCommand.__init__(self, cli, argv0) self.set_usage("%prog [options] <tql>") # set tql filter stuff self.tql_filter = "" Loading Loading @@ -214,34 +255,3 @@ class TqlCommand(OptionCommand): self.print_objects(d, ["output"], index=False) except RpcError as e: self.printer.error("RPCError: %s"%str(e)) def print_objects(self, objectlist, ignore=None, index=False): '''Trivial objectlist printing of tag''' if objectlist is None: return _order = objectlist.get("order", None) for (i,o) in enumerate(objectlist["objects"]): if index: self.printer.out("[%s] "%i, nl="") self.print_tags(o, order=_order, ignore=ignore) def print_tags(self, taglist, order=None, ignore=None): '''Display a tag with tagdisplay settings''' ignore = () if ignore is None else ignore order = () if order is None else order # copy dict to show tl = taglist.copy() # remove ignore tags for tn in ignore: tl.pop(tn, None) # list to print pls = [] # print firstly order tags for tn in order: tv = tl.pop(tn, None) if tv is not None: pls.append("%s%s:%s%s"%(self.tdtc(tn), tn, self.tdc(tn), self.tdr(tn, tv))) # print tags without order, alpha ordered for tn in sorted(tl.keys()): pls.append("%s%s:%s%s"%(self.tdtc(tn), tn, self.tdc(tn), self.tdr(tn, tl[tn]))) self.printer.out("%s%s"%(" ".join(pls), color["reset"]))
cccli/command/execute.py +3 −0 Original line number Diff line number Diff line Loading @@ -30,3 +30,6 @@ class Command_execute(TqlCommand): 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="") def remote_functions(self): return set(("execute",))