Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/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
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))