5GTANGO LLCM: Preliminary fix of the E-LINE configruation.
[osm/vim-emu.git] / src / emuvim / api / tango / llcm.py
index fbdd663..14c9e0b 100755 (executable)
@@ -240,27 +240,33 @@ class Service(object):
         Extract resource limits from deployment units.
         """
         # defaults
-        cpu_list = "1"
+        cpu_list = None
         cpu_period, cpu_quota = self._calculate_cpu_cfs_values(float(1.0))
-        mem_limit = 0
+        mem_limit = None
         # update from descriptor
         if "resource_requirements" in deployment_unit:
             res_req = deployment_unit.get("resource_requirements")
-            cpu_list = res_req.get("cpu").get("cores")
+            cpu_list = res_req.get("cpu").get("cpuset")
             if cpu_list is None:
                 cpu_list = res_req.get("cpu").get("vcpus")
-            cpu_bw = res_req.get("cpu").get("cpu_bw", 1.0)
+            if cpu_list is not None:
+                # attention: docker expects list as string w/o spaces:
+                cpu_list = str(cpu_list).replace(" ", "").strip()
+            cpu_bw = res_req.get("cpu").get("cpu_bw")
+            if cpu_bw is None:
+                cpu_bw = 1.0
             cpu_period, cpu_quota = self._calculate_cpu_cfs_values(float(cpu_bw))
-            mem_num = str(res_req.get("memory").get("size", 2))
+            mem_limit = res_req.get("memory").get("size")
             mem_unit = str(res_req.get("memory").get("size_unit", "GB"))
-            mem_limit = float(mem_num)
-            if mem_unit == "GB":
-                mem_limit = mem_limit * 1024 * 1024 * 1024
-            elif mem_unit == "MB":
-                mem_limit = mem_limit * 1024 * 1024
-            elif mem_unit == "KB":
-                mem_limit = mem_limit * 1024
-            mem_limit = int(mem_limit)
+            if mem_limit is not None:
+                mem_limit = int(mem_limit)
+                # to bytes
+                if "G" in mem_unit:
+                    mem_limit = mem_limit * 1024 * 1024 * 1024
+                elif "M" in mem_unit:
+                    mem_limit = mem_limit * 1024 * 1024
+                elif "K" in mem_unit:
+                    mem_limit = mem_limit * 1024
         return cpu_list, cpu_period, cpu_quota, mem_limit
 
     def _start_vnfd(self, vnfd, vnf_id, **kwargs):
@@ -329,7 +335,7 @@ class Service(object):
                 image=docker_image_name,
                 cpu_quota=cpu_quota,
                 cpu_period=cpu_period,
-                cpuset=cpu_list,
+                cpuset_cpus=cpu_list,
                 mem_limit=mem_limit,
                 volumes=volumes,
                 properties=cenv,  # environment
@@ -372,6 +378,8 @@ class Service(object):
         "vnf_id" taken from an NSD.
         :return: list
         """
+        if vnf_id is None:
+            return None
         r = list()
         for vnfi in self.instances[instance_uuid]["vnf_instances"]:
             if vnf_id in vnfi.name:
@@ -417,7 +425,6 @@ class Service(object):
             env = config.get("Env", list())
             for env_var in env:
                 var, cmd = map(str.strip, map(str, env_var.split('=', 1)))
-                # LOG.debug("%r = %r" % (var, cmd))
                 if var == "SON_EMU_CMD" or var == "VIM_EMU_CMD":
                     LOG.info("Executing script in '{}': {}={}"
                              .format(vnfi.name, var, cmd))
@@ -522,23 +529,33 @@ class Service(object):
         cookie = 1
         for link in eline_fwd_links:
             LOG.info("Found E-Line: {}".format(link))
-            # check if we need to deploy this link when its a management link:
-            if USE_DOCKER_MGMT:
-                if self.check_mgmt_interface(
-                        link["connection_points_reference"]):
-                    continue
-
             src_id, src_if_name = parse_interface(
                 link["connection_points_reference"][0])
             dst_id, dst_if_name = parse_interface(
                 link["connection_points_reference"][1])
-            setChaining = False
-            LOG.info("Creating E-Line: src={}, dst={}"
-                     .format(src_id, dst_id))
+            LOG.info("Searching C/VDU for E-Line: src={}, src_if={}, dst={}, dst_if={}"
+                     .format(src_id, src_if_name, dst_id, dst_if_name))
+            # handle C/VDUs (ugly hack, only one V/CDU per VNF for now)
+            src_units = self._get_vnf_instance_units(instance_uuid, src_id)
+            dst_units = self._get_vnf_instance_units(instance_uuid, dst_id)
+            if src_units is None or dst_units is None:
+                LOG.info("No VNF-VNF link. Skipping: src={}, src_if={}, dst={}, dst_if={}"
+                         .format(src_id, src_if_name, dst_id, dst_if_name))
+                return
+            # we only support VNFs with one V/CDU right now
+            if len(src_units) != 1 or len(dst_units) != 1:
+                raise BaseException("LLCM does not support E-LINES for multi V/CDU VNFs.")
+            # get the full name from that C/VDU and use it as src_id and dst_id
+            src_id = src_units[0].name
+            dst_id = dst_units[0].name
+            # from here we have all info we need
+            LOG.info("Creating E-Line for C/VDU: src={}, src_if={}, dst={}, dst_if={}"
+                     .format(src_id, src_if_name, dst_id, dst_if_name))
             # get involved vnfis
-            src_vnfi = self._get_vnf_instance(instance_uuid, src_id)
-            dst_vnfi = self._get_vnf_instance(instance_uuid, dst_id)
-
+            src_vnfi = src_units[0]
+            dst_vnfi = dst_units[0]
+            # proceed with chaining setup
+            setChaining = False
             if src_vnfi is not None and dst_vnfi is not None:
                 setChaining = True
                 # re-configure the VNFs IP assignment and ensure that a new