X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2Fvim-emu.git;a=blobdiff_plain;f=src%2Femuvim%2Fapi%2Ftango%2Fllcm.py;h=8b4a35064f270f5b18e086e29d45a288b4fee455;hp=1d55d1163f9a52ff256f3c0361612ae55a2d1a8d;hb=5a5f40533189c4bc21ffe2daed13dd2fa68a2d0b;hpb=36d4033918dd7b076fe4db5eba6e3eb8698b27dc 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 @@ VNF_STOP_WAIT_TIME = 5 # 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 .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 @@ class Service(object): " 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 @@ class Service(object): 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//