[virt-tools-list] [virt-manager PATCH 1/3] Add target_to_num method
Martin Kletzander
mkletzan at redhat.com
Wed Feb 12 17:17:58 UTC 2014
Opposite to num_to_target. It will be used in future patch.
Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
---
tests/xmlconfig.py | 13 +++++++++++++
virtinst/devicedisk.py | 15 ++++++++++++++-
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/tests/xmlconfig.py b/tests/xmlconfig.py
index c885738..9db51cb 100644
--- a/tests/xmlconfig.py
+++ b/tests/xmlconfig.py
@@ -1027,6 +1027,16 @@ class TestXMLConfig(unittest.TestCase):
self.assertEquals("zz", VirtualDisk.num_to_target(27 * 26))
self.assertEquals("aaa", VirtualDisk.num_to_target(27 * 26 + 1))
+ self.assertEquals(VirtualDisk.target_to_num("hda"), 1)
+ self.assertEquals(VirtualDisk.target_to_num("hdb"), 2)
+ self.assertEquals(VirtualDisk.target_to_num("sdz"), 26)
+ self.assertEquals(VirtualDisk.target_to_num("sdaa"), 27)
+ self.assertEquals(VirtualDisk.target_to_num("vdab"), 28)
+ self.assertEquals(VirtualDisk.target_to_num("vdaz"), 52)
+ self.assertEquals(VirtualDisk.target_to_num("xvdba"), 53)
+ self.assertEquals(VirtualDisk.target_to_num("xvdzz"), 27 * 26)
+ self.assertEquals(VirtualDisk.target_to_num("xvdaaa"), 27 * 26 + 1)
+
disk = virtinst.VirtualDisk(utils.get_conn())
disk.bus = "ide"
@@ -1035,6 +1045,9 @@ class TestXMLConfig(unittest.TestCase):
self.assertEquals("hdc", disk.generate_target(["hdb", "sda"]))
self.assertEquals("hdb", disk.generate_target(["hda", "hdd"]))
+ disk.bus = "scsi"
+ self.assertEquals("sdh", disk.generate_target(["sda", "sdg"], 1))
+
def testFedoraTreeinfo(self):
i = utils.make_distro_installer(
location="tests/cli-test-xml/fakefedoratree")
diff --git a/virtinst/devicedisk.py b/virtinst/devicedisk.py
index ce038de..330bd48 100644
--- a/virtinst/devicedisk.py
+++ b/virtinst/devicedisk.py
@@ -1,7 +1,7 @@
#
# Classes for building disk device xml
#
-# Copyright 2006-2008, 2012-2013 Red Hat, Inc.
+# Copyright 2006-2008, 2012-2014 Red Hat, Inc.
# Jeremy Katz <katzj at redhat.com>
#
# This program is free software; you can redistribute it and/or modify
@@ -474,6 +474,19 @@ class VirtualDisk(VirtualDevice):
return gen_t
+ @staticmethod
+ def target_to_num(tgt):
+ """
+ Convert disk /dev number (like hda, hdb, hdaa, etc.) to an index
+ """
+ num = 0
+ if tgt[0] == 'x'
+ tgt = tgt[1:]
+ for i, c in enumerate(reversed(tgt[2:])):
+ num += (ord(c) - ord('a') + 1) * (26 ** i)
+ return num
+
+
_XML_PROP_ORDER = [
"type", "device",
"driver_name", "driver_type",
--
1.8.5.4
More information about the virt-tools-list
mailing list