2caca2c00a62ed1093e40fb38bdef86f2cada599
[osm/vim-emu.git] / src / emuvim / cli / monitor.py
1 """
2 son-emu network CLI
3 (c) 2016 by Manuel Peuster <manuel.peuster@upb.de>
4 """
5
6 import argparse
7 import pprint
8 from tabulate import tabulate
9 import zerorpc
10 import time
11
12
13 pp = pprint.PrettyPrinter(indent=4)
14
15 class ZeroRpcClient(object):
16
17 def __init__(self):
18 self.c = zerorpc.Client()
19 # TODO connect to DCNetwork API
20 #self.c.connect("tcp://127.0.0.1:4242") # TODO hard coded for now. we'll change this later
21 self.c.connect("tcp://127.0.0.1:5151")
22 self.cmds = {}
23
24 def execute_command(self, args):
25 if getattr(self, args["command"]) is not None:
26 # call the local method with the same name as the command arg
27 getattr(self, args["command"])(args)
28 else:
29 print "Command not implemented."
30
31 def get_rate(self, args):
32 while True:
33 r = self.c.monitor_get_rate(
34 args.get("vnf_name"),
35 args.get("direction"))
36 pp.pprint(r)
37 time.sleep(1)
38
39
40 parser = argparse.ArgumentParser(description='son-emu network')
41 parser.add_argument(
42 "command",
43 help="Action to be executed: get_rate")
44 parser.add_argument(
45 "--vnf_name", "-vnf", dest="vnf_name",
46 help="vnf name to be monitored")
47 parser.add_argument(
48 "--direction", "-d", dest="direction",
49 help="in (ingress rate) or out (egress rate)")
50
51 def main(argv):
52 print "This is the son-emu monitor CLI."
53 print "Arguments: %s" % str(argv)
54 args = vars(parser.parse_args(argv))
55 c = ZeroRpcClient()
56 c.execute_command(args)