Refactoring: Made complete codebase PEP8 compatible.
[osm/vim-emu.git] / src / emuvim / api / openstack / openstack_dummies / neutron_sfc_dummy_api.py
index 1494bce..f2ea6bb 100644 (file)
@@ -1,38 +1,32 @@
-"""
-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):
@@ -52,8 +46,10 @@ class PortPairsCreate(SFC):
             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
@@ -66,10 +62,13 @@ class PortPairsCreate(SFC):
             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):
@@ -87,10 +86,13 @@ 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):
@@ -102,8 +104,10 @@ class PortPairsDelete(SFC):
             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):
@@ -115,10 +119,13 @@ class PortPairsList(SFC):
                 port_pair_list.append(port_pair.create_dict(self.api.compute))
             resp = {"port_pairs": port_pair_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 PortPairsShow(SFC):
@@ -130,10 +137,13 @@ 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')
 
 
 ###############################################################################
@@ -147,20 +157,25 @@ class PortPairGroupCreate(SFC):
         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):
@@ -169,7 +184,8 @@ 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:
@@ -180,10 +196,13 @@ class PortPairGroupUpdate(SFC):
             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):
@@ -195,8 +214,10 @@ class PortPairGroupDelete(SFC):
             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):
@@ -205,13 +226,17 @@ 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):
@@ -219,14 +244,18 @@ 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')
 
 
 ###############################################################################
@@ -240,7 +269,8 @@ class FlowClassifierCreate(SFC):
         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:
@@ -252,9 +282,11 @@ class FlowClassifierCreate(SFC):
             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:
@@ -269,10 +301,13 @@ class FlowClassifierCreate(SFC):
             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):
@@ -281,7 +316,8 @@ 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:
@@ -290,10 +326,13 @@ class FlowClassifierUpdate(SFC):
             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):
@@ -305,8 +344,10 @@ class FlowClassifierDelete(SFC):
             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):
@@ -315,13 +356,17 @@ 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):
@@ -329,14 +374,18 @@ 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')
 
 
 ###############################################################################
@@ -350,7 +399,8 @@ class PortChainCreate(SFC):
         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"]
@@ -364,10 +414,13 @@ class PortChainCreate(SFC):
             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):
@@ -394,10 +447,13 @@ 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):
@@ -409,8 +465,10 @@ class PortChainDelete(SFC):
             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):
@@ -419,13 +477,17 @@ 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):
@@ -433,11 +495,15 @@ 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')