- for vdur in get_iterable(db_vnfr, "vdur"):
- if (vdur["vdu-id-ref"] == vdu_id and vdur["count-index"] == vdu_index) or \
- (ip_address and vdur.get("ip-address") == ip_address):
- if vdur.get("status") == "ACTIVE":
- target_vdu_id = vdur["vdu-id-ref"]
- elif vdur.get("status") == "ERROR":
- raise LcmException("Cannot inject ssh-key because target VM is in error state")
- break
- else:
+ vdur = next((x for x in get_iterable(db_vnfr, "vdur") if x.get("ip-address") == ip_address), None)
+ else: # VDU case
+ vdur = next((x for x in get_iterable(db_vnfr, "vdur")
+ if x.get("vdu-id-ref") == vdu_id and x.get("count-index") == vdu_index), None)
+
+ if not vdur: