- def ns_update_vnfr(self, db_vnfrs, nsr_desc_RO):
- """
- Updates database vnfr with the RO info, e.g. ip_address, vim_id... Descriptor db_vnfrs is also updated
- :param db_vnfrs: dictionary with member-vnf-index: vnfr-content
- :param nsr_desc_RO: nsr descriptor from RO
- :return: Nothing, LcmException is raised on errors
- """
- for vnf_index, db_vnfr in db_vnfrs.items():
- for vnf_RO in nsr_desc_RO["vnfs"]:
- if vnf_RO["member_vnf_index"] != vnf_index:
- continue
- vnfr_update = {}
- if vnf_RO.get("ip_address"):
- db_vnfr["ip-address"] = vnfr_update["ip-address"] = vnf_RO[
- "ip_address"
- ].split(";")[0]
- elif not db_vnfr.get("ip-address"):
- if db_vnfr.get("vdur"): # if not VDUs, there is not ip_address
- raise LcmExceptionNoMgmtIP(
- "ns member_vnf_index '{}' has no IP address".format(
- vnf_index
- )
- )
-
- for vdu_index, vdur in enumerate(get_iterable(db_vnfr, "vdur")):
- vdur_RO_count_index = 0
- if vdur.get("pdu-type"):
- continue
- for vdur_RO in get_iterable(vnf_RO, "vms"):
- if vdur["vdu-id-ref"] != vdur_RO["vdu_osm_id"]:
- continue
- if vdur["count-index"] != vdur_RO_count_index:
- vdur_RO_count_index += 1
- continue
- vdur["vim-id"] = vdur_RO.get("vim_vm_id")
- if vdur_RO.get("ip_address"):
- vdur["ip-address"] = vdur_RO["ip_address"].split(";")[0]
- else:
- vdur["ip-address"] = None
- vdur["vdu-id-ref"] = vdur_RO.get("vdu_osm_id")
- vdur["name"] = vdur_RO.get("vim_name")
- vdur["status"] = vdur_RO.get("status")
- vdur["status-detailed"] = vdur_RO.get("error_msg")
- for ifacer in get_iterable(vdur, "interfaces"):
- for interface_RO in get_iterable(vdur_RO, "interfaces"):
- if ifacer["name"] == interface_RO.get("internal_name"):
- ifacer["ip-address"] = interface_RO.get(
- "ip_address"
- )
- ifacer["mac-address"] = interface_RO.get(
- "mac_address"
- )
- break
- else:
- raise LcmException(
- "ns_update_vnfr: Not found member_vnf_index={} vdur={} interface={} "
- "from VIM info".format(
- vnf_index, vdur["vdu-id-ref"], ifacer["name"]
- )
- )
- vnfr_update["vdur.{}".format(vdu_index)] = vdur
- break
- else:
- raise LcmException(
- "ns_update_vnfr: Not found member_vnf_index={} vdur={} count_index={} from "
- "VIM info".format(
- vnf_index, vdur["vdu-id-ref"], vdur["count-index"]
- )
- )
-
- for vld_index, vld in enumerate(get_iterable(db_vnfr, "vld")):
- for net_RO in get_iterable(nsr_desc_RO, "nets"):
- if vld["id"] != net_RO.get("vnf_net_osm_id"):
- continue
- vld["vim-id"] = net_RO.get("vim_net_id")
- vld["name"] = net_RO.get("vim_name")
- vld["status"] = net_RO.get("status")
- vld["status-detailed"] = net_RO.get("error_msg")
- vnfr_update["vld.{}".format(vld_index)] = vld
- break
- else:
- raise LcmException(
- "ns_update_vnfr: Not found member_vnf_index={} vld={} from VIM info".format(
- vnf_index, vld["id"]
- )
- )
-
- self.update_db_2("vnfrs", db_vnfr["_id"], vnfr_update)
- break
-
- else:
- raise LcmException(
- "ns_update_vnfr: Not found member_vnf_index={} from VIM info".format(
- vnf_index
- )
- )
-