1
1
# Copyright 2016 Cloudbase Solutions Srl
2
2
# All Rights Reserved.
3
3
4
+ import re
5
+
4
6
from oslo_log import log as logging
5
7
6
8
from coriolis import constants
14
16
LOG = logging .getLogger (__name__ )
15
17
16
18
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
+
17
48
class OSMorphingTask (base .TaskRunner ):
18
49
19
50
@classmethod
@@ -28,7 +59,7 @@ def get_required_task_info_properties(cls):
28
59
29
60
@classmethod
30
61
def get_returned_task_info_properties (cls ):
31
- return []
62
+ return ["instance_deployment_info" ]
32
63
33
64
@classmethod
34
65
def get_required_provider_types (cls ):
@@ -53,6 +84,7 @@ def _run(self, ctxt, instance, origin, destination, task_info,
53
84
osmorphing_connection_info = base .unmarshal_migr_conn_info (
54
85
task_info ['osmorphing_connection_info' ])
55
86
osmorphing_info = task_info .get ('osmorphing_info' , {})
87
+ instance_deployment_info = task_info .get ('instance_deployment_info' , {})
56
88
57
89
user_scripts = task_info .get ("user_scripts" )
58
90
instance_script = None
@@ -72,7 +104,13 @@ def _run(self, ctxt, instance, origin, destination, task_info,
72
104
instance_script ,
73
105
event_handler )
74
106
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 }
76
114
77
115
78
116
class DeployOSMorphingResourcesTask (base .TaskRunner ):
0 commit comments