Skip to content

Commit 06a0969

Browse files
ms4onsrsmontero
authored andcommitted
B OpenNebula/one-ee#7194: Fix the check of datastore usage history (#3751)
Signed-off-by: Mirko Stojiljkovic <mstojiljkovic@opennebula.io> (cherry picked from commit 1a4d3f4)
1 parent fcb39c2 commit 06a0969

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/schedm_mad/remotes/one_drs/lib/optimizer_parser.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -703,16 +703,16 @@ def _build_disk_capacity(self, host):
703703
}
704704

705705
def _build_used_dstores(self, vm):
706-
_, _, host_ds = self.get_ds_map()
707-
vm_hist = vm.history_records.history
708-
last_rec = max(vm_hist, key=lambda item: item.seq)
709-
ds_id = last_rec.ds_id
710-
# Host DS
711-
if ds_id in host_ds.keys():
712-
self.used_host_dstores[vm.id, 0] = ds_id
713-
# Shared system ds or image ds
714-
else:
715-
self.used_shared_dstores[vm.id, 0] = ds_id
706+
if vm_hist := vm.history_records.history:
707+
last_rec = max(vm_hist, key=lambda item: item.seq)
708+
ds_id = last_rec.ds_id
709+
# Host DS
710+
_, _, host_ds = self.get_ds_map()
711+
if ds_id in host_ds.keys():
712+
self.used_host_dstores[vm.id, 0] = ds_id
713+
# Shared system ds or image ds
714+
else:
715+
self.used_shared_dstores[vm.id, 0] = ds_id
716716

717717
def get_ds_map(self) -> tuple[set[int], set[int], dict[int, int]]:
718718
shared_ds, image_ds = set(), set()
@@ -723,8 +723,7 @@ def get_ds_map(self) -> tuple[set[int], set[int], dict[int, int]]:
723723
}
724724
if ds_attrs.get("TYPE") == "IMAGE_DS":
725725
image_ds.add(int(ds.id))
726-
# elif ds_attrs.get("SHARED") == "YES":
727-
else:
726+
elif ds_attrs.get("SHARED") == "YES":
728727
shared_ds.add(int(ds.id))
729728
host_ds_dict = {
730729
int(host_ds.id): int(host.id)

0 commit comments

Comments
 (0)