0c3c515289a79b29315755a31212aff5bcf085ac
3 (c) 2016 by Manuel Peuster <manuel.peuster@upb.de>
8 from tabulate
import tabulate
13 pp
= pprint
.PrettyPrinter(indent
=4)
15 class ZeroRpcClient(object):
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")
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
)
29 print "Command not implemented."
31 def get_rate(self
, args
):
32 vnf_name
= self
._parse
_vnf
_name
(args
.get("vnf_name"))
33 vnf_interface
= self
._parse
_vnf
_interface
(args
.get("vnf_name"))
34 self
.c
.monitor_setup_rate_measurement(
37 args
.get("direction"),
40 r
= self
.c
.monitor_get_rate(
43 args
.get("direction"),
48 def _parse_vnf_name(self
, vnf_name_str
):
49 vnf_name
= vnf_name_str
.split(':')[0]
52 def _parse_vnf_interface(self
, vnf_name_str
):
54 vnf_interface
= vnf_name_str
.split(':')[1]
60 parser
= argparse
.ArgumentParser(description
='son-emu network')
63 help="Action to be executed: get_rate")
65 "--vnf_name", "-vnf", dest
="vnf_name",
66 help="vnf name to be monitored")
68 "--direction", "-d", dest
="direction",
69 help="rx (ingress rate) or tx (egress rate)")
71 "--metric", "-m", dest
="metric",
72 help="bytes (byte rate), packets (packet rate)")
75 print "This is the son-emu monitor CLI."
76 print "Arguments: %s" % str(argv
)
77 args
= vars(parser
.parse_args(argv
))
79 c
.execute_command(args
)