From 4948c19162958b110f677db86797002a5fbc7386 Mon Sep 17 00:00:00 2001 From: Seblu <sebastien.luttringer@smartjog.com> Date: Wed, 9 Feb 2011 12:01:23 +0100 Subject: [PATCH] new command server which merge cache and remote --- cccli/command/__init__.py | 2 +- cccli/command/cache.py | 21 --------------- cccli/command/connection.py | 11 -------- cccli/command/server.py | 52 +++++++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 33 deletions(-) delete mode 100644 cccli/command/cache.py create mode 100644 cccli/command/server.py diff --git a/cccli/command/__init__.py b/cccli/command/__init__.py index 00546ee..a2f447f 100644 --- a/cccli/command/__init__.py +++ b/cccli/command/__init__.py @@ -18,4 +18,4 @@ from cccli.command.vm import * # by command module from cccli.command.list import Command_list from cccli.command.expert import Command_expert -from cccli.command.cache import Command_cache +from cccli.command.server import Command_server diff --git a/cccli/command/cache.py b/cccli/command/cache.py deleted file mode 100644 index 01a4063..0000000 --- a/cccli/command/cache.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python -#coding=utf8 - -''' -CloudControl cache command -''' -from cccli.exception import * -from sjrpc.core.exceptions import * -from cccli.printer import Printer, color -from cccli.command.command import Command - -class Command_cache(Command): - '''Show server cache statistics''' - - def __call__(self, argv): - try: - d = self.cli.rpc.call("dbstats") - for i,v in d.items(): - self.printer.out("%s: %s"%(i,v)) - except RpcError as e: - raise cmdError("RPCError: %s"%str(e)) diff --git a/cccli/command/connection.py b/cccli/command/connection.py index 297c46e..92c7b45 100644 --- a/cccli/command/connection.py +++ b/cccli/command/connection.py @@ -29,17 +29,6 @@ class Command_uptime(Command): return "Usage: uptime [tql]" -class Command_remote(Command): - '''Show remote command list''' - - def __call__(self, argv): - try: - for cmds in self.cli.rpc.call("list_commands"): - self.printer.out("%s"%cmds["name"]) - except RpcError as e: - raise cmdError("RPCError: %s"%str(e)) - - class Command_whoami(Command): '''Show connection login''' diff --git a/cccli/command/server.py b/cccli/command/server.py new file mode 100644 index 0000000..1a0eedb --- /dev/null +++ b/cccli/command/server.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +#coding=utf8 + +''' +CloudControl server command +''' +from cccli.exception import * +from sjrpc.core.exceptions import * +from cccli.printer import Printer, color +from cccli.command.command import OptionCommand + +class Command_server(OptionCommand): + '''Server manipulation command''' + + def __init__(self, cli, argv0): + OptionCommand.__init__(self, cli, argv0) + self.option.set_usage("%prog <options>") + self.option.add_option("-c", action="store_true", dest="cache", + help="show server cache") + self.option.add_option("-l", action="store_true", dest="commands", + help="list server commands") + + def __call__(self, argv): + try: + (options, args) = self.option.parse_args(argv[1:]) + except SystemExit: + return + print dir(options) + if len(args) > 0 or (not options.cache and not options.commands): + self.printer.out(self.usage()) + return + if options.cache: + self.show_cache() + if options.commands: + self.show_commands() + + def show_commands(self): + try: + self.printer.out("%sServer commands:%s"%(color["lblue"], color["reset"])) + for cmds in self.cli.rpc.call("list_commands"): + self.printer.out("%s"%cmds["name"]) + except RpcError as e: + raise cmdError("RPCError: %s"%str(e)) + + def show_cache(self): + try: + self.printer.out("%sServer cache:%s"%(color["lblue"], color["reset"])) + d = self.cli.rpc.call("dbstats") + for i,v in d.items(): + self.printer.out("%s: %s"%(i,v)) + except RpcError as e: + raise cmdError("RPCError: %s"%str(e)) -- GitLab