e74427b8ec59d1a0c88db78d3d5c8e952cf98205
1 from requests
import get
,put
, delete
2 from tabulate
import tabulate
7 pp
= pprint
.PrettyPrinter(indent
=4)
14 def execute_command(self
, args
):
15 if getattr(self
, args
["command"]) is not None:
16 # call the local method with the same name as the command arg
17 getattr(self
, args
["command"])(args
)
19 print("Command not implemented.")
22 vnf_src_name
= self
._parse
_vnf
_name
(args
.get("source"))
23 vnf_dst_name
= self
._parse
_vnf
_name
(args
.get("destination"))
25 params
= self
._create
_dict
(
26 vnf_src_interface
=self
._parse
_vnf
_interface
(args
.get("source")),
27 vnf_dst_interface
=self
._parse
_vnf
_interface
(args
.get("destination")),
28 weight
=args
.get("weight"),
29 match
=args
.get("match"),
30 bidirectional
=args
.get("bidirectional"),
31 cookie
=args
.get("cookie"))
33 response
= put("%s/restapi/network/%s/%s" %
34 (args
.get("endpoint"),
37 json
=json
.dumps(params
))
38 pp
.pprint(response
.json())
40 def remove(self
, args
):
41 vnf_src_name
= self
._parse
_vnf
_name
(args
.get("source"))
42 vnf_dst_name
= self
._parse
_vnf
_name
(args
.get("destination"))
44 params
= self
._create
_dict
(
45 vnf_src_interface
=self
._parse
_vnf
_interface
(args
.get("source")),
46 vnf_dst_interface
=self
._parse
_vnf
_interface
(args
.get("destination")),
47 weight
=args
.get("weight"),
48 match
=args
.get("match"),
49 bidirectional
=args
.get("bidirectional"),
50 cookie
=args
.get("cookie"))
52 response
= delete("%s/restapi/network/%s/%s" %
53 (args
.get("endpoint"),
56 json
=json
.dumps(params
))
57 pp
.pprint(response
.json())
59 def _parse_vnf_name(self
, vnf_name_str
):
60 vnf_name
= vnf_name_str
.split(':')[0]
63 def _parse_vnf_interface(self
, vnf_name_str
):
65 vnf_interface
= vnf_name_str
.split(':')[1]
71 def _create_dict(self
, **kwargs
):
74 parser
= argparse
.ArgumentParser(description
='son-emu network')
77 choices
=['add', 'remove'],
78 help="Action to be executed.")
80 "--datacenter", "-d", dest
="datacenter",
81 help="Data center to in which the network action should be initiated")
83 "--source", "-src", dest
="source",
84 help="vnf name of the source of the chain")
86 "--destination", "-dst", dest
="destination",
87 help="vnf name of the destination of the chain")
89 "--weight", "-w", dest
="weight",
90 help="weight metric to calculate the path")
92 "--match", "-m", dest
="match",
93 help="string holding extra matches for the flow entries")
95 "--bidirectional", "-b", dest
="bidirectional",
97 help="add/remove the flow entries from src to dst and back")
99 "--cookie", "-c", dest
="cookie",
100 help="cookie for this flow, as easy to use identifier (eg. per tenant/service)")
102 "--endpoint", "-e", dest
="endpoint",
103 default
="http://127.0.0.1:5001",
104 help="UUID of the plugin to be manipulated.")
107 args
= vars(parser
.parse_args(argv
))
109 c
.execute_command(args
)