Fix: 5GTANGO LLCM now correctly terminates servies. 93/7093/1
authorpeusterm <manuel.peuster@uni-paderborn.de>
Thu, 10 Jan 2019 14:21:26 +0000 (15:21 +0100)
committerpeusterm <manuel.peuster@uni-paderborn.de>
Thu, 10 Jan 2019 14:21:26 +0000 (15:21 +0100)
Also adding an example topology for 5GTANGO experiments.

Change-Id: Ibb5565814e448569d3d7e7a8a28a3ed5bd45af7f
Signed-off-by: peusterm <manuel.peuster@uni-paderborn.de>
examples/tango_default_cli_topology_1_pop.py [new file with mode: 0644]
src/emuvim/api/tango/llcm.py

diff --git a/examples/tango_default_cli_topology_1_pop.py b/examples/tango_default_cli_topology_1_pop.py
new file mode 100644 (file)
index 0000000..0222099
--- /dev/null
@@ -0,0 +1,64 @@
+# Copyright (c) 2018 SONATA-NFV, 5GTANGO 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, 5GTANGO, 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 also been performed in the framework of the 5GTANGO project,
+# funded by the European Commission under Grant number 761493 through
+# the Horizon 2020 and 5G-PPP programmes. The authors would like to
+# acknowledge the contributions of their colleagues of the 5GTANGO
+# partner consortium (www.5gtango.eu).
+import logging
+from mininet.log import setLogLevel
+from emuvim.dcemulator.net import DCNetwork
+from emuvim.api.rest.rest_api_endpoint import RestApiEndpoint
+from emuvim.api.tango import TangoLLCMEndpoint
+
+logging.basicConfig(level=logging.DEBUG)
+setLogLevel('info')  # set Mininet loglevel
+logging.getLogger('werkzeug').setLevel(logging.DEBUG)
+logging.getLogger('5gtango.llcm').setLevel(logging.DEBUG)
+
+
+def create_topology():
+    net = DCNetwork(monitor=False, enable_learning=True)
+    # create two data centers
+    dc1 = net.addDatacenter("dc1")
+    # add the command line interface endpoint to the emulated DC (REST API)
+    rapi1 = RestApiEndpoint("0.0.0.0", 5001)
+    rapi1.connectDCNetwork(net)
+    rapi1.connectDatacenter(dc1)
+    rapi1.start()
+    # add the 5GTANGO lightweight life cycle manager (LLCM) to the topology
+    llcm1 = TangoLLCMEndpoint("0.0.0.0", 5000, deploy_sap=False)
+    llcm1.connectDatacenter(dc1)
+    # run the dummy gatekeeper (in another thread, don't block)
+    llcm1.start()
+    # start the emulation and enter interactive CLI
+    net.start()
+    net.CLI()
+    # when the user types exit in the CLI, we stop the emulator
+    net.stop()
+
+
+def main():
+    create_topology()
+
+
+if __name__ == '__main__':
+    main()
index bc94eb0..fbdd663 100755 (executable)
@@ -920,24 +920,32 @@ class Instantiations(fr.Resource):
         """
         # try to extract the service  and instance UUID from the request
         json_data = request.get_json(force=True)
-        service_uuid = json_data.get("service_uuid")
-        instance_uuid = json_data.get("service_instance_uuid")
-
+        service_uuid_input = json_data.get("service_uuid")
+        instance_uuid_input = json_data.get("service_instance_uuid")
+        if len(GK.services) < 1:
+            return "No service on-boarded.", 404
         # try to be fuzzy
-        if service_uuid is None and len(GK.services) > 0:
-            # if we don't get a service uuid, we simply stop the last service
-            # in the list
-            service_uuid = list(GK.services.iterkeys())[0]
-        if instance_uuid is None and len(
-                GK.services[service_uuid].instances) > 0:
-            instance_uuid = list(
-                GK.services[service_uuid].instances.iterkeys())[0]
-
-        if service_uuid in GK.services and instance_uuid in GK.services[service_uuid].instances:
-            # valid service and instance UUID, stop service
-            GK.services.get(service_uuid).stop_service(instance_uuid)
-            return "service instance with uuid %r stopped." % instance_uuid, 200
-        return "Service not found", 404
+        if service_uuid_input is None:
+            # if we don't get a service uuid we stop all services
+            service_uuid_list = list(GK.services.iterkeys())
+            LOG.info("No service_uuid given, stopping all.")
+        else:
+            service_uuid_list = [service_uuid_input]
+        # for each service
+        for service_uuid in service_uuid_list:
+            if instance_uuid_input is None:
+                instance_uuid_list = list(
+                    GK.services[service_uuid].instances.iterkeys())
+            else:
+                instance_uuid_list = [instance_uuid_input]
+            # for all service instances
+            for instance_uuid in instance_uuid_list:
+                if (service_uuid in GK.services and
+                        instance_uuid in GK.services[service_uuid].instances):
+                    # valid service and instance UUID, stop service
+                    GK.services.get(service_uuid).stop_service(instance_uuid)
+                    LOG.info("Service instance with uuid %r stopped." % instance_uuid)
+        return "Service(s) stopped.", 200
 
 
 class Exit(fr.Resource):