X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=inline;f=NG-RO%2Fosm_ng_ro%2Fns.py;h=b71f1b462dfbab51d393320dd8530e64c2d6699b;hb=2fbb3a264e4117f4a6569fede6558836d67ac4a4;hp=a7c1562861c26c891f40933513554423d265fdfb;hpb=6585ea3e5a2b68ed7ca3afb72ec816cb841f624d;p=osm%2FRO.git diff --git a/NG-RO/osm_ng_ro/ns.py b/NG-RO/osm_ng_ro/ns.py index a7c15628..b71f1b46 100644 --- a/NG-RO/osm_ng_ro/ns.py +++ b/NG-RO/osm_ng_ro/ns.py @@ -31,6 +31,7 @@ from cryptography.hazmat.primitives import serialization as crypto_serialization from cryptography.hazmat.primitives.asymmetric import rsa from jinja2 import ( Environment, + select_autoescape, StrictUndefined, TemplateError, TemplateNotFound, @@ -77,8 +78,8 @@ def get_process_id(): if text_id: return text_id - except Exception: - pass + except Exception as error: + logging.exception(f"{error} occured while getting process id") # Return a random id return "".join(random_choice("0123456789abcdef") for _ in range(12)) @@ -380,7 +381,10 @@ class Ns(object): str: [description] """ try: - env = Environment(undefined=StrictUndefined) + env = Environment( + undefined=StrictUndefined, + autoescape=select_autoescape(default_for_string=True, default=True), + ) template = env.from_string(cloud_init_content) return template.render(params or {}) @@ -1649,7 +1653,7 @@ class Ns(object): target_record_id = "{}.{}".format(db_record, existing_item["id"]) item_ = item - if target_vim.startswith("sdn"): + if target_vim.startswith("sdn") or target_vim.startswith("wim"): # item must be sdn-net instead of net if target_vim is a sdn item_ = "sdn_net" target_record_id += ".sdn" @@ -1697,7 +1701,7 @@ class Ns(object): target_record_id = "{}.{}".format(db_record, target_item["id"]) item_ = item - if target_vim.startswith("sdn"): + if target_vim.startswith("sdn") or target_vim.startswith("wim"): # item must be sdn-net instead of net if target_vim is a sdn item_ = "sdn_net" target_record_id += ".sdn" @@ -2050,15 +2054,23 @@ class Ns(object): # Check each VNF of the target for target_vnf in target_list: - # Find this VNF in the list from DB - vnfr_id = target_vnf.get("vnfInstanceId", None) - if vnfr_id: - existing_vnf = db_vnfrs.get(vnfr_id) - db_record = "vnfrs:{}:{}".format(vnfr_id, db_path) - # vim_account_id = existing_vnf.get("vim-account-id", "") + # Find this VNF in the list from DB, raise exception if vnfInstanceId is not found + vnfr_id = target_vnf["vnfInstanceId"] + existing_vnf = db_vnfrs.get(vnfr_id) + db_record = "vnfrs:{}:{}".format(vnfr_id, db_path) + # vim_account_id = existing_vnf.get("vim-account-id", "") + target_vdus = target_vnf.get("additionalParams", {}).get("vdu", []) # Check each VDU of this VNF - for target_vdu in target_vnf["additionalParams"].get("vdu", None): + if not target_vdus: + # Create target_vdu_list from DB, if VDUs are not specified + target_vdus = [] + for existing_vdu in existing_vnf.get("vdur"): + vdu_name = existing_vdu.get("vdu-name", None) + vdu_index = existing_vdu.get("count-index", 0) + vdu_to_be_healed = {"vdu-id": vdu_name, "count-index": vdu_index} + target_vdus.append(vdu_to_be_healed) + for target_vdu in target_vdus: vdu_name = target_vdu.get("vdu-id", None) # For multi instance VDU count-index is mandatory # For single session VDU count-indes is 0