3 (c) 2016 by Manuel Peuster <manuel.peuster@upb.de>
4 Steven Van Rossem <steven.vanrossem@intec.ugent.be>
9 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.")
32 vnf_src_name
= self
._parse
_vnf
_name
(args
.get("source"))
33 vnf_dst_name
= self
._parse
_vnf
_name
(args
.get("destination"))
35 params
= self
._create
_dict
(
36 vnf_src_interface
=self
._parse
_vnf
_interface
(args
.get("source")),
37 vnf_dst_interface
=self
._parse
_vnf
_interface
(args
.get("destination")),
38 weight
=args
.get("weight"),
39 match
=args
.get("match"),
40 bidirectional
=args
.get("bidirectional"),
41 cookie
=args
.get("cookie"))
43 # note zerorpc does not support named arguments
44 r
= self
.c
.network_action_start(
45 #args.get("datacenter"),
51 def remove(self
, args
):
52 vnf_src_name
= self
._parse
_vnf
_name
(args
.get("source"))
53 vnf_dst_name
= self
._parse
_vnf
_name
(args
.get("destination"))
55 params
= self
._create
_dict
(
56 vnf_src_interface
=self
._parse
_vnf
_interface
(args
.get("source")),
57 vnf_dst_interface
=self
._parse
_vnf
_interface
(args
.get("destination")),
58 weight
=args
.get("weight"),
59 match
=args
.get("match"),
60 bidirectional
=args
.get("bidirectional"),
61 cookie
=args
.get("cookie"))
63 r
= self
.c
.network_action_stop(
64 #args.get("datacenter"),
70 def _parse_vnf_name(self
, vnf_name_str
):
71 vnf_name
= vnf_name_str
.split(':')[0]
74 def _parse_vnf_interface(self
, vnf_name_str
):
76 vnf_interface
= vnf_name_str
.split(':')[1]
82 def _create_dict(self
, **kwargs
):
85 parser
= argparse
.ArgumentParser(description
='son-emu network')
88 choices
=['add', 'remove'],
89 help="Action to be executed.")
91 "--datacenter", "-d", dest
="datacenter",
92 help="Data center to in which the network action should be initiated")
94 "--source", "-src", dest
="source",
95 help="vnf name of the source of the chain")
97 "--destination", "-dst", dest
="destination",
98 help="vnf name of the destination of the chain")
100 "--weight", "-w", dest
="weight",
101 help="weight metric to calculate the path")
103 "--match", "-m", dest
="match",
104 help="string holding extra matches for the flow entries")
106 "--bidirectional", "-b", dest
="bidirectional",
108 help="add/remove the flow entries from src to dst and back")
110 "--cookie", "-c", dest
="cookie",
111 help="cookie for this flow, as easy to use identifier (eg. per tenant/service)")
114 args
= vars(parser
.parse_args(argv
))
116 c
.execute_command(args
)