2 from flask_restful
import Resource
3 from flask
import request
6 logging
.basicConfig(level
=logging
.INFO
)
11 class NetworkAction(Resource
):
13 Add or remove chains between VNFs. These chain links are implemented as flow entries in the networks' SDN switches.
14 :param vnf_src_name: VNF name of the source of the link
15 :param vnf_dst_name: VNF name of the destination of the link
16 :param vnf_src_interface: VNF interface name of the source of the link
17 :param vnf_dst_interface: VNF interface name of the destination of the link
18 :param weight: weight of the link (can be useful for routing calculations)
19 :param match: OpenFlow match format of the flow entry
20 :param bidirectional: boolean value if the link needs to be implemented from src to dst and back
21 :param cookie: cookie value, identifier of the flow entry to be installed.
22 :return: message string indicating if the chain action is succesful or not
27 def put(self
, vnf_src_name
, vnf_dst_name
):
28 logging
.debug("REST CALL: network chain add")
30 return self
._NetworkAction
(vnf_src_name
, vnf_dst_name
, command
=command
)
32 def delete(self
, vnf_src_name
, vnf_dst_name
):
33 logging
.debug("REST CALL: network chain remove")
35 return self
._NetworkAction
(vnf_src_name
, vnf_dst_name
, command
=command
)
37 def _NetworkAction(self
, vnf_src_name
, vnf_dst_name
, command
=None):
38 # call DCNetwork method, not really datacenter specific API for now...
39 # no check if vnfs are really connected to this datacenter...
41 vnf_src_interface
= json
.loads(request
.json
).get("vnf_src_interface")
42 vnf_dst_interface
= json
.loads(request
.json
).get("vnf_dst_interface")
43 weight
= json
.loads(request
.json
).get("weight")
44 match
= json
.loads(request
.json
).get("match")
45 bidirectional
= json
.loads(request
.json
).get("bidirectional")
46 cookie
= json
.loads(request
.json
).get("cookie")
48 vnf_src_name
, vnf_dst_name
,
49 vnf_src_interface
=vnf_src_interface
,
50 vnf_dst_interface
=vnf_dst_interface
,
54 bidirectional
=bidirectional
,
56 # return setChain response
58 except Exception as ex
:
59 logging
.exception("API error.")
60 return ex
.message
, 500