@@ -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