Change in vdsm[master]: vm: use response.error() with custom message
fromani at redhat.com
fromani at redhat.com
Mon Mar 16 15:49:26 UTC 2015
Francesco Romani has uploaded a new change for review.
Change subject: vm: use response.error() with custom message
......................................................................
vm: use response.error() with custom message
Use the newly introduced response.error() in
Vm flows when we need to use a custom
error message.
Change-Id: I1c75970111bcc93308919a928a90afd2c44ec18c
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M vdsm/virt/vm.py
1 file changed, 12 insertions(+), 30 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/02/38802/1
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index bb2ab62..0d09070 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -38,6 +38,7 @@
from vdsm import libvirtconnection
from vdsm import netinfo
from vdsm import qemuimg
+from vdsm import response
from vdsm import utils
from vdsm.compat import pickle
from vdsm.config import config
@@ -2343,8 +2344,7 @@
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'],
- 'message': e.message}}
+ return response.error('hotplugNic', e.message)
else:
# FIXME! We may have a problem here if vdsm dies right after
# we sent command to libvirt and before save conf. In this case
@@ -2373,9 +2373,7 @@
network)
nicParams['portMirroring'] = mirroredNetworks
self.hotunplugNic({'nic': nicParams})
- return {'status':
- {'code': errCode['hotplugNic']['status']['code'],
- 'message': e.message}}
+ return response.error('hotplugNic', e.message)
return {'status': doneCode, 'vmList': self.status()}
@@ -2439,9 +2437,7 @@
except (LookupError,
SetLinkAndNetworkError,
UpdatePortMirroringError) as e:
- return {'status':
- {'code': errCode['updateDevice']['status']['code'],
- 'message': e.message}}
+ return response.error('updateDevice', e.message)
@contextmanager
def setLinkAndNetwork(self, dev, conf, linkValue, networkValue, custom,
@@ -2572,9 +2568,7 @@
else:
self.log.error("Hotunplug NIC failed - NIC not found: %s",
nicParams)
- return {'status': {'code': errCode['hotunplugNic']
- ['status']['code'],
- 'message': "NIC not found"}}
+ return response.error('hotunplugNic', "NIC not found")
# Remove found NIC from vm's NICs list
if nic:
@@ -2606,9 +2600,7 @@
self.saveState()
hooks.after_nic_hotunplug_fail(nicXml, self.conf,
params=nic.custom)
- return {
- 'status': {'code': errCode['hotunplugNic']['status']['code'],
- 'message': e.message}}
+ return response.error('hotunplugNic', e.message)
hooks.after_nic_hotunplug(nicXml, self.conf,
params=nic.custom)
@@ -2628,8 +2620,7 @@
self.log.exception("setNumberOfCpus failed")
if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:
return errCode['noVM']
- return {'status': {'code': errCode['setNumberOfCpusErr']
- ['status']['code'], 'message': e.message}}
+ return response.error('setNumberOfCpusErr', e.message)
self.conf['smp'] = str(numberOfCpus)
self.saveState()
@@ -2916,9 +2907,7 @@
self.cif.teardownVolumePath(diskParams)
if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:
return errCode['noVM']
- return {'status': {'code': errCode['hotplugDisk']
- ['status']['code'],
- 'message': e.message}}
+ return response.error('hotplugDisk', e.message)
else:
# FIXME! We may have a problem here if vdsm dies right after
# we sent command to libvirt and before save conf. In this case
@@ -2947,10 +2936,7 @@
except LookupError:
self.log.error("Hotunplug disk failed - Disk not found: %s",
diskParams)
- return {'status': {
- 'code': errCode['hotunplugDisk']['status']['code'],
- 'message': "Disk not found"
- }}
+ return response.error('hotunplugDisk', "Disk not found")
if drive.hasVolumeLeases:
return errCode['noimpl']
@@ -2987,9 +2973,7 @@
with self._confLock:
self.conf['devices'].append(diskDev)
self.saveState()
- return {
- 'status': {'code': errCode['hotunplugDisk']['status']['code'],
- 'message': e.message}}
+ return response.error('hotunplugDisk', e.message)
else:
hooks.after_disk_hotunplug(driveXml, self.conf,
params=drive.custom)
@@ -3788,8 +3772,7 @@
try:
self._dom.updateDeviceFlags(graphics.toxml(), 0)
except TimeoutError as tmo:
- res = {'status': {'code': errCode['ticketErr']['status']['code'],
- 'message': unicode(tmo)}}
+ res = response.error('ticketErr', unicode(tmo))
else:
hooks.after_vm_set_ticket(self._domain.xml, self.conf, params)
res = {'status': doneCode}
@@ -4046,8 +4029,7 @@
if msg is None:
error = errCode[key]
else:
- error = {'status': {'code': errCode[key]
- ['status']['code'], 'message': msg}}
+ error = response.error(key, msg)
return error
def _reportException(self, key, msg=None):
--
To view, visit https://gerrit.ovirt.org/38802
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1c75970111bcc93308919a928a90afd2c44ec18c
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