[Kimchi-devel] [PATCH] [Kimchi 2/2] Make detach device return an AsyncTask
pvital at linux.vnet.ibm.com
pvital at linux.vnet.ibm.com
Wed Apr 20 15:02:58 UTC 2016
From: Paulo Vital <pvital at linux.vnet.ibm.com>
Modified VMHostDev class to be an AsyncResource and return an AsyncTask when
deleting a specific resource (a.k.a. detach a device from a VM).
This patch is part of the solution for Kimchi Issue #817
Signed-off-by: Paulo Vital <pvital at linux.vnet.ibm.com>
---
control/vm/hostdevs.py | 4 ++--
model/vmhostdevs.py | 24 ++++++++++++++++++++++++
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/control/vm/hostdevs.py b/control/vm/hostdevs.py
index b0c4d1d..e9fd5dc 100644
--- a/control/vm/hostdevs.py
+++ b/control/vm/hostdevs.py
@@ -17,7 +17,7 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-from wok.control.base import AsyncCollection, Resource
+from wok.control.base import AsyncCollection, AsyncResource
from wok.control.utils import UrlSubNode
@@ -46,7 +46,7 @@ class VMHostDevs(AsyncCollection):
})
-class VMHostDev(Resource):
+class VMHostDev(AsyncResource):
def __init__(self, model, vmid, ident):
super(VMHostDev, self).__init__(model, ident)
self.vmid = vmid
diff --git a/model/vmhostdevs.py b/model/vmhostdevs.py
index 2927472..7051324 100644
--- a/model/vmhostdevs.py
+++ b/model/vmhostdevs.py
@@ -420,6 +420,8 @@ class VMHostDevsModel(object):
class VMHostDevModel(object):
def __init__(self, **kargs):
self.conn = kargs['conn']
+ self.objstore = kargs['objstore']
+ self.task = TaskModel(**kargs)
def lookup(self, vmid, dev_name):
dom = VMModel.get_vm(vmid, self.conn)
@@ -457,6 +459,23 @@ class VMHostDevModel(object):
raise NotFoundError('KCHVMHDEV0001E',
{'vmid': vmid, 'dev_name': dev_name})
+ task_params = {'vmid': vmid,
+ 'dev_name': dev_name,
+ 'dom': dom,
+ 'hostdev': hostdev}
+ task_uri = u'/plugins/kimchi/vms/%s/hostdevs/%s' % \
+ (VMModel.get_vm(vmid, self.conn).name(), dev_name)
+ taskid = add_task(task_uri, self._detach_device, self.objstore,
+ task_params)
+ return self.task.lookup(taskid)
+
+ def _detach_device(self, cb, params):
+ cb('Detaching device.')
+ vmid = params['vmid']
+ dev_name = params['dev_name']
+ dom = params['dom']
+ hostdev = params['hostdev']
+
pci_devs = [(DeviceModel.deduce_dev_name(e, self.conn), e)
for e in hostdev if e.attrib['type'] == 'pci']
@@ -470,11 +489,14 @@ class VMHostDevModel(object):
for e in hostdev:
if DeviceModel.deduce_dev_name(e, self.conn) == dev_name:
xmlstr = etree.tostring(e)
+ cb('Detaching device from VM...')
dom.detachDeviceFlags(
xmlstr, get_vm_config_flag(dom, mode='all'))
if e.attrib['type'] == 'pci':
+ cb('Deleting affected PCI devices...')
self._delete_affected_pci_devices(dom, dev_name, pci_devs)
if is_3D_device:
+ cb('Updating MMIO from VM...')
devsmodel = VMHostDevsModel(conn=self.conn)
devsmodel.update_mmio_guest(vmid, False)
break
@@ -482,6 +504,8 @@ class VMHostDevModel(object):
raise NotFoundError('KCHVMHDEV0001E',
{'vmid': vmid, 'dev_name': dev_name})
+ cb('OK', True)
+
def _delete_affected_pci_devices(self, dom, dev_name, pci_devs):
dev_model = DeviceModel(conn=self.conn)
try:
--
2.5.5
More information about the Kimchi-devel
mailing list