5GTANGO LLCM: Instance-specific env. configs.
Change-Id: Id50bd7b6329e3e9d8b4a4a5d39730861b940371f
Signed-off-by: peusterm <manuel.peuster@uni-paderborn.de>
diff --git a/src/emuvim/api/tango/__init__.py b/src/emuvim/api/tango/__init__.py
index 6bebaa5..e96aa19 100755
--- a/src/emuvim/api/tango/__init__.py
+++ b/src/emuvim/api/tango/__init__.py
@@ -46,7 +46,7 @@
def __init__(self, listenip, port, deploy_sap=False, docker_management=False,
auto_deploy=False, auto_delete=False, sap_vnfd_path=None,
- placement_algorithm_obj=None):
+ placement_algorithm_obj=None, env_conf_folder=None):
self.dcs = {}
self.ip = listenip
self.port = port
@@ -59,6 +59,7 @@
# Default placement is RR placement
placement_algorithm_obj = llcm.RoundRobinDcPlacement()
llcm.PLACEMENT_ALGORITHM_OBJ = placement_algorithm_obj
+ llcm.PER_INSTANCE_ENV_CONFIGURATION_FOLDER = env_conf_folder
LOG.info("Created 5GTANGO LLCM API endpoint %s" % self)
LOG.info("Using placement algorithm: {}".format(
placement_algorithm_obj))
diff --git a/src/emuvim/api/tango/llcm.py b/src/emuvim/api/tango/llcm.py
index 1d55d11..8b4a350 100755
--- a/src/emuvim/api/tango/llcm.py
+++ b/src/emuvim/api/tango/llcm.py
@@ -93,11 +93,15 @@
# offset for this: NEW_PORT (SSIID * OFFSET) + ORIGINAL_PORT
MULTI_INSTANCE_PORT_OFFSET = 1000
-
# Selected Placement Algorithm: Points to the class of the selected
# placement algorithm.
PLACEMENT_ALGORITHM_OBJ = None
+# Path to folder with <container_name>.env.yml files that contain
+# environment variables injected into the specific container
+# when it is started.
+PER_INSTANCE_ENV_CONFIGURATION_FOLDER = None
+
class OnBoardingException(BaseException):
pass
@@ -388,6 +392,10 @@
" Overwriting SON_EMU_CMD_STOP.")
cenv["SON_EMU_CMD_STOP"] = VNFD_CMD_STOP
+ # 5.2 inject per instance configurations based on envs
+ conf_envs = self._load_instance_conf_envs(vnf_container_instance_name)
+ cenv.update(conf_envs)
+
# 6. Start the container
LOG.info("Starting %r as %r in DC %r" %
(vnf_name, vnf_container_instance_name, target_dc))
@@ -521,6 +529,26 @@
t.start()
break # only execute one command
+ def _load_instance_conf_envs(self, cname):
+ """
+ Try to load an instance-specific env file. If not found,
+ just return an empty dict.
+ """
+ if PER_INSTANCE_ENV_CONFIGURATION_FOLDER is None:
+ return dict()
+ try:
+ path = os.path.expanduser(PER_INSTANCE_ENV_CONFIGURATION_FOLDER)
+ path = os.path.join(path, "{}.env.yml".format(cname))
+ res = load_yaml(path)
+ LOG.info("Loaded instance-specific env file for '{}': {}"
+ .format(cname, res))
+ return res
+ except BaseException as ex:
+ LOG.info("No instance-specific env file found for: {}"
+ .format(cname))
+ del ex
+ return dict()
+
def _unpack_service_package(self):
"""
unzip *.son file and store contents in CATALOG_FOLDER/services/<service_uuid>/