Francesco Romani has uploaded a new change for review.

Change subject: virt: fully convert to response module
......................................................................

virt: fully convert to response module

convert the missing bits to response.{error,success}
for the sake of code clarity.

Change-Id: If1bb95b46197ba4d6c8eccaed33fd77c426a084c
Signed-off-by: Francesco Romani <[email protected]>
---
M vdsm/virt/vm.py
M vdsm/virt/vmpowerdown.py
2 files changed, 35 insertions(+), 37 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/00/40900/1

diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index ce058a0..01c2c47 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -42,7 +42,7 @@
 from vdsm import utils
 from vdsm.compat import pickle
 from vdsm.config import config
-from vdsm.define import ERROR, NORMAL, doneCode
+from vdsm.define import ERROR, NORMAL
 from vdsm.netinfo import DUMMY_BRIDGE
 from storage import outOfProcess as oop
 from storage import sd
@@ -1093,7 +1093,7 @@
                     del self.conf['pauseCode']
             except KeyError:
                 pass
-            return {'status': doneCode, 'output': ['']}
+            return response.success(output=[''])
         finally:
             if not guestCpuLocked:
                 self._guestCpuLock.release()
@@ -1110,7 +1110,7 @@
                                      guestCpuLocked=True)
             self._logGuestCpuStatus('pause')
             self._lastStatus = afterState
-            return {'status': doneCode, 'output': ['']}
+            return response.success(output=[''])
         finally:
             if not guestCpuLocked:
                 self._guestCpuLock.release()
@@ -1919,7 +1919,7 @@
                 self.hotunplugNic({'nic': nicParams})
                 return response.error('hotplugNic', e.message)
 
-        return {'status': doneCode, 'vmList': self.status()}
+        return response.success(vmList=self.status())
 
     def _lookupDeviceByAlias(self, devType, alias):
         for dev in self._devices[devType][:]:
@@ -1977,7 +1977,7 @@
             with self.setLinkAndNetwork(netDev, netConf, linkValue, network,
                                         custom, specParams):
                 with self.updatePortMirroring(netConf, netsToMirror):
-                    return {'status': doneCode, 'vmList': self.status()}
+                    return response.success(vmList=self.status())
         except (LookupError,
                 SetLinkAndNetworkError,
                 UpdatePortMirroringError) as e:
@@ -2148,7 +2148,7 @@
 
         hooks.after_nic_hotunplug(nicXml, self.conf,
                                   params=nic.custom)
-        return {'status': doneCode, 'vmList': self.status()}
+        return response.success(vmList=self.status())
 
     def setNumberOfCpus(self, numberOfCpus):
 
@@ -2169,7 +2169,7 @@
         self.conf['smp'] = str(numberOfCpus)
         self.saveState()
         hooks.after_set_num_of_cpus()
-        return {'status': doneCode, 'vmList': self.status()}
+        return response.success(vmList=self.status())
 
     def _updateVcpuLimit(self):
         qos = self._getVmPolicy()
@@ -2275,7 +2275,7 @@
                 else:
                     return response.error('updateVmPolicyErr', e.message)
 
-        return {'status': doneCode}
+        return response.success()
 
     def _getVmPolicy(self):
         """
@@ -2380,7 +2380,7 @@
                           found_device.name, xml)
             found_device._deviceXML = xml
 
-        return {'status': doneCode}
+        return response.success()
 
     def _createTransientDisk(self, diskParams):
         if (diskParams.get('shared', None) !=
@@ -2464,7 +2464,7 @@
             hooks.after_disk_hotplug(driveXml, self.conf,
                                      params=drive.custom)
 
-        return {'status': doneCode, 'vmList': self.status()}
+        return response.success(vmList=self.status())
 
     def hotunplugDisk(self, params):
         if self.isMigrating():
@@ -2521,7 +2521,7 @@
                                        params=drive.custom)
             self._cleanupDrives(drive)
 
-        return {'status': doneCode, 'vmList': self.status()}
+        return response.success(vmList=self.status())
 
     def _readPauseCode(self):
         state, reason = self._dom.state(0)
@@ -2864,7 +2864,7 @@
         # If all the drives are the current ones, return success
         if len(newDrives) == 0:
             self.log.debug('all the drives are already in use, success')
-            return {'status': doneCode}
+            return response.success()
 
         preparedDrives = {}
 
@@ -2970,9 +2970,10 @@
 
         # Returning quiesce to notify the manager whether the guest agent
         # froze and flushed the filesystems or not.
-        return {'status': doneCode, 'quiesce':
-                (snapFlags & libvirt.VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE
-                    == libvirt.VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE)}
+        guestDidQuiesce = (
+            snapFlags & libvirt.VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE
+            == libvirt.VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE)
+        return response.success(quiesce=guestDidQuiesce)
 
     def _setDiskReplica(self, srcDrive, dstDisk):
         """
@@ -3064,7 +3065,7 @@
                 self.log.exception("Initial extension request failed for %s",
                                    srcDrive.name)
 
-        return {'status': doneCode}
+        return response.success()
 
     def diskReplicateFinish(self, srcDisk, dstDisk):
         try:
@@ -3148,7 +3149,7 @@
             self._delDiskReplica(srcDrive)
             self.startDisksStatsCollection()
 
-        return {'status': doneCode}
+        return response.success()
 
     def _startDriveReplication(self, drive, replica):
         flags = (libvirt.VIR_DOMAIN_BLOCK_REBASE_COPY |
@@ -3198,7 +3199,7 @@
             self._setVolumeSize(drive.domainID, drive.poolID, drive.imageID,
                                 drive.volumeID, newVirtualSize)
 
-        return {'status': doneCode, 'size': str(newVirtualSize)}
+        return response.success(size=str(newVirtualSize))
 
     def _diskSizeExtendRaw(self, drive, newSizeBytes):
         # Picking up the volume size extension
@@ -3231,7 +3232,7 @@
                 "reboot", volSize.apparentsize, exc_info=True)
             return response.error('updateDevice')
 
-        return {'status': doneCode, 'size': str(volSize.apparentsize)}
+        return response.success(size=str(volSize.apparentsize))
 
     def diskSizeExtend(self, driveSpecs, newSizeBytes):
         try:
@@ -3309,7 +3310,7 @@
             self.cif.teardownVolumePath(self.conf[vmDev])
 
         self.conf[vmDev] = path
-        return {'status': doneCode, 'vmList': self.status()}
+        return response.success(vmList=self.status())
 
     def setTicket(self, otp, seconds, connAct, params):
         """
@@ -3338,7 +3339,7 @@
             res = response.error('ticketErr', unicode(tmo))
         else:
             hooks.after_vm_set_ticket(self._domain.xml, self.conf, params)
-            res = {'status': doneCode}
+            res = response.success()
         return res
 
     def _reviveTicket(self, newlife):
@@ -3443,7 +3444,7 @@
 
         with self._releaseLock:
             if self._released:
-                return {'status': doneCode}
+                return response.success()
 
             self.log.info('Release VM resources')
             self.lastStatus = vmstatus.POWERING_DOWN
@@ -3473,7 +3474,7 @@
 
             self._released = True
 
-        return {'status': doneCode}
+        return response.success()
 
     def _destroyVmGraceful(self):
         try:
@@ -3490,7 +3491,7 @@
                 if e.get_error_code() == libvirt.VIR_ERR_OPERATION_FAILED:
                     return self._destroyVmForceful()
                 return response.error('destroyErr')
-        return {'status': doneCode}
+        return response.success()
 
     def _destroyVmForceful(self):
         try:
@@ -3499,7 +3500,7 @@
             self.log.warning("Failed to destroy VM '%s'",
                              self.conf['vmId'], exc_info=True)
             return response.error('destroyErr')
-        return {'status': doneCode}
+        return response.success()
 
     def deleteVm(self):
         """
@@ -3521,7 +3522,7 @@
         # Clean VM from the system
         self.deleteVm()
 
-        return {'status': doneCode}
+        return response.success()
 
     def doDestroy(self):
         for dev in self._customDevices():
@@ -3561,7 +3562,7 @@
                     dev['target'] = target
             # persist the target value to make it consistent after recovery
             self.saveState()
-            return {'status': doneCode}
+            return response.success()
 
     def setCpuTuneQuota(self, quota):
         try:
@@ -3593,7 +3594,7 @@
         except libvirt.libvirtError as e:
             return self._reportException(key='cpuTuneErr', msg=e.message)
         else:
-            return {'status': doneCode}
+            return response.success()
 
     def _reportException(self, key, msg=None):
         """
@@ -4454,7 +4455,7 @@
         # of getVmStats after this returns will see the new job
         self.updateVmJobs()
 
-        return {'status': doneCode}
+        return response.success()
 
     def _diskXMLGetVolumeChainInfo(self, diskXML, drive):
         def find_element_by_name(doc, name):
diff --git a/vdsm/virt/vmpowerdown.py b/vdsm/virt/vmpowerdown.py
index 2382a88..aae927d 100644
--- a/vdsm/virt/vmpowerdown.py
+++ b/vdsm/virt/vmpowerdown.py
@@ -19,8 +19,8 @@
 #
 import libvirt
 
+from vdsm import response
 from vdsm import utils
-from vdsm.define import doneCode, errCode
 
 
 class VmPowerDown(object):
@@ -69,15 +69,12 @@
             self.event.clear()
 
             self.chain.start()
-            return {'status': {'code': doneCode['code'],
-                               'message': self.returnMsg}}
+            return response.success(message=self.returnMsg)
         else:
             # No tools, no ACPI
-            return {
-                'status': {
-                    'code': errCode['exist']['status']['code'],
-                    'message': 'VM without ACPI or active oVirt guest agent. '
-                               'Try Forced Shutdown.'}}
+            return response.error('exist',
+                                  message='VM without ACPI or active oVirt '
+                                          'guest agent. Try Forced Shutdown.')
 
 
 class VmShutdown(VmPowerDown):


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If1bb95b46197ba4d6c8eccaed33fd77c426a084c
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to