-
- # looks the first nsi fulfilling the conditions but not being the current NSIR
- if nsi:
- nsi_admin_shared = nsi["_admin"]["nsrs-detailed-list"]
- for nsi_nsr_item in nsi_admin_shared:
- if nsi_nsr_item["nsd-id"] == nsr_item["nsd-id"] and nsi_nsr_item["shared"]:
- self.add_shared_nsr_2vld(nsir, nsr_item)
- nslcmops.append(nsi_nsr_item["nslcmop_instantiate"])
- _update = {"_admin.nsrs-detailed-list.{}".format(index): nsi_nsr_item}
- self.db.set_one("nsis", {"_id": nsir["_id"]}, _update)
- break
- # continue to not create nslcmop since nsrs is shared and nsrs was created
- continue
- else:
- self.add_shared_nsr_2vld(nsir, nsr_item)
+ if nsi: # other nsi is using this nsr and it needs this nsr instantiated
+ continue # do not create nsilcmop
+ else: # instantiate
+ # looks the first nsi fulfilling the conditions but not being the current NSIR
+ if nsi:
+ nsi_nsr_item = next(n for n in nsi["_admin"]["nsrs-detailed-list"] if
+ n["nsrId"] == nsr_id and n["shared"] and
+ n["nslcmop_instantiate"])
+ self.add_shared_nsr_2vld(nsir, nsr_item)
+ nslcmops.append(nsi_nsr_item["nslcmop_instantiate"])
+ _update = {"_admin.nsrs-detailed-list.{}".format(index): nsi_nsr_item}
+ self.db.set_one("nsis", {"_id": nsir["_id"]}, _update)
+ # continue to not create nslcmop since nsrs is shared and nsrs was created
+ continue
+ else:
+ self.add_shared_nsr_2vld(nsir, nsr_item)