3 (c) 2016 by Manuel Peuster <manuel.peuster@upb.de>
8 from tabulate
import tabulate
12 pp
= pprint
.PrettyPrinter(indent
=4)
15 class ZeroRpcClient(object):
18 self
.c
= zerorpc
.Client()
19 self
.c
.connect("tcp://127.0.0.1:4242") # TODO hard coded for now. we'll change this later
22 def execute_command(self
, args
):
23 if getattr(self
, args
["command"]) is not None:
24 # call the local method with the same name as the command arg
25 getattr(self
, args
["command"])(args
)
27 print "Command not implemented."
30 r
= self
.c
.datacenter_list()
33 # for each dc add a line to the output table
35 table
.append([d
.get("label"),
36 d
.get("internalname"),
38 d
.get("n_running_containers"),
39 len(d
.get("metadata"))])
45 print tabulate(table
, headers
=headers
, tablefmt
="grid")
47 def status(self
, args
):
48 r
= self
.c
.datacenter_status(
49 args
.get("datacenter"))
53 parser
= argparse
.ArgumentParser(description
='son-emu datacenter')
56 choices
=['list', 'status'],
57 help="Action to be executed.")
59 "--datacenter", "-d", dest
="datacenter",
60 help="Data center to which the command should be applied.")
64 args
= vars(parser
.parse_args(argv
))
66 c
.execute_command(args
)