Skip to content

Commit a618c02

Browse files
committed
Hotfix: Keep volumes order on VM recreation
The `list_volumes` should return volumes in correct order based on their indexes. It returned volumes in random order without the fix. Signed-off-by: Anton Kremenetsky <anton.kremenetsky@gmail.com>
1 parent 5c885fc commit a618c02

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

genesis_core/compute/pool/drivers/libvirt.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import time
2020
import typing as tp
2121
import uuid as sys_uuid
22+
import operator
2223
from xml.dom import minidom
2324

2425
# It's more efficient to use ElementTree than minidom
@@ -839,7 +840,11 @@ def list_volumes(
839840
if machine is None:
840841
return volumes
841842

842-
return [v for v in volumes if v.machine == machine.uuid]
843+
# Return volumes sorted by index for specific machine.
844+
# Otherwise volumes can be shuffled during machine recreation.
845+
machine_volumes = [v for v in volumes if v.machine == machine.uuid]
846+
machine_volumes.sort(key=operator.attrgetter("index"))
847+
return machine_volumes
843848

844849
def get_volume(self, volume: sys_uuid.UUID) -> models.MachineVolume:
845850
storage_pool = self._client.storagePoolLookupByName(self._spec.storage_pool)

0 commit comments

Comments
 (0)