summaryrefslogtreecommitdiff
path: root/virtinst
diff options
context:
space:
mode:
authorMartin Kletzander <mkletzan@redhat.com>2014-02-12 15:44:40 +0100
committerMartin Kletzander <mkletzan@redhat.com>2014-02-12 21:55:32 +0100
commita9c791b5b86b93745454a159eb6d5945fb4ae5c1 (patch)
treec97e0a8a37f4b03b96de80ca29ef416da65f9c43 /virtinst
parent55e85b16121e73475a8eb1652be7e43a42d2dd9d (diff)
downloadvirt-manager-a9c791b5b86b93745454a159eb6d5945fb4ae5c1.tar.gz
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>
Diffstat (limited to 'virtinst')
-rw-r--r--virtinst/devicedisk.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/virtinst/devicedisk.py b/virtinst/devicedisk.py
index ce038ded..e69a0e92 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@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",