def post(self, src_vnf, src_intfs, dst_vnf, dst_intfs):
"""
A post request to "/v1/chain/<src_vnf>/<src_intfs>/<dst_vnf>/<dst_intfs>"
will create a chain between two interfaces at the specified vnfs.
The POST data contains the path like this.
{ "path": ["dc1.s1", "s1", "dc4.s1"]}
path specifies the destination vnf and interface and contains a list of switches
that the path traverses. The path may not contain single hop loops like:
[s1, s2, s1].
This is a limitation of Ryu, as Ryu does not allow the `INPUT_PORT` action!
:param src_vnf: Name of the source VNF
:type src_vnf: ``str``
:param src_intfs: Name of the source VNF interface to chain on
:type src_intfs: ``str``
:param dst_vnf: Name of the destination VNF
:type dst_vnf: ``str``
:param dst_intfs: Name of the destination VNF interface to chain on
:type dst_intfs: ``str``
:return: flask.Response 200 if set up correctly else 500 also returns the cookie as dict {'cookie': value}
501 if one of the VNF / intfs does not exist
:rtype: :class:`flask.Response`
"""
if request.is_json:
path = request.json.get('path')
layer2 = request.json.get('layer2', True)
else:
path = None
layer2 = True
# check if both VNFs exist
if not self.api.manage.check_vnf_intf_pair(src_vnf, src_intfs):
return Response(u"VNF %s or intfs %s does not exist" % (src_vnf, src_intfs), status=501,
mimetype="application/json")
if not self.api.manage.check_vnf_intf_pair(dst_vnf, dst_intfs):
return Response(u"VNF %s or intfs %s does not exist" % (dst_vnf, dst_intfs), status=501,
mimetype="application/json")
try:
cookie = self.api.manage.network_action_start(src_vnf, dst_vnf, vnf_src_interface=src_intfs,
vnf_dst_interface=dst_intfs, bidirectional=True,
path=path, layer2=layer2)
resp = {'cookie': cookie}
return Response(json.dumps(resp), status=200, mimetype="application/json")
except Exception as e:
logging.exception(u"%s: Error setting up the chain.\n %s" % (__name__, e))
return Response(u"Error setting up the chain", status=500, mimetype="application/json")
评论列表
文章目录