Change in vdsm[master]: virt: Move Vm._getUnderlyingControllerDeviceInfo() out of Vm

mzamazal at redhat.com mzamazal at redhat.com
Fri Feb 26 16:24:30 UTC 2016


Milan Zamazal has uploaded a new change for review.

Change subject: virt: Move Vm._getUnderlyingControllerDeviceInfo() out of Vm
......................................................................

virt: Move Vm._getUnderlyingControllerDeviceInfo() out of Vm

This is just a simple move of code, following the Sound device example.

Change-Id: I04cbe440e7301021878aed6905443cf7326c798d
Signed-off-by: Milan Zamazal <mzamazal at redhat.com>
---
M vdsm/virt/vm.py
M vdsm/virt/vmdevices/core.py
2 files changed, 44 insertions(+), 46 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/92/54092/1

diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index fc8904f..24e51b2 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -1726,12 +1726,12 @@
         vmdevices.core.Sound.update_device_info(self)
         vmdevices.core.Video.update_device_info(self)
         self._getUnderlyingGraphicsDeviceInfo()
-        self._getUnderlyingControllerDeviceInfo()
         self._getUnderlyingBalloonDeviceInfo()
         self._getUnderlyingWatchdogDeviceInfo()
         self._getUnderlyingSmartcardDeviceInfo()
         self._getUnderlyingRngDeviceInfo()
         self._getUnderlyingConsoleDeviceInfo()
+        vmdevices.core.Controller.update_device_info(self)
         self._getUnderlyingHostDeviceInfo()
         self._getUnderlyingMemoryDeviceInfo()
         # Obtain info of all unknown devices. Must be last!
@@ -4041,51 +4041,6 @@
                           'device': device,
                           'address': address}
                 self.conf['devices'].append(newDev)
-
-    def _getUnderlyingControllerDeviceInfo(self):
-        """
-        Obtain controller devices info from libvirt.
-        """
-        for x in self._domain.get_device_elements('controller'):
-            # Ignore controller devices without address
-            if not x.getElementsByTagName('address'):
-                continue
-            alias = x.getElementsByTagName('alias')[0].getAttribute('name')
-            device = x.getAttribute('type')
-            # Get model and index. Relevant for USB controllers.
-            model = x.getAttribute('model')
-            index = x.getAttribute('index')
-
-            # Get controller address
-            address = vmxml.device_address(x)
-
-            # In case the controller has index and/or model, they
-            # are compared. Currently relevant for USB controllers.
-            for ctrl in self._devices[hwclass.CONTROLLER]:
-                if ((ctrl.device == device) and
-                        (not hasattr(ctrl, 'index') or ctrl.index == index) and
-                        (not hasattr(ctrl, 'model') or ctrl.model == model)):
-                    ctrl.alias = alias
-                    ctrl.address = address
-            # Update vm's conf with address for known controller devices
-            # In case the controller has index and/or model, they
-            # are compared. Currently relevant for USB controllers.
-            knownDev = False
-            for dev in self.conf['devices']:
-                if ((dev['type'] == hwclass.CONTROLLER) and
-                        (dev['device'] == device) and
-                        ('index' not in dev or dev['index'] == index) and
-                        ('model' not in dev or dev['model'] == model)):
-                    dev['address'] = address
-                    dev['alias'] = alias
-                    knownDev = True
-            # Add unknown controller device to vm's conf
-            if not knownDev:
-                self.conf['devices'].append(
-                    {'type': hwclass.CONTROLLER,
-                     'device': device,
-                     'address': address,
-                     'alias': alias})
 
     def _getUnderlyingBalloonDeviceInfo(self):
         """
diff --git a/vdsm/virt/vmdevices/core.py b/vdsm/virt/vmdevices/core.py
index a13eb93..dd1404b 100644
--- a/vdsm/virt/vmdevices/core.py
+++ b/vdsm/virt/vmdevices/core.py
@@ -202,6 +202,49 @@
 
         return ctrl
 
+    @classmethod
+    def update_device_info(cls, vm):
+        for x in vm.domain.get_device_elements('controller'):
+            # Ignore controller devices without address
+            if not x.getElementsByTagName('address'):
+                continue
+            alias = x.getElementsByTagName('alias')[0].getAttribute('name')
+            device = x.getAttribute('type')
+            # Get model and index. Relevant for USB controllers.
+            model = x.getAttribute('model')
+            index = x.getAttribute('index')
+
+            # Get controller address
+            address = vmxml.device_address(x)
+
+            # In case the controller has index and/or model, they
+            # are compared. Currently relevant for USB controllers.
+            for ctrl in vm.get_devices(hwclass.CONTROLLER):
+                if ((ctrl.device == device) and
+                        (not hasattr(ctrl, 'index') or ctrl.index == index) and
+                        (not hasattr(ctrl, 'model') or ctrl.model == model)):
+                    ctrl.alias = alias
+                    ctrl.address = address
+            # Update vm's conf with address for known controller devices
+            # In case the controller has index and/or model, they
+            # are compared. Currently relevant for USB controllers.
+            knownDev = False
+            for dev in vm.conf['devices']:
+                if ((dev['type'] == hwclass.CONTROLLER) and
+                        (dev['device'] == device) and
+                        ('index' not in dev or dev['index'] == index) and
+                        ('model' not in dev or dev['model'] == model)):
+                    dev['address'] = address
+                    dev['alias'] = alias
+                    knownDev = True
+            # Add unknown controller device to vm's conf
+            if not knownDev:
+                device_conf.append(
+                    {'type': hwclass.CONTROLLER,
+                     'device': device,
+                     'address': address,
+                     'alias': alias})
+
 
 class Smartcard(Base):
     __slots__ = ('address',)


-- 
To view, visit https://gerrit.ovirt.org/54092
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I04cbe440e7301021878aed6905443cf7326c798d
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Milan Zamazal <mzamazal at redhat.com>


More information about the vdsm-patches mailing list