Change in vdsm[master]: virt: dev: move getUnderlyingDeviceAddress away

fromani at redhat.com fromani at redhat.com
Fri Oct 3 07:17:08 UTC 2014


Francesco Romani has uploaded a new change for review.

Change subject: virt: dev: move getUnderlyingDeviceAddress away
......................................................................

virt: dev: move getUnderlyingDeviceAddress away

make VmDevice._getUnderlyingDeviceAddress() a function
-it never used 'self' anyway- and move it into vmxml.py.

This patch is another step towards the isolation of vm.py
from any xml processing.

Change-Id: I7e70968020877d36b555468971d327d8d569d352
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M vdsm/virt/vm.py
M vdsm/virt/vmxml.py
2 files changed, 26 insertions(+), 25 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/49/33749/1

diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 7f21085..5b710a8 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -4681,22 +4681,6 @@
         self.log.exception("Operation failed")
         return self._reportError(key, msg)
 
-    def _getUnderlyingDeviceAddress(self, devXml):
-        """
-        Obtain device's address from libvirt
-        """
-        address = {}
-        adrXml = devXml.getElementsByTagName('address')[0]
-        # Parse address to create proper dictionary.
-        # Libvirt device's address definition is:
-        # PCI = {'type':'pci', 'domain':'0x0000', 'bus':'0x00',
-        #        'slot':'0x0c', 'function':'0x0'}
-        # IDE = {'type':'drive', 'controller':'0', 'bus':'0', 'unit':'0'}
-        for key in adrXml.attributes.keys():
-            address[key.strip()] = adrXml.getAttribute(key).strip()
-
-        return address
-
     def _getUnderlyingUnknownDeviceInfo(self):
         """
         Obtain unknown devices info from libvirt.
@@ -4721,7 +4705,7 @@
 
             alias = x.getElementsByTagName('alias')[0].getAttribute('name')
             if not isKnownDevice(alias):
-                address = self._getUnderlyingDeviceAddress(x)
+                address = vmxml.device_address(x)
                 # I general case we assume that device has attribute 'type',
                 # if it hasn't getAttribute returns ''.
                 device = x.getAttribute('type')
@@ -4749,7 +4733,7 @@
             index = x.getAttribute('index')
 
             # Get controller address
-            address = self._getUnderlyingDeviceAddress(x)
+            address = vmxml.device_address(x)
 
             # In case the controller has index and/or model, they
             # are compared. Currently relevant for USB controllers.
@@ -4790,7 +4774,7 @@
             if not x.getElementsByTagName('address'):
                 address = None
             else:
-                address = self._getUnderlyingDeviceAddress(x)
+                address = vmxml.device_address(x)
             alias = x.getElementsByTagName('alias')[0].getAttribute('name')
 
             for dev in self._devices[BALLOON_DEVICES]:
@@ -4836,7 +4820,7 @@
             if not x.getElementsByTagName('address'):
                 continue
 
-            address = self._getUnderlyingDeviceAddress(x)
+            address = vmxml.device_address(x)
             alias = x.getElementsByTagName('alias')[0].getAttribute('name')
 
             for dev in self._devices[SMARTCARD_DEVICES]:
@@ -4861,7 +4845,7 @@
 
             # PCI watchdog has "address" different from ISA watchdog
             if x.getElementsByTagName('address'):
-                address = self._getUnderlyingDeviceAddress(x)
+                address = vmxml.device_address(x)
                 alias = x.getElementsByTagName('alias')[0].getAttribute('name')
 
                 for wd in self._devices[WATCHDOG_DEVICES]:
@@ -4884,7 +4868,7 @@
         for x in videosxml:
             alias = x.getElementsByTagName('alias')[0].getAttribute('name')
             # Get video card address
-            address = self._getUnderlyingDeviceAddress(x)
+            address = vmxml.device_address(x)
 
             # FIXME. We have an identification problem here.
             # Video card device has not unique identifier, except the alias
@@ -4912,7 +4896,7 @@
         for x in soundsxml:
             alias = x.getElementsByTagName('alias')[0].getAttribute('name')
             # Get sound card address
-            address = self._getUnderlyingDeviceAddress(x)
+            address = vmxml.device_address(x)
 
             # FIXME. We have an identification problem here.
             # Sound device has not unique identifier, except the alias
@@ -4966,7 +4950,7 @@
             else:
                 drv = 'raw'
             # Get disk address
-            address = self._getUnderlyingDeviceAddress(x)
+            address = vmxml.device_address(x)
 
             # Keep data as dict for easier debugging
             deviceDict = {'path': devPath, 'name': name,
@@ -5109,7 +5093,7 @@
                     network = network[len(netinfo.LIBVIRT_NET_PREFIX):]
 
             # Get nic address
-            address = self._getUnderlyingDeviceAddress(x)
+            address = vmxml.device_address(x)
             for nic in self._devices[NIC_DEVICES]:
                 if nic.macAddr.lower() == mac.lower():
                     nic.name = name
diff --git a/vdsm/virt/vmxml.py b/vdsm/virt/vmxml.py
index 5baa144..ba6e1f1 100644
--- a/vdsm/virt/vmxml.py
+++ b/vdsm/virt/vmxml.py
@@ -480,6 +480,23 @@
         return self.conf.get('maxVCpus', self._getSmp())
 
 
+def device_address(devXml):
+    """
+    Obtain device's address from libvirt
+    """
+    address = {}
+    adrXml = devXml.getElementsByTagName('address')[0]
+    # Parse address to create proper dictionary.
+    # Libvirt device's address definition is:
+    # PCI = {'type':'pci', 'domain':'0x0000', 'bus':'0x00',
+    #        'slot':'0x0c', 'function':'0x0'}
+    # IDE = {'type':'drive', 'controller':'0', 'bus':'0', 'unit':'0'}
+    for key in adrXml.attributes.keys():
+        address[key.strip()] = adrXml.getAttribute(key).strip()
+
+    return address
+
+
 if sys.version_info[:2] == (2, 6):
     # A little unrelated hack to make xml.dom.minidom.Document.toprettyxml()
     # not wrap Text node with whitespace.


-- 
To view, visit http://gerrit.ovirt.org/33749
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7e70968020877d36b555468971d327d8d569d352
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>


More information about the vdsm-patches mailing list