Change in vdsm[master]: cleanup: make VmDevice.custom ever-present

danken at redhat.com danken at redhat.com
Wed Mar 5 10:42:44 UTC 2014


Dan Kenigsberg has uploaded a new change for review.

Change subject: cleanup: make VmDevice.custom ever-present
......................................................................

cleanup: make VmDevice.custom ever-present

Device configuration may carry a "custom properties" dictionary that is
copied into its respective VmDevice object. If no such dictionary exist,
the VmDevice.custom is never set.

This patch removes this duality. VmDevice.custom is always there, but it
may be empty if the user has not set any device-specific custom
property.

Change-Id: Icf0677b3d52c3e51c874dcb2b4df12fb3fc22c34
Signed-off-by: Dan Kenigsberg <danken at redhat.com>
---
M vdsm/vm.py
1 file changed, 14 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/91/25391/1

diff --git a/vdsm/vm.py b/vdsm/vm.py
index 467e8a5..c03513c 100644
--- a/vdsm/vm.py
+++ b/vdsm/vm.py
@@ -1238,12 +1238,13 @@
 
 class VmDevice(object):
     __slots__ = ('deviceType', 'device', 'alias', 'specParams', 'deviceId',
-                 'conf', 'log', '_deviceXML', 'type')
+                 'conf', 'log', '_deviceXML', 'type', 'custom')
 
     def __init__(self, conf, log, **kwargs):
         self.conf = conf
         self.log = log
         self.specParams = {}
+        self.custom = kwargs.pop('custom', {})
         for attr, value in kwargs.iteritems():
             try:
                 setattr(self, attr, value)
@@ -1336,7 +1337,7 @@
 
 class NetworkInterfaceDevice(VmDevice):
     __slots__ = ('nicModel', 'macAddr', 'network', 'bootOrder', 'address',
-                 'linkActive', 'portMirroring', 'custom', 'filter',
+                 'linkActive', 'portMirroring', 'filter',
                  'sndbufParam', 'driver', 'name')
 
     def __init__(self, conf, log, **kwargs):
@@ -2962,7 +2963,7 @@
 
         for devType in self._devices:
             for dev in self._devices[devType]:
-                if getattr(dev, 'custom', {}):
+                if dev.custom:
                     yield dev
 
     def _appendDevices(self, domxml):
@@ -3291,10 +3292,9 @@
 
         nicParams = params['nic']
         nic = NetworkInterfaceDevice(self.conf, self.log, **nicParams)
-        customProps = getattr(nic, 'custom', {})
         nicXml = nic.getXML().toprettyxml(encoding='utf-8')
         nicXml = hooks.before_nic_hotplug(nicXml, self.conf,
-                                          params=customProps)
+                                          params=nic.custom)
         nic._deviceXML = nicXml
         self.log.debug("Hotplug NIC xml: %s", nicXml)
 
@@ -3303,7 +3303,7 @@
         except libvirt.libvirtError as e:
             self.log.error("Hotplug failed", exc_info=True)
             nicXml = hooks.after_nic_hotplug_fail(
-                nicXml, self.conf, params=customProps)
+                nicXml, self.conf, params=nic.custom)
             if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:
                 return errCode['noVM']
             return {'status': {'code': errCode['hotplugNic']['status']['code'],
@@ -3319,7 +3319,7 @@
             self.saveState()
             self._getUnderlyingNetworkInterfaceInfo()
             hooks.after_nic_hotplug(nicXml, self.conf,
-                                    params=customProps)
+                                    params=nic.custom)
 
         if hasattr(nic, 'portMirroring'):
             mirroredNetworks = []
@@ -3493,10 +3493,9 @@
                 for network in nicParams['portMirroring']:
                     supervdsm.getProxy().unsetPortMirroring(network, nic.name)
 
-            customProps = getattr(nic, 'custom', {})
             nicXml = nic.getXML().toprettyxml(encoding='utf-8')
             hooks.before_nic_hotunplug(nicXml, self.conf,
-                                       params=customProps)
+                                       params=nic.custom)
             self.log.debug("Hotunplug NIC xml: %s", nicXml)
         else:
             self.log.error("Hotunplug NIC failed - NIC not found: %s",
@@ -3534,13 +3533,13 @@
                 self._devices[NIC_DEVICES].append(nic)
             self.saveState()
             hooks.after_nic_hotunplug_fail(nicXml, self.conf,
-                                           params=customProps)
+                                           params=nic.custom)
             return {
                 'status': {'code': errCode['hotunplugNic']['status']['code'],
                            'message': e.message}}
 
         hooks.after_nic_hotunplug(nicXml, self.conf,
-                                  params=customProps)
+                                  params=nic.custom)
         return {'status': doneCode, 'vmList': self.status()}
 
     def setNumberOfCpus(self, numberOfCpus):
@@ -3617,12 +3616,11 @@
         if drive.hasVolumeLeases:
             return errCode['noimpl']
 
-        customProps = getattr(drive, 'custom', {})
         driveXml = drive.getXML().toprettyxml(encoding='utf-8')
         self.log.debug("Hotplug disk xml: %s" % (driveXml))
 
         driveXml = hooks.before_disk_hotplug(driveXml, self.conf,
-                                             params=customProps)
+                                             params=drive.custom)
         drive._deviceXML = driveXml
         try:
             self._dom.attachDevice(driveXml)
@@ -3647,7 +3645,7 @@
             self.saveState()
             self._getUnderlyingDriveInfo()
             hooks.after_disk_hotplug(driveXml, self.conf,
-                                     params=customProps)
+                                     params=drive.custom)
 
         return {'status': doneCode, 'vmList': self.status()}
 
@@ -3671,7 +3669,6 @@
         if drive.hasVolumeLeases:
             return errCode['noimpl']
 
-        customProps = getattr(drive, 'custom', {})
         driveXml = drive.getXML().toprettyxml(encoding='utf-8')
         self.log.debug("Hotunplug disk xml: %s", driveXml)
         # Remove found disk from vm's drives list
@@ -3691,7 +3688,7 @@
         self.saveState()
 
         hooks.before_disk_hotunplug(driveXml, self.conf,
-                                    params=customProps)
+                                    params=drive.custom)
         try:
             self._dom.detachDevice(driveXml)
         except libvirt.libvirtError as e:
@@ -3709,7 +3706,7 @@
                            'message': e.message}}
         else:
             hooks.after_disk_hotunplug(driveXml, self.conf,
-                                       params=customProps)
+                                       params=drive.custom)
             self._cleanupDrives(drive)
 
         return {'status': doneCode, 'vmList': self.status()}


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icf0677b3d52c3e51c874dcb2b4df12fb3fc22c34
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Dan Kenigsberg <danken at redhat.com>


More information about the vdsm-patches mailing list