X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=NG-RO%2Fosm_ng_ro%2Fns.py;h=b95667fae88a4b60750aca23db89ee25f88b2f10;hb=refs%2Fchanges%2F79%2F11479%2F4;hp=a7d8aa61e31c1a7a041289baa54d5972c95acb18;hpb=686720bb2f845cd70af053e3b13ffb0a37f53691;p=osm%2FRO.git diff --git a/NG-RO/osm_ng_ro/ns.py b/NG-RO/osm_ng_ro/ns.py index a7d8aa61..b95667fa 100644 --- a/NG-RO/osm_ng_ro/ns.py +++ b/NG-RO/osm_ng_ro/ns.py @@ -755,6 +755,119 @@ class Ns(object): return extra_dict + @staticmethod + def _ip_profile_to_ro( + ip_profile: Dict[str, Any], + ) -> Dict[str, Any]: + """[summary] + + Args: + ip_profile (Dict[str, Any]): [description] + + Returns: + Dict[str, Any]: [description] + """ + if not ip_profile: + return None + + ro_ip_profile = { + "ip_version": "IPv4" + if "v4" in ip_profile.get("ip-version", "ipv4") + else "IPv6", + "subnet_address": ip_profile.get("subnet-address"), + "gateway_address": ip_profile.get("gateway-address"), + "dhcp_enabled": ip_profile.get("dhcp-params", {}).get("enabled", False), + "dhcp_start_address": ip_profile.get("dhcp-params", {}).get( + "start-address", None + ), + "dhcp_count": ip_profile.get("dhcp-params", {}).get("count", None), + } + + if ip_profile.get("dns-server"): + ro_ip_profile["dns_address"] = ";".join( + [v["address"] for v in ip_profile["dns-server"] if v.get("address")] + ) + + if ip_profile.get("security-group"): + ro_ip_profile["security_group"] = ip_profile["security-group"] + + return ro_ip_profile + + @staticmethod + def _process_net_params( + target_vld: Dict[str, Any], + indata: Dict[str, Any], + vim_info: Dict[str, Any], + target_record_id: str, + ) -> Dict[str, Any]: + """Function to process network parameters. + + Args: + target_vld (Dict[str, Any]): [description] + indata (Dict[str, Any]): [description] + vim_info (Dict[str, Any]): [description] + target_record_id (str): [description] + + Returns: + Dict[str, Any]: [description] + """ + extra_dict = {} + + if vim_info.get("sdn"): + # vnf_preffix = "vnfrs:{}".format(vnfr_id) + # ns_preffix = "nsrs:{}".format(nsr_id) + # remove the ending ".sdn + vld_target_record_id, _, _ = target_record_id.rpartition(".") + extra_dict["params"] = { + k: vim_info[k] + for k in ("sdn-ports", "target_vim", "vlds", "type") + if vim_info.get(k) + } + + # TODO needed to add target_id in the dependency. + if vim_info.get("target_vim"): + extra_dict["depends_on"] = [ + f"{vim_info.get('target_vim')} {vld_target_record_id}" + ] + + return extra_dict + + if vim_info.get("vim_network_name"): + extra_dict["find_params"] = { + "filter_dict": { + "name": vim_info.get("vim_network_name"), + }, + } + elif vim_info.get("vim_network_id"): + extra_dict["find_params"] = { + "filter_dict": { + "id": vim_info.get("vim_network_id"), + }, + } + elif target_vld.get("mgmt-network"): + extra_dict["find_params"] = { + "mgmt": True, + "name": target_vld["id"], + } + else: + # create + extra_dict["params"] = { + "net_name": ( + f"{indata.get('name')[:16]}-{target_vld.get('name', target_vld.get('id'))[:16]}" + ), + "ip_profile": Ns._ip_profile_to_ro(vim_info.get("ip_profile")), + "provider_network_profile": vim_info.get("provider_network"), + } + + if not target_vld.get("underlay"): + extra_dict["params"]["net_type"] = "bridge" + else: + extra_dict["params"]["net_type"] = ( + "ptp" if target_vld.get("type") == "ELINE" else "data" + ) + + return extra_dict + def deploy(self, session, indata, version, nsr_id, *args, **kwargs): self.logger.debug("ns.deploy nsr_id={} indata={}".format(nsr_id, indata)) validate_input(indata, deploy_schema) @@ -811,87 +924,6 @@ class Ns(object): index += 1 - def _ip_profile_2_ro(ip_profile): - if not ip_profile: - return None - - ro_ip_profile = { - "ip_version": "IPv4" - if "v4" in ip_profile.get("ip-version", "ipv4") - else "IPv6", - "subnet_address": ip_profile.get("subnet-address"), - "gateway_address": ip_profile.get("gateway-address"), - "dhcp_enabled": ip_profile.get("dhcp-params", {}).get( - "enabled", False - ), - "dhcp_start_address": ip_profile.get("dhcp-params", {}).get( - "start-address", None - ), - "dhcp_count": ip_profile.get("dhcp-params", {}).get("count", None), - } - - if ip_profile.get("dns-server"): - ro_ip_profile["dns_address"] = ";".join( - [v["address"] for v in ip_profile["dns-server"]] - ) - - if ip_profile.get("security-group"): - ro_ip_profile["security_group"] = ip_profile["security-group"] - - return ro_ip_profile - - def _process_net_params(target_vld, indata, vim_info, target_record_id): - extra_dict = {} - - if vim_info.get("sdn"): - # vnf_preffix = "vnfrs:{}".format(vnfr_id) - # ns_preffix = "nsrs:{}".format(nsr_id) - # remove the ending ".sdn - vld_target_record_id, _, _ = target_record_id.rpartition(".") - extra_dict["params"] = { - k: vim_info[k] - for k in ("sdn-ports", "target_vim", "vlds", "type") - if vim_info.get(k) - } - - # TODO needed to add target_id in the dependency. - if vim_info.get("target_vim"): - extra_dict["depends_on"] = [ - vim_info.get("target_vim") + " " + vld_target_record_id - ] - - return extra_dict - - if vim_info.get("vim_network_name"): - extra_dict["find_params"] = { - "filter_dict": {"name": vim_info.get("vim_network_name")} - } - elif vim_info.get("vim_network_id"): - extra_dict["find_params"] = { - "filter_dict": {"id": vim_info.get("vim_network_id")} - } - elif target_vld.get("mgmt-network"): - extra_dict["find_params"] = {"mgmt": True, "name": target_vld["id"]} - else: - # create - extra_dict["params"] = { - "net_name": "{}-{}".format( - indata["name"][:16], - target_vld.get("name", target_vld["id"])[:16], - ), - "ip_profile": _ip_profile_2_ro(vim_info.get("ip_profile")), - "provider_network_profile": vim_info.get("provider_network"), - } - - if not target_vld.get("underlay"): - extra_dict["params"]["net_type"] = "bridge" - else: - extra_dict["params"]["net_type"] = ( - "ptp" if target_vld.get("type") == "ELINE" else "data" - ) - - return extra_dict - def _process_vdu_params(target_vdu, indata, vim_info, target_record_id): nonlocal vnfr_id nonlocal nsr_id @@ -1280,7 +1312,7 @@ class Ns(object): db_update=db_nsr_update, db_path="vld", item="net", - process_params=_process_net_params, + process_params=Ns._process_net_params, ) step = "process NS images" @@ -1325,7 +1357,7 @@ class Ns(object): db_update=db_vnfrs_update[vnfr["_id"]], db_path="vld", item="net", - process_params=_process_net_params, + process_params=Ns._process_net_params, ) target_list = target_vnf.get("vdur") if target_vnf else None