Skip to content

Commit ea4a832

Browse files
ms4onsrsmontero
authored andcommitted
B #7176: Fix incorrect datastore handling (#3740)
Signed-off-by: Mirko Stojiljkovic <mstojiljkovic@opennebula.io> (cherry picked from commit 2255885)
1 parent 96635df commit ea4a832

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

src/schedm_mad/remotes/one_drs/lib/mapper/ilp_optimizer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,9 @@ def _add_variables(self) -> None:
512512
# continue
513513
if (vm_id, req_id) in used_shared_dstores:
514514
dstore_id = used_shared_dstores[vm_id, req_id]
515-
x_next_dstore_shared[vm_id, req_id, dstore_id] = 1.0
516-
continue
515+
if dstore_id in set(dstore_match.shared_dstores):
516+
x_next_dstore_shared[vm_id, req_id, dstore_id] = 1.0
517+
continue
517518
for host_id, disk_ids in dstore_match.host_dstores.items():
518519
for disk_id in disk_ids:
519520
x_name_idx = f"{vm_id}_{req_id}_{host_id}_{disk_id}"

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -704,20 +704,15 @@ def _build_disk_capacity(self, host):
704704

705705
def _build_used_dstores(self, vm):
706706
_, _, host_ds = self.get_ds_map()
707-
for idx, disk in enumerate(vm.template.disk):
708-
ds_id = int(
709-
next(
710-
e.text
711-
for e in disk.any_element
712-
if e.qname.upper() == "DATASTORE_ID"
713-
)
714-
)
715-
# Host DS
716-
if ds_id in host_ds.keys():
717-
self.used_host_dstores[(vm.id, idx)] = ds_id
718-
# Shared system ds or image ds
719-
else:
720-
self.used_shared_dstores[(vm.id, idx)] = ds_id
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
721716

722717
def get_ds_map(self) -> tuple[set[int], set[int], dict[int, int]]:
723718
shared_ds, image_ds = set(), set()
@@ -728,7 +723,8 @@ def get_ds_map(self) -> tuple[set[int], set[int], dict[int, int]]:
728723
}
729724
if ds_attrs.get("TYPE") == "IMAGE_DS":
730725
image_ds.add(int(ds.id))
731-
elif ds_attrs.get("SHARED") == "YES":
726+
# elif ds_attrs.get("SHARED") == "YES":
727+
else:
732728
shared_ds.add(int(ds.id))
733729
host_ds_dict = {
734730
int(host_ds.id): int(host.id)

0 commit comments

Comments
 (0)