-"""
-Copyright (c) 2017 SONATA-NFV and Paderborn University
-ALL RIGHTS RESERVED.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-
-Neither the name of the SONATA-NFV, Paderborn University
-nor the names of its contributors may be used to endorse or promote
-products derived from this software without specific prior written
-permission.
-
-This work has been performed in the framework of the SONATA project,
-funded by the European Commission under Grant number 671517 through
-the Horizon 2020 and 5G-PPP programmes. The authors would like to
-acknowledge the contributions of their colleagues of the SONATA
-partner consortium (www.sonata-nfv.eu).
-"""
+# Copyright (c) 2015 SONATA-NFV and Paderborn University
+# ALL RIGHTS RESERVED.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Neither the name of the SONATA-NFV, Paderborn University
+# nor the names of its contributors may be used to endorse or promote
+# products derived from this software without specific prior written
+# permission.
+#
+# This work has been performed in the framework of the SONATA project,
+# funded by the European Commission under Grant number 671517 through
+# the Horizon 2020 and 5G-PPP programmes. The authors would like to
+# acknowledge the contributions of their colleagues of the SONATA
+# partner consortium (www.sonata-nfv.eu).
from flask_restful import Resource
from flask import request, Response
import logging
import json
-import uuid
-
-from emuvim.api.openstack.resources.port_chain import PortChain
-from emuvim.api.openstack.helper import get_host
class SFC(Resource):
request_dict = json.loads(request.data).get("port_pair")
name = request_dict["name"]
- ingress_port = self.api.compute.find_port_by_name_or_id(request_dict["ingress"])
- egress_port = self.api.compute.find_port_by_name_or_id(request_dict["egress"])
+ ingress_port = self.api.compute.find_port_by_name_or_id(
+ request_dict["ingress"])
+ egress_port = self.api.compute.find_port_by_name_or_id(
+ request_dict["egress"])
port_pair = self.api.compute.create_port_pair(name)
port_pair.ingress = ingress_port
resp = {
"port_pair": port_pair.create_dict(self.api.compute)
}
- return Response(json.dumps(resp), status=201, mimetype='application/json')
+ return Response(json.dumps(resp), status=201,
+ mimetype='application/json')
except Exception as ex:
- logging.exception("Neutron SFC: %s Exception." % str(self.__class__.__name__))
- return Response(ex.message, status=500, mimetype='application/json')
+ logging.exception("Neutron SFC: %s Exception." %
+ str(self.__class__.__name__))
+ return Response(ex.message, status=500,
+ mimetype='application/json')
class PortPairsUpdate(SFC):
resp = {
"port_pair": port_pair.create_dict(self.api.compute)
}
- return Response(json.dumps(resp), status=200, mimetype='application/json')
+ return Response(json.dumps(resp), status=200,
+ mimetype='application/json')
except Exception as ex:
- logging.exception("Neutron SFC: %s Exception." % str(self.__class__.__name__))
- return Response(ex.message, status=500, mimetype='application/json')
+ logging.exception("Neutron SFC: %s Exception." %
+ str(self.__class__.__name__))
+ return Response(ex.message, status=500,
+ mimetype='application/json')
class PortPairsDelete(SFC):
try:
self.api.compute.delete_port_pair(pair_id)
- return Response("Port pair %s deleted.\n" % pair_id, status=204, mimetype='application/json')
+ return Response("", status=204,
+ mimetype='application/json')
except Exception as ex:
- logging.exception("Neutron SFC: %s Exception." % str(self.__class__.__name__))
- return Response(ex.message, status=500, mimetype='application/json')
+ logging.exception("Neutron SFC: %s Exception." %
+ str(self.__class__.__name__))
+ return Response(ex.message, status=500,
+ mimetype='application/json')
class PortPairsList(SFC):
def get(self):
logging.debug("API CALL: %s GET" % str(self.__class__.__name__))
try:
- port_pair_list = []
- for port_pair in self.api.compute.port_pairs.values():
- port_pair_list.append(port_pair.create_dict(self.api.compute))
- resp = {"port_pairs": port_pair_list}
+ port_pairs = self.api.compute.port_pairs.values()
+ id = request.args.get('id')
+ if id and any(id):
+ port_pairs = filter(lambda port_pair: port_pair.id == id, port_pairs)
+ resp = {"port_pairs": map(lambda port_pair: port_pair.create_dict(self.api.compute), port_pairs)}
- return Response(json.dumps(resp), status=200, mimetype='application/json')
+ return Response(json.dumps(resp), status=200,
+ mimetype='application/json')
except Exception as ex:
- logging.exception("Neutron SFC: %s Exception." % str(self.__class__.__name__))
- return Response(ex.message, status=500, mimetype='application/json')
+ logging.exception("Neutron SFC: %s Exception." %
+ str(self.__class__.__name__))
+ return Response(ex.message, status=500,
+ mimetype='application/json')
class PortPairsShow(SFC):
resp = {
"port_pair": port_pair.create_dict(self.api.compute)
}
- return Response(json.dumps(resp), status=200, mimetype='application/json')
+ return Response(json.dumps(resp), status=200,
+ mimetype='application/json')
except Exception as ex:
- logging.exception("Neutron SFC: %s Exception." % str(self.__class__.__name__))
- return Response(ex.message, status=500, mimetype='application/json')
+ logging.exception("Neutron SFC: %s Exception." %
+ str(self.__class__.__name__))
+ return Response(ex.message, status=500,
+ mimetype='application/json')
###############################################################################
try:
request_dict = json.loads(request.data).get("port_pair_group")
- port_pair_group = self.api.compute.create_port_pair_group(request_dict["name"])
+ port_pair_group = self.api.compute.create_port_pair_group(
+ request_dict["name"])
port_pair_group.port_pairs = request_dict["port_pairs"]
if "description" in request_dict:
port_pair_group.description = request_dict["description"]
if "port_pair_group_parameters" in request_dict:
- port_pair_group.port_pair_group_parameters = request_dict["port_pair_group_parameters"]
+ port_pair_group.port_pair_group_parameters = request_dict[
+ "port_pair_group_parameters"]
resp = {
"port_pair_group": port_pair_group.create_dict(self.api.compute)
}
- return Response(json.dumps(resp), status=201, mimetype='application/json')
+ return Response(json.dumps(resp), status=201,
+ mimetype='application/json')
except Exception as ex:
- logging.exception("Neutron SFC: %s Exception." % str(self.__class__.__name__))
- return Response(ex.message, status=500, mimetype='application/json')
+ logging.exception("Neutron SFC: %s Exception." %
+ str(self.__class__.__name__))
+ return Response(ex.message, status=500,
+ mimetype='application/json')
class PortPairGroupUpdate(SFC):
try:
request_dict = json.loads(request.data).get("port_pair_group")
- port_pair_group = self.api.compute.find_port_pair_group_by_name_or_id(group_id)
+ port_pair_group = self.api.compute.find_port_pair_group_by_name_or_id(
+ group_id)
if "name" in request_dict:
port_pair_group.name = request_dict["name"]
if "description" in request_dict:
resp = {
"port_pair_group": port_pair_group.create_dict(self.api.compute)
}
- return Response(json.dumps(resp), status=200, mimetype='application/json')
+ return Response(json.dumps(resp), status=200,
+ mimetype='application/json')
except Exception as ex:
- logging.exception("Neutron SFC: %s Exception." % str(self.__class__.__name__))
- return Response(ex.message, status=500, mimetype='application/json')
+ logging.exception("Neutron SFC: %s Exception." %
+ str(self.__class__.__name__))
+ return Response(ex.message, status=500,
+ mimetype='application/json')
class PortPairGroupDelete(SFC):
try:
self.api.compute.delete_port_pair_group(group_id)
- return Response("Port pair group %s deleted.\n" % group_id, status=204, mimetype='application/json')
+ return Response("", status=204,
+ mimetype='application/json')
except Exception as ex:
- logging.exception("Neutron SFC: %s Exception." % str(self.__class__.__name__))
- return Response(ex.message, status=500, mimetype='application/json')
+ logging.exception("Neutron SFC: %s Exception." %
+ str(self.__class__.__name__))
+ return Response(ex.message, status=500,
+ mimetype='application/json')
class PortPairGroupList(SFC):
try:
port_pair_group_list = []
for port_pair_group in self.api.compute.port_pair_groups.values():
- port_pair_group_list.append(port_pair_group.create_dict(self.api.compute))
+ port_pair_group_list.append(
+ port_pair_group.create_dict(self.api.compute))
resp = {"port_pair_groups": port_pair_group_list}
- return Response(json.dumps(resp), status=200, mimetype='application/json')
+ return Response(json.dumps(resp), status=200,
+ mimetype='application/json')
except Exception as ex:
- logging.exception("Neutron SFC: %s Exception." % str(self.__class__.__name__))
- return Response(ex.message, status=500, mimetype='application/json')
+ logging.exception("Neutron SFC: %s Exception." %
+ str(self.__class__.__name__))
+ return Response(ex.message, status=500,
+ mimetype='application/json')
class PortPairGroupShow(SFC):
logging.debug("API CALL: %s GET" % str(self.__class__.__name__))
try:
- port_pair_group = self.api.compute.find_port_pair_group_by_name_or_id(group_id)
+ port_pair_group = self.api.compute.find_port_pair_group_by_name_or_id(
+ group_id)
resp = {
"port_pair_group": port_pair_group.create_dict(self.api.compute)
}
- return Response(json.dumps(resp), status=200, mimetype='application/json')
+ return Response(json.dumps(resp), status=200,
+ mimetype='application/json')
except Exception as ex:
- logging.exception("Neutron SFC: %s Exception." % str(self.__class__.__name__))
- return Response(ex.message, status=500, mimetype='application/json')
+ logging.exception("Neutron SFC: %s Exception." %
+ str(self.__class__.__name__))
+ return Response(ex.message, status=500,
+ mimetype='application/json')
###############################################################################
try:
request_dict = json.loads(request.data).get("flow_classifier")
- flow_classifier = self.api.compute.create_flow_classifier(request_dict["name"])
+ flow_classifier = self.api.compute.create_flow_classifier(
+ request_dict["name"])
if "description" in request_dict:
flow_classifier.description = request_dict["description"]
if "ethertype" in request_dict:
if "source_port_range_max" in request_dict:
flow_classifier.source_port_range_max = request_dict["source_port_range_max"]
if "destination_port_range_min" in request_dict:
- flow_classifier.destination_port_range_min = request_dict["destination_port_range_min"]
+ flow_classifier.destination_port_range_min = request_dict[
+ "destination_port_range_min"]
if "destination_port_range_max" in request_dict:
- flow_classifier.destination_port_range_max = request_dict["destination_port_range_max"]
+ flow_classifier.destination_port_range_max = request_dict[
+ "destination_port_range_max"]
if "source_ip_prefix" in request_dict:
flow_classifier.source_ip_prefix = request_dict["source_ip_prefix"]
if "destination_ip_prefix" in request_dict:
resp = {
"flow_classifier": flow_classifier.create_dict(self.api.compute)
}
- return Response(json.dumps(resp), status=201, mimetype='application/json')
+ return Response(json.dumps(resp), status=201,
+ mimetype='application/json')
except Exception as ex:
- logging.exception("Neutron SFC: %s Exception." % str(self.__class__.__name__))
- return Response(ex.message, status=500, mimetype='application/json')
+ logging.exception("Neutron SFC: %s Exception." %
+ str(self.__class__.__name__))
+ return Response(ex.message, status=500,
+ mimetype='application/json')
class FlowClassifierUpdate(SFC):
try:
request_dict = json.loads(request.data).get("flow_classifier")
- flow_classifier = self.api.compute.find_flow_classifier_by_name_or_id(flow_classifier_id)
+ flow_classifier = self.api.compute.find_flow_classifier_by_name_or_id(
+ flow_classifier_id)
if "name" in request_dict:
flow_classifier.name = request_dict["name"]
if "description" in request_dict:
resp = {
"flow_classifier": flow_classifier.create_dict(self.api.compute)
}
- return Response(json.dumps(resp), status=200, mimetype='application/json')
+ return Response(json.dumps(resp), status=200,
+ mimetype='application/json')
except Exception as ex:
- logging.exception("Neutron SFC: %s Exception." % str(self.__class__.__name__))
- return Response(ex.message, status=500, mimetype='application/json')
+ logging.exception("Neutron SFC: %s Exception." %
+ str(self.__class__.__name__))
+ return Response(ex.message, status=500,
+ mimetype='application/json')
class FlowClassifierDelete(SFC):
try:
self.api.compute.delete_flow_classifier(flow_classifier_id)
- return Response("Port pair group %s deleted.\n" % flow_classifier_id, status=204,
+ return Response("", status=204,
mimetype='application/json')
except Exception as ex:
- logging.exception("Neutron SFC: %s Exception." % str(self.__class__.__name__))
- return Response(ex.message, status=500, mimetype='application/json')
+ logging.exception("Neutron SFC: %s Exception." %
+ str(self.__class__.__name__))
+ return Response(ex.message, status=500,
+ mimetype='application/json')
class FlowClassifierList(SFC):
try:
flow_classifier_list = []
for flow_classifier in self.api.compute.flow_classifiers.values():
- flow_classifier_list.append(flow_classifier.create_dict(self.api.compute))
+ flow_classifier_list.append(
+ flow_classifier.create_dict(self.api.compute))
resp = {"flow_classifiers": flow_classifier_list}
- return Response(json.dumps(resp), status=200, mimetype='application/json')
+ return Response(json.dumps(resp), status=200,
+ mimetype='application/json')
except Exception as ex:
- logging.exception("Neutron SFC: %s Exception." % str(self.__class__.__name__))
- return Response(ex.message, status=500, mimetype='application/json')
+ logging.exception("Neutron SFC: %s Exception." %
+ str(self.__class__.__name__))
+ return Response(ex.message, status=500,
+ mimetype='application/json')
class FlowClassifierShow(SFC):
logging.debug("API CALL: %s GET" % str(self.__class__.__name__))
try:
- flow_classifier = self.api.compute.find_flow_classifier_by_name_or_id(flow_classifier_id)
+ flow_classifier = self.api.compute.find_flow_classifier_by_name_or_id(
+ flow_classifier_id)
resp = {
"flow_classifier": flow_classifier.create_dict(self.api.compute)
}
- return Response(json.dumps(resp), status=200, mimetype='application/json')
+ return Response(json.dumps(resp), status=200,
+ mimetype='application/json')
except Exception as ex:
- logging.exception("Neutron SFC: %s Exception." % str(self.__class__.__name__))
- return Response(ex.message, status=500, mimetype='application/json')
+ logging.exception("Neutron SFC: %s Exception." %
+ str(self.__class__.__name__))
+ return Response(ex.message, status=500,
+ mimetype='application/json')
###############################################################################
try:
request_dict = json.loads(request.data).get("port_chain")
- port_chain = self.api.compute.create_port_chain(request_dict["name"])
+ port_chain = self.api.compute.create_port_chain(
+ request_dict["name"])
port_chain.port_pair_groups = request_dict["port_pair_groups"]
if "description" in request_dict:
port_chain.description = request_dict["description"]
resp = {
"port_chain": port_chain.create_dict(self.api.compute)
}
- return Response(json.dumps(resp), status=201, mimetype='application/json')
+ return Response(json.dumps(resp), status=201,
+ mimetype='application/json')
except Exception as ex:
- logging.exception("Neutron SFC: %s Exception." % str(self.__class__.__name__))
- return Response(ex.message, status=500, mimetype='application/json')
+ logging.exception("Neutron SFC: %s Exception." %
+ str(self.__class__.__name__))
+ return Response(ex.message, status=500,
+ mimetype='application/json')
class PortChainUpdate(SFC):
resp = {
"port_chain": port_chain.create_dict(self.api.compute)
}
- return Response(json.dumps(resp), status=200, mimetype='application/json')
+ return Response(json.dumps(resp), status=200,
+ mimetype='application/json')
except Exception as ex:
- logging.exception("Neutron SFC: %s Exception." % str(self.__class__.__name__))
- return Response(ex.message, status=500, mimetype='application/json')
+ logging.exception("Neutron SFC: %s Exception." %
+ str(self.__class__.__name__))
+ return Response(ex.message, status=500,
+ mimetype='application/json')
class PortChainDelete(SFC):
self.api.compute.delete_port_chain(chain_id)
try:
- return Response("Port chain %s deleted.\n" % chain_id, status=204, mimetype='application/json')
+ return Response("", status=204,
+ mimetype='application/json')
except Exception as ex:
- logging.exception("Neutron SFC: %s Exception." % str(self.__class__.__name__))
- return Response(ex.message, status=500, mimetype='application/json')
+ logging.exception("Neutron SFC: %s Exception." %
+ str(self.__class__.__name__))
+ return Response(ex.message, status=500,
+ mimetype='application/json')
class PortChainList(SFC):
try:
port_chain_list = []
for port_chain in self.api.compute.port_chains.values():
- port_chain_list.append(port_chain.create_dict(self.api.compute))
+ port_chain_list.append(
+ port_chain.create_dict(self.api.compute))
resp = {"port_chains": port_chain_list}
- return Response(json.dumps(resp), status=200, mimetype='application/json')
+ return Response(json.dumps(resp), status=200,
+ mimetype='application/json')
except Exception as ex:
- logging.exception("Neutron SFC: %s Exception." % str(self.__class__.__name__))
- return Response(ex.message, status=500, mimetype='application/json')
+ logging.exception("Neutron SFC: %s Exception." %
+ str(self.__class__.__name__))
+ return Response(ex.message, status=500,
+ mimetype='application/json')
class PortChainShow(SFC):
logging.debug("API CALL: %s GET" % str(self.__class__.__name__))
try:
- port_chain = self.api.compute.find_port_chain_by_name_or_id(chain_id)
+ port_chain = self.api.compute.find_port_chain_by_name_or_id(
+ chain_id)
resp = {
"port_chain": port_chain.create_dict(self.api.compute)
}
- return Response(json.dumps(resp), status=200, mimetype='application/json')
+ return Response(json.dumps(resp), status=200,
+ mimetype='application/json')
except Exception as ex:
- logging.exception("Neutron SFC: %s Exception." % str(self.__class__.__name__))
- return Response(ex.message, status=500, mimetype='application/json')
+ logging.exception("Neutron SFC: %s Exception." %
+ str(self.__class__.__name__))
+ return Response(ex.message, status=500,
+ mimetype='application/json')