mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-23 17:34:21 +03:00
Add target_to_num method
Opposite to num_to_target. It will be used in future patch. Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
55e85b1612
commit
a9c791b5b8
@ -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")
|
||||
|
@ -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@redhat.com>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
@ -474,6 +474,20 @@ 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':
|
||||
# This case is here for 'xvda'
|
||||
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",
|
||||
|
Loading…
Reference in New Issue
Block a user