- def _look_for_pdu(self, vdur, vnfr, vim_account): # TODO feature 1417: project_id
- """
- Look for a free PDU in the catalog matching vdur type and interfaces. Fills vdur with ip_address information
- :param vdur: vnfr:vdur descriptor. It is modified with pdu interface info if pdu is found
- :param member_vnf_index: used just for logging. Target vnfd of nsd
- :param vim_account:
- :return: vder_update: dictionary to update vnfr:vdur with pdu info. In addition it modified choosen pdu to set
- at status IN_USE
- """
- pdu_type = vdur.get("pdu-type")
- assert pdu_type
- pdu_filter = {
- "vim.vim_accounts": vim_account,
- "type": pdu_type,
- "_admin.operationalState": "ENABLED",
- "_admin.usageSate": "NOT_IN_USE",
- # TODO feature 1417: "shared": True,
- # TODO feature 1417: "_admin.projects_read.cont": ["ANY", project_id],
- }
- available_pdus = self.db.get_list("pdus", pdu_filter)
- for pdu in available_pdus:
- # step 1 check if this pdu contains needed interfaces:
- match_interfaces = True
- for vdur_interface in vdur["interfaces"]:
- for pdu_interface in pdu["interfaces"]:
- if pdu_interface["name"] == vdur_interface["name"]:
- # TODO feature 1417: match per mgmt type
- break
- else: # no interface found
- match_interfaces = False
- break
- if not match_interfaces:
- continue
-
- # step 2. Update pdu
- self.update_db_2("pdus", pdu["_id"], {"_admin.usageSate": "IN_USE",
- "_admin.usage.vnfr_id": vnfr["_id"],
- "_admin.usage.nsr_id": vnfr["nsr-id-ref"],
- "_admin.usage.vdur": vdur["vdu-id-ref"],
- })
- # step 3. Fill vnfr info by filling vdur
- vdur["pdu-id"] = pdu["_id"]
- for vdur_interface in vdur["interfaces"]:
- for pdu_interface in pdu["interfaces"]:
- if pdu_interface["name"] == vdur_interface["name"]:
- vdur_interface.update(pdu_interface)
- break
-
- return
- raise LcmException("No PDU of type={} found for member_vng_index={} at vim_account={} matching interface "
- "names".format(vdur["vdu-id-ref"], vnfr["member-vnf-index-ref"], pdu_type))
-