Browse Source

Adds mounted volumes auto detection

Alessandro Pilotti 10 years ago
parent
commit
62b4dc9526

+ 2 - 2
coriolis/osmorphing/manager.py

@@ -7,12 +7,12 @@ LOG = logging.getLogger(__name__)
 
 
 def morph_image(connection_info, os_type, target_hypervisor, target_platform,
-                volume_devs, nics_info, event_manager):
+                nics_info, event_manager):
     os_mount_tools = osmount_factory.get_os_mount_tools(
         os_type, connection_info, event_manager)
 
     event_manager.progress_update("Discovering and mounting OS partitions")
-    os_root_dir, other_mounted_dirs = os_mount_tools.mount_os(volume_devs)
+    os_root_dir, other_mounted_dirs = os_mount_tools.mount_os()
 
     conn = os_mount_tools.get_connection()
     os_morphing_tools, os_info = osmorphing_factory.get_os_morphing_tools(

+ 1 - 1
coriolis/osmorphing/osmount/base.py

@@ -28,7 +28,7 @@ class BaseOSMountTools(object):
         pass
 
     @abc.abstractmethod
-    def mount_os(self, volume_devs):
+    def mount_os(self):
         pass
 
     @abc.abstractmethod

+ 23 - 5
coriolis/osmorphing/osmount/ubuntu.py

@@ -1,10 +1,14 @@
 import os
 import re
 
+from oslo_log import log as logging
+
 from coriolis import exception
 from coriolis.osmorphing.osmount import base
 from coriolis import utils
 
+LOG = logging.getLogger(__name__)
+
 
 class UbuntuOSMountTools(base.BaseSSHOSMountTools):
     def check_os(self):
@@ -27,19 +31,31 @@ class UbuntuOSMountTools(base.BaseSSHOSMountTools):
                 vg_names.append(m.groups()[0])
         return vg_names
 
-    def mount_os(self, volume_devs):
+    def _get_volume_block_devices(self):
+        volume_devs = self._exec_cmd(
+            "lsblk -lnao NAME").decode().split('\n')[:-1]
+        LOG.debug("All block devices: %s", str(volume_devs))
+
+        # Skip this instance's current root device (first in the list)
+        volume_devs = ["/dev/%s" % d for d in volume_devs if
+                       not re.match(r"^.*\d+$", d)][1:]
+        LOG.info("Volume block devices: %s", str(volume_devs))
+        return volume_devs
+
+    def mount_os(self):
         dev_paths = []
         other_mounted_dirs = []
 
+        self._exec_cmd("sudo apt-get update -y")
+        self._exec_cmd("sudo apt-get install lvm2 -y")
+        self._exec_cmd("sudo modprobe dm-mod")
+
+        volume_devs = self._get_volume_block_devices()
         for volume_dev in volume_devs:
             self._exec_cmd("sudo partx -v -a %s || true" % volume_dev)
             dev_paths += self._exec_cmd(
                 "sudo ls %s*" % volume_dev).decode().split('\n')[:-1]
 
-        self._exec_cmd("sudo apt-get update -y")
-        self._exec_cmd("sudo apt-get install lvm2 -y")
-        self._exec_cmd("sudo modprobe dm-mod")
-
         for vg_name in self._get_vgnames():
             self._exec_cmd("sudo vgchange -ay %s" % vg_name)
             lvm_dev_paths = self._exec_cmd(
@@ -68,12 +84,14 @@ class UbuntuOSMountTools(base.BaseSSHOSMountTools):
             if (not os_root_dir and 'etc' in dirs and 'bin' in dirs and
                     'sbin' in dirs):
                 os_root_dir = tmp_dir
+                LOG.info("OS root device: %s", dev_path)
             # TODO: better ways to check for a linux boot dir?
             else:
                 # TODO: better ways to check for a linux boot dir?
                 if not boot_dev_path and ('grub' in dirs or 'grub2' in dirs):
                     # Needs to be remounted under os_root_dir
                     boot_dev_path = dev_path
+                    LOG.info("OS boot device: %s", dev_path)
 
                 self._exec_cmd('sudo umount %s' % tmp_dir)
 

+ 1 - 1
coriolis/osmorphing/osmount/windows.py

@@ -77,7 +77,7 @@ class WindowsMountTools(base.BaseOSMountTools):
         return self._conn.exec_ps_command(
             "(get-psdrive -PSProvider FileSystem).Root").split(self._conn.EOL)
 
-    def mount_os(self, volume_devs):
+    def mount_os(self):
         self._refresh_storage()
         self._bring_all_disks_online()
         self._set_all_disks_rw_mode()

+ 2 - 11
coriolis/providers/openstack/__init__.py

@@ -325,7 +325,7 @@ class ImportProvider(base.BaseImportProvider):
             raise
 
     @utils.retry_on_error()
-    def _attach_volume(self, nova, instance, volume, volume_dev):
+    def _attach_volume(self, nova, instance, volume, volume_dev=None):
         nova.volumes.create_server_volume(
             instance.id, volume.id, volume_dev)
         self._wait_for_volume(nova, volume, 'in-use')
@@ -448,16 +448,8 @@ class ImportProvider(base.BaseImportProvider):
                 self._event_manager.progress_update(
                     "Attaching volume to worker instance")
 
-                # TODO: improve device assignment
-                if hypervisor_type == constants.HYPERVISOR_HYPERV:
-                    volume_dev_base = "/dev/sd%s"
-                else:
-                    volume_dev_base = "/dev/vd%s"
-
-                volume_dev = volume_dev_base % chr(ord('a') + i + 1)
-                volume_devs.append(volume_dev)
                 self._attach_volume(nova, migr_resources.get_instance(),
-                                    volume, volume_dev)
+                                    volume)
 
                 guest_conn_info = migr_resources.get_guest_connection_info()
 
@@ -467,7 +459,6 @@ class ImportProvider(base.BaseImportProvider):
                                            os_type,
                                            hypervisor_type,
                                            constants.PLATFORM_OPENSTACK,
-                                           volume_devs,
                                            nics_info,
                                            self._event_manager)
         finally: