[virt-tools-list] [virt-manager PATCH 2/3] disk: generate target controller-wise

Martin Kletzander mkletzan at redhat.com
Wed Feb 12 17:17:59 UTC 2014


Add an optional parameter to generate_target() that controls what
controller the disk should reside in (using libvirt's rules to create
addresses).

Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
---
 virtinst/devicedisk.py | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/virtinst/devicedisk.py b/virtinst/devicedisk.py
index 330bd48..935add0 100644
--- a/virtinst/devicedisk.py
+++ b/virtinst/devicedisk.py
@@ -901,14 +901,18 @@ class VirtualDisk(VirtualDevice):
                     return _return(pref)
         return _return("sd")

-    def generate_target(self, skip_targets):
+    def generate_target(self, skip_targets, pref_ctrl=None):
         """
         Generate target device ('hda', 'sdb', etc..) for disk, excluding
-        any targets in 'skip_targets'. Sets self.target, and returns the
-        generated value
+        any targets in 'skip_targets'.  If given the 'pref_ctrl'
+        parameter, it tries to select the target so that the disk is
+        mapped onto that controller.
+        Sets self.target, and returns the generated value.

         @param skip_targets: list of targets to exclude
         @type skip_targets: C{list}
+        @param pref_ctrl: preferred controller to connect the disk to
+        @type pref_ctrl: C{int}
         @raise ValueError: can't determine target type, no targets available
         @returns generated target
         @rtype C{str}
@@ -920,7 +924,13 @@ class VirtualDisk(VirtualDevice):
         def get_target():
             first_found = None

-            for i in range(1, maxnode + 1):
+            ran = range(1, maxnode + 1)
+            if pref_ctrl:
+                # We assume narrow SCSI bus and libvirt assigning 7
+                # (0-6, 7-13, etc.) devices per controller
+                ran = range(pref_ctrl * 7, (pref_ctrl + 1) * 7)
+
+            for i in ran:
                 gen_t = prefix + self.num_to_target(i)
                 if gen_t in skip_targets:
                     skip_targets.remove(gen_t)
@@ -936,7 +946,14 @@ class VirtualDisk(VirtualDevice):
         if ret:
             self.target = ret
             return ret
-        raise ValueError(_("Only %s disks of type '%s' are supported"
-            % (maxnode, prefix)))
+
+        if pref_ctrl:
+            # This basically means that we either chose full
+            # controller or didn't add any
+            raise ValueError(_("Controller number %d for disk of type %s has "
+                               "no empty slot to use" % (pref_ctrl, prefix)))
+        else:
+            raise ValueError(_("Only %s disks of type '%s' are supported"
+                               % (maxnode, prefix)))

 VirtualDisk.register_type()
-- 
1.8.5.4




More information about the virt-tools-list mailing list