update openflow port for ryu
[osm/vim-emu.git] / 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
11
12 pp = pprint.PrettyPrinter(indent=4)
13
14 class ZeroRpcClient(object):
15
16 def __init__(self):
17 self.c = zerorpc.Client()
18 # TODO connect to DCNetwork API
19 #self.c.connect("tcp://127.0.0.1:4242") # TODO hard coded for now. we'll change this later
20 self.c.connect("tcp://127.0.0.1:5151")
21 self.cmds = {}
22
23 def execute_command(self, args):
24 if getattr(self, args["command"]) is not None:
25 # call the local method with the same name as the command arg
26 getattr(self, args["command"])(args)
27 else:
28 print "Command not implemented."
29
30 def get_rate(self, args):
31 r = self.c.monitor_get_rate(
32 args.get("vnf_name"),
33 args.get("direction"))
34 pp.pprint(r)
35
36
37 parser = argparse.ArgumentParser(description='son-emu network')
38 parser.add_argument(
39 "command",
40 help="Action to be executed: get_rate")
41 parser.add_argument(
42 "--vnf_name", "-vnf", dest="vnf_name",
43 help="vnf name to be monitored")
44 parser.add_argument(
45 "--direction", "-d", dest="direction",
46 help="in (ingress rate) or out (egress rate)")
47
48 def main(argv):
49 print "This is the son-emu monitor CLI."
50 print "Arguments: %s" % str(argv)
51 args = vars(parser.parse_args(argv))
52 c = ZeroRpcClient()
53 c.execute_command(args)