11# Copyright 2016 Cloudbase Solutions Srl
22# All Rights Reserved.
33
4+ import re
5+
46from oslo_log import log as logging
57
68from coriolis import constants
1416LOG = logging .getLogger (__name__ )
1517
1618
19+ def _reorder_root_disk (volumes_info , root_device ):
20+ """
21+ Reorders volumes_info so that the root disk will always be the first volume
22+
23+ root_device is returned by the osmount tools as the root partition device
24+ (i.e. /dev/vdd2). We need to strip the trailing digits to get the actual
25+ disk device. After that, we convert the last letter of the disk device name
26+ into the equivalent index by alphabetical order (starting with 0, so 'a' -> 0).
27+ Then we just swap the indexes in the volumes_info list.
28+ """
29+ if not root_device :
30+ LOG .warn ('os_root_dev was not returned by OSMount Tools. '
31+ 'Skipping root disk reordering' )
32+ return
33+
34+ pattern = r'[0-9]'
35+ root_disk = re .sub (pattern , '' , root_device )
36+ disk_nmb = ord (root_disk [- 1 ]) - 98
37+ if disk_nmb :
38+ if disk_nmb < len (volumes_info ):
39+ volumes_info [0 ], volumes_info [disk_nmb ] = (
40+ volumes_info [disk_nmb ], volumes_info [0 ])
41+ else :
42+ LOG .warn ('Disk device name index out of range: %s for device %s'
43+ 'Skipping root disk reordering' , disk_nmb , root_disk )
44+ return
45+
46+
47+
1748class OSMorphingTask (base .TaskRunner ):
1849
1950 @classmethod
@@ -28,7 +59,7 @@ def get_required_task_info_properties(cls):
2859
2960 @classmethod
3061 def get_returned_task_info_properties (cls ):
31- return []
62+ return ["instance_deployment_info" ]
3263
3364 @classmethod
3465 def get_required_provider_types (cls ):
@@ -53,6 +84,7 @@ def _run(self, ctxt, instance, origin, destination, task_info,
5384 osmorphing_connection_info = base .unmarshal_migr_conn_info (
5485 task_info ['osmorphing_connection_info' ])
5586 osmorphing_info = task_info .get ('osmorphing_info' , {})
87+ instance_deployment_info = task_info .get ('instance_deployment_info' , {})
5688
5789 user_scripts = task_info .get ("user_scripts" )
5890 instance_script = None
@@ -72,7 +104,13 @@ def _run(self, ctxt, instance, origin, destination, task_info,
72104 instance_script ,
73105 event_handler )
74106
75- return {}
107+ volumes_info = instance_deployment_info .get ('volumes_info' , [])
108+ LOG .debug ('Volumes info before root disk reordering: %s' , volumes_info )
109+ _reorder_root_disk (volumes_info , osmorphing_info .get ('os_root_dev' ))
110+ LOG .debug ('Volumes info after root disk reordering: %s' , volumes_info )
111+
112+ return {
113+ 'instance_deployment_info' : instance_deployment_info }
76114
77115
78116class DeployOSMorphingResourcesTask (base .TaskRunner ):
0 commit comments