c27da59f2909b2df13e869b37be50f83f954bff9
3 (c) 2016 by Manuel Peuster <manuel.peuster@upb.de>
8 from tabulate
import tabulate
12 pp
= pprint
.PrettyPrinter(indent
=4)
14 class ZeroRpcClient(object):
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")
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
)
28 print "Command not implemented."
31 vnf_src_name
= self
._parse
_vnf
_name
(args
.get("source"))
32 vnf_src_interface
= self
._parse
_vnf
_interface
(args
.get("source"))
33 vnf_dst_name
= self
._parse
_vnf
_name
(args
.get("destination"))
34 vnf_dst_interface
= self
._parse
_vnf
_interface
(args
.get("destination"))
35 r
= self
.c
.network_action_start(
36 #args.get("datacenter"),
43 def remove(self
, args
):
44 vnf_src_name
= self
._parse
_vnf
_name
(args
.get("source"))
45 vnf_src_interface
= self
._parse
_vnf
_interface
(args
.get("source"))
46 vnf_dst_name
= self
._parse
_vnf
_name
(args
.get("destination"))
47 vnf_dst_interface
= self
._parse
_vnf
_interface
(args
.get("destination"))
48 r
= self
.c
.network_action_stop(
49 #args.get("datacenter"),
56 def _parse_vnf_name(self
, vnf_name_str
):
57 vnf_name
= vnf_name_str
.split(':')[0]
60 def _parse_vnf_interface(self
, vnf_name_str
):
62 vnf_interface
= vnf_name_str
.split(':')[1]
69 parser
= argparse
.ArgumentParser(description
='son-emu network')
72 help="Action to be executed: add|remove")
74 "--datacenter", "-d", dest
="datacenter",
75 help="Data center to in which the network action should be initiated")
77 "--source", "-src", dest
="source",
78 help="vnf name of the source of the chain")
80 "--destination", "-dst", dest
="destination",
81 help="vnf name of the destination of the chain")
84 args
= vars(parser
.parse_args(argv
))
86 c
.execute_command(args
)