[PATCH] virt: Support for indirect image_name definition

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch adds a support to specify the disk image by re + select
instead of the image_name.

Params:
    indirect_image_select: Index of the disk from list matching disks
    image_name: regular expression (ls $image_name)

Usage:
    images += " stg"
    image_name_stg = "/dev/sd*"
    image_raw_device_stg = yes
    image_format_stg = raw
    drive_index_stg = 3
    drive_format_stg = scsi-block
    indirect_image_select_stg = -1

Signed-off-by: Lukas Doktor <ldoktor@xxxxxxxxxx>
---
 client/virt/base.cfg.sample |    2 ++
 client/virt/virt_vm.py      |   22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/client/virt/base.cfg.sample b/client/virt/base.cfg.sample
index 04bd00f..5cfd47b 100644
--- a/client/virt/base.cfg.sample
+++ b/client/virt/base.cfg.sample
@@ -248,3 +248,5 @@ netdev_peer_re = "\s{2,}(.*?): .*?\\\s(.*?):"
 
 image_clone_commnad = 'cp --reflink=auto %s %s'
 image_remove_commnad = 'rm -rf %s'
+
+indirect_image_blacklist = "/dev/hda.* /dev/sda.* /dev/sg0 /dev/md0"
diff --git a/client/virt/virt_vm.py b/client/virt/virt_vm.py
index 9df6396..8ee08b4 100644
--- a/client/virt/virt_vm.py
+++ b/client/virt/virt_vm.py
@@ -310,8 +310,30 @@ def get_image_filename(params, root_dir):
     @note: params should contain:
            image_name -- the name of the image file, without extension
            image_format -- the format of the image (qcow2, raw etc)
+    @raise VMDeviceError: When no matching disk found (in indirect method).
     """
     image_name = params.get("image_name", "image")
+    indirect_image_select = params.get("indirect_image_select")
+    if indirect_image_select:
+        re_name = image_name
+        indirect_image_select = int(indirect_image_select)
+        matching_images = utils.system_output("ls -1d %s" % re_name)
+        matching_images = sorted(matching_images.split('\n'))
+        if matching_images[-1] == '':
+            matching_images = matching_images[:-1]
+        try:
+            image_name = matching_images[indirect_image_select]
+        except IndexError:
+            raise VMDeviceError("No matching disk found for name = '%s', "
+                                "matching = '%s' and selector = '%s'" %
+                                (re_name, matching_images,
+                                 indirect_image_select))
+        for protected in params.get('indirect_image_blacklist', '').split(' '):
+            if re.match(protected, image_name):
+                raise VMDeviceError("Matching disk is in blacklist. name = '%s"
+                                    "', matching = '%s' and selector = '%s'" %
+                                    (re_name, matching_images,
+                                     indirect_image_select))
     image_format = params.get("image_format", "qcow2")
     if params.get("image_raw_device") == "yes":
         return image_name
-- 
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux