792736578100003c746c97e1497e806f8c3b7f3a
1 from requests
import get
2 from tabulate
import tabulate
6 pp
= pprint
.PrettyPrinter(indent
=4)
13 def execute_command(self
, args
):
14 if getattr(self
, args
["command"]) is not None:
15 # call the local method with the same name as the command arg
16 getattr(self
, args
["command"])(args
)
18 print("Command not implemented.")
21 list = get('%s/restapi/datacenter' % args
.get('endpoint')).json()
24 # for each dc add a line to the output table
26 table
.append([d
.get("label"),
27 d
.get("internalname"),
29 d
.get("n_running_containers"),
30 len(d
.get("metadata"))])
36 print (tabulate(table
, headers
=headers
, tablefmt
="grid"))
38 def status(self
,args
):
39 list = get('%s/restapi/datacenter/%s' % ( args
.get("endpoint"), args
.get("datacenter"))).json()
41 table
.append([list.get('label'),
42 list.get('internalname'),
44 list.get('n_running_containers'),
45 len(list.get('metadata'))])
53 print (tabulate(table
, headers
=headers
, tablefmt
="grid"))
56 parser
= argparse
.ArgumentParser(description
='son-emu datacenter')
59 choices
=['list', 'status'],
60 help="Action to be executed.")
62 "--datacenter", "-d", dest
="datacenter",
63 help="Data center to which the command should be applied.")
65 "--endpoint", "-e", dest
="endpoint",
66 default
="http://127.0.0.1:5001",
67 help="UUID of the plugin to be manipulated.")
71 args
= vars(parser
.parse_args(argv
))
73 c
.execute_command(args
)