本文整理匯總了Python中wok.plugins.kimchi.model.host.DeviceModel.lookup方法的典型用法代碼示例。如果您正苦於以下問題:Python DeviceModel.lookup方法的具體用法?Python DeviceModel.lookup怎麽用?Python DeviceModel.lookup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wok.plugins.kimchi.model.host.DeviceModel
的用法示例。
在下文中一共展示了DeviceModel.lookup方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: delete
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import lookup [as 別名]
def delete(self, vmid, dev_name):
dom = VMModel.get_vm(vmid, self.conn)
xmlstr = dom.XMLDesc(0)
root = objectify.fromstring(xmlstr)
try:
hostdev = root.devices.hostdev
except AttributeError:
raise NotFoundError('KCHVMHDEV0001E',
{'vmid': vmid, 'dev_name': dev_name})
pci_devs = [(DeviceModel.deduce_dev_name(e, self.conn), e)
for e in hostdev if e.attrib['type'] == 'pci']
dev_model = DeviceModel(conn=self.conn)
dev_info = dev_model.lookup(dev_name)
is_3D_device = dev_model.is_device_3D_controller(dev_info)
if is_3D_device and DOM_STATE_MAP[dom.info()[0]] != "shutoff":
raise InvalidOperation('KCHVMHDEV0006E',
{'name': dev_info['name']})
for e in hostdev:
if DeviceModel.deduce_dev_name(e, self.conn) == dev_name:
xmlstr = etree.tostring(e)
dom.detachDeviceFlags(
xmlstr, get_vm_config_flag(dom, mode='all'))
if e.attrib['type'] == 'pci':
self._delete_affected_pci_devices(dom, dev_name, pci_devs)
if is_3D_device:
devsmodel = VMHostDevsModel(conn=self.conn)
devsmodel.update_mmio_guest(vmid, False)
break
else:
raise NotFoundError('KCHVMHDEV0001E',
{'vmid': vmid, 'dev_name': dev_name})
示例2: _delete_affected_pci_devices
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import lookup [as 別名]
def _delete_affected_pci_devices(self, dom, dev_name, pci_devs):
dev_model = DeviceModel(conn=self.conn)
try:
dev_model.lookup(dev_name)
except NotFoundError:
return
affected_names = set(
DevicesModel(
conn=self.conn).get_list(_passthrough_affected_by=dev_name))
for pci_name, e in pci_devs:
if pci_name in affected_names:
xmlstr = etree.tostring(e)
dom.detachDeviceFlags(
xmlstr, get_vm_config_flag(dom, mode='all'))
示例3: _detach_device
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import lookup [as 別名]
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']
dev_model = DeviceModel(conn=self.conn)
dev_info = dev_model.lookup(dev_name)
is_3D_device = dev_model.is_device_3D_controller(dev_info)
if is_3D_device and DOM_STATE_MAP[dom.info()[0]] != "shutoff":
raise InvalidOperation('KCHVMHDEV0006E',
{'name': dev_info['name']})
if self._hotunplug_multifunction_pci(dom, hostdev, dev_name):
if is_3D_device:
cb('Updating MMIO from VM...')
devsmodel = VMHostDevsModel(conn=self.conn)
devsmodel.update_mmio_guest(vmid, False)
cb('OK', True)
return
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
else:
raise NotFoundError('KCHVMHDEV0001E',
{'vmid': vmid, 'dev_name': dev_name})
cb('OK', True)
示例4: lookup
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import lookup [as 別名]
def lookup(self, vmid, dev_name):
dom = VMModel.get_vm(vmid, self.conn)
xmlstr = dom.XMLDesc(0)
root = objectify.fromstring(xmlstr)
try:
hostdev = root.devices.hostdev
except AttributeError:
raise NotFoundError('KCHVMHDEV0001E',
{'vmid': vmid, 'dev_name': dev_name})
dev_model = DeviceModel(conn=self.conn)
for e in hostdev:
deduced_name = DeviceModel.deduce_dev_name(e, self.conn)
if deduced_name == dev_name:
dev_info = dev_model.lookup(dev_name)
return {'name': dev_name,
'type': e.attrib['type'],
'product': dev_info.get('product', None),
'vendor': dev_info.get('vendor', None)}
raise NotFoundError('KCHVMHDEV0001E',
{'vmid': vmid, 'dev_name': dev_name})
示例5: _attach_pci_device
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import lookup [as 別名]
def _attach_pci_device(self, vmid, dev_info):
self._validate_pci_passthrough_env()
dom = VMModel.get_vm(vmid, self.conn)
# Due to libvirt limitation, we don't support live assigne device to
# vfio driver.
driver = ('vfio' if DOM_STATE_MAP[dom.info()[0]] == "shutoff" and
self.caps.kernel_vfio else 'kvm')
# on powerkvm systems it must be vfio driver.
distro, _, _ = platform.linux_distribution()
if distro == 'IBM_PowerKVM':
driver = 'vfio'
# Attach all PCI devices in the same IOMMU group
dev_model = DeviceModel(conn=self.conn)
devs_model = DevicesModel(conn=self.conn)
affected_names = devs_model.get_list(
_passthrough_affected_by=dev_info['name'])
passthrough_names = devs_model.get_list(
_cap='pci', _passthrough='true')
group_names = list(set(affected_names) & set(passthrough_names))
pci_infos = [dev_model.lookup(dev_name) for dev_name in group_names]
pci_infos.append(dev_info)
is_multifunction = len(pci_infos) > 1 and \
DOM_STATE_MAP[dom.info()[0]] == "shutoff"
pci_infos = sorted(pci_infos, key=itemgetter('name'))
# all devices in the group that is going to be attached to the vm
# must be detached from the host first
with RollbackContext() as rollback:
for pci_info in pci_infos:
try:
dev = self.conn.get().nodeDeviceLookupByName(
pci_info['name'])
dev.dettach()
except Exception:
raise OperationFailed('KCHVMHDEV0005E',
{'name': pci_info['name']})
else:
rollback.prependDefer(dev.reAttach)
rollback.commitAll()
device_flags = get_vm_config_flag(dom, mode='all')
slot = 0
if is_multifunction:
slot = self._available_slot(dom)
with RollbackContext() as rollback:
for pci_info in pci_infos:
pci_info['detach_driver'] = driver
xmlstr = self._get_pci_device_xml(pci_info,
slot,
is_multifunction)
try:
dom.attachDeviceFlags(xmlstr, device_flags)
except libvirt.libvirtError:
wok_log.error(
'Failed to attach host device %s to VM %s: \n%s',
pci_info['name'], vmid, xmlstr)
raise
rollback.prependDefer(dom.detachDeviceFlags,
xmlstr, device_flags)
rollback.commitAll()
return dev_info['name']
示例6: VMHostDevModel
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import lookup [as 別名]
class VMHostDevModel(object):
def __init__(self, **kargs):
self.conn = kargs['conn']
self.objstore = kargs['objstore']
self.events = kargs['eventsloop']
self.task = TaskModel(**kargs)
self.devs_model = DevicesModel(**kargs)
self.dev_model = DeviceModel(**kargs)
self._cb = None
self.events.registerDetachDevicesEvent(
self.conn,
self._event_devices,
self)
def lookup(self, vmid, dev_name):
dom = VMModel.get_vm(vmid, self.conn)
xmlstr = dom.XMLDesc(0)
root = objectify.fromstring(xmlstr)
try:
hostdev = root.devices.hostdev
except AttributeError:
raise NotFoundError('KCHVMHDEV0001E',
{'vmid': vmid, 'dev_name': dev_name})
for e in hostdev:
deduced_name = DeviceModel.deduce_dev_name(e, self.conn)
if deduced_name == dev_name:
dev_info = self.dev_model.lookup(dev_name)
return {'name': dev_name,
'type': e.attrib['type'],
'product': dev_info.get('product', None),
'vendor': dev_info.get('vendor', None),
'multifunction': dev_info.get('multifunction', None),
'vga3d': dev_info.get('vga3d', None)}
raise NotFoundError('KCHVMHDEV0001E',
{'vmid': vmid, 'dev_name': dev_name})
def delete(self, vmid, dev_name):
dom = VMModel.get_vm(vmid, self.conn)
xmlstr = dom.XMLDesc(0)
root = objectify.fromstring(xmlstr)
try:
hostdev = root.devices.hostdev
except AttributeError:
raise NotFoundError('KCHVMHDEV0001E',
{'vmid': vmid, 'dev_name': dev_name})
task_params = {'vmid': vmid,
'dev_name': dev_name,
'dom': dom,
'hostdev': hostdev,
'lock': threading.RLock()}
task_uri = u'/plugins/kimchi/vms/%s/hostdevs/%s' % \
(VMModel.get_vm(vmid, self.conn).name(), dev_name)
taskid = AsyncTask(task_uri, self._detach_device, task_params).id
return self.task.lookup(taskid)
def _event_devices(self, conn, dom, alias, opaque):
"""
Callback to handle add/remove devices event
"""
if opaque._cb is None:
wok_log.error('opaque must be valid')
return
wok_log.info("Device %s removed successfully" % alias)
# Re-attach device to host if it's not managed mode
if not opaque._managed:
try:
dev = conn.get().nodeDeviceLookupByName(alias)
dev.reAttach()
except libvirt.libvirtError, e:
wok_log.error(
"Unable to attach device %s back to host. Error: %s",
alias, e.message
)
else:
示例7: VMHostDevsModel
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import lookup [as 別名]
class VMHostDevsModel(object):
def __init__(self, **kargs):
self.conn = kargs['conn']
self.objstore = kargs['objstore']
self.events = kargs['eventsloop']
self.caps = CapabilitiesModel(**kargs)
self.devs_model = DevicesModel(**kargs)
self.dev_model = DeviceModel(**kargs)
self.task = TaskModel(**kargs)
self._cb = None
self.events.registerAttachDevicesEvent(
self.conn,
self._event_devices,
self)
def get_list(self, vmid):
dom = VMModel.get_vm(vmid, self.conn)
xmlstr = dom.XMLDesc(0)
root = objectify.fromstring(xmlstr)
try:
hostdev = root.devices.hostdev
except AttributeError:
return []
return [DeviceModel.deduce_dev_name(e, self.conn) for e in hostdev]
def _passthrough_device_validate(self, dev_name):
eligible_dev_names = self.devs_model.get_list(_passthrough='true')
if dev_name not in eligible_dev_names:
raise InvalidParameter('KCHVMHDEV0002E', {'dev_name': dev_name})
def _event_devices(self, conn, dom, alias, opaque):
"""
Callback to handle add/remove devices event
"""
if opaque._cb is None:
wok_log.error('opaque must be valid')
return
wok_log.info("Device %s added successfuly" % alias)
opaque._cb('OK', True)
def create(self, vmid, params):
dev_name = params['name']
dev_info = self.dev_model.lookup(dev_name)
if dev_info['device_type'] == 'pci':
taskid = AsyncTask(u'/plugins/kimchi/vms/%s/hostdevs/' %
VMModel.get_vm(vmid, self.conn).name(),
self._attach_pci_device,
{'vmid': vmid, 'dev_info': dev_info,
'lock': threading.RLock()}).id
return self.task.lookup(taskid)
with RollbackContext() as rollback:
try:
dev = self.conn.get().nodeDeviceLookupByName(dev_name)
dev.dettach()
except Exception:
raise OperationFailed('KCHVMHDEV0005E', {'name': dev_name})
else:
rollback.prependDefer(dev.reAttach)
rollback.commitAll()
taskid = AsyncTask(u'/plugins/kimchi/vms/%s/hostdevs/' %
VMModel.get_vm(vmid, self.conn).name(),
'_attach_%s_device' % dev_info['device_type'],
{'vmid': vmid, 'dev_info': dev_info,
'lock': threading.RLock()}).id
return self.task.lookup(taskid)
def _get_pci_devices_xml(self, pci_infos, slot, driver):
hostdevs = ''
# all devices included in the xml will be sorted in reverse (the
# function 0 will be the last one) and will include the guest
# address details
for dev_info in sorted(pci_infos,
key=itemgetter('function'),
reverse=True):
dev_info['detach_driver'] = driver
hostdevs += self._get_pci_device_xml(dev_info,
slot,
True)
return '<devices>%s</devices>' % hostdevs
def have_usb_controller(self, vmid):
dom = VMModel.get_vm(vmid, self.conn)
root = objectify.fromstring(dom.XMLDesc(0))
try:
controllers = root.devices.controller
except AttributeError:
return False
#.........這裏部分代碼省略.........
示例8: _attach_pci_device
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import lookup [as 別名]
def _attach_pci_device(self, cb, params):
cb('Attaching PCI device')
vmid = params['vmid']
dev_info = params['dev_info']
self._validate_pci_passthrough_env()
dom = VMModel.get_vm(vmid, self.conn)
# Due to libvirt limitation, we don't support live assigne device to
# vfio driver.
driver = ('vfio' if DOM_STATE_MAP[dom.info()[0]] == "shutoff" and
self.caps.kernel_vfio else 'kvm')
# on powerkvm systems it must be vfio driver.
distro, _, _ = platform.linux_distribution()
if distro == 'IBM_PowerKVM':
driver = 'vfio'
# Attach all PCI devices in the same IOMMU group
dev_model = DeviceModel(conn=self.conn)
devs_model = DevicesModel(conn=self.conn)
affected_names = devs_model.get_list(
_passthrough_affected_by=dev_info['name'])
passthrough_names = devs_model.get_list(
_cap='pci', _passthrough='true')
group_names = list(set(affected_names) & set(passthrough_names))
pci_infos = [dev_model.lookup(dev_name) for dev_name in group_names]
pci_infos.append(dev_info)
is_multifunction = len(pci_infos) > 1
pci_infos = sorted(pci_infos, key=itemgetter('name'))
# does not allow hot-plug of 3D graphic cards
is_3D_device = dev_model.is_device_3D_controller(dev_info)
if is_3D_device and DOM_STATE_MAP[dom.info()[0]] != "shutoff":
raise InvalidOperation('KCHVMHDEV0006E',
{'name': dev_info['name']})
# all devices in the group that is going to be attached to the vm
# must be detached from the host first
with RollbackContext() as rollback:
for pci_info in pci_infos:
try:
dev = self.conn.get().nodeDeviceLookupByName(
pci_info['name'])
dev.dettach()
except Exception:
raise OperationFailed('KCHVMHDEV0005E',
{'name': pci_info['name']})
else:
rollback.prependDefer(dev.reAttach)
rollback.commitAll()
device_flags = get_vm_config_flag(dom, mode='all')
# when attaching a 3D graphic device it might be necessary to increase
# the window size memory in order to be able to attach more than one
# device to the same guest
if is_3D_device:
self.update_mmio_guest(vmid, True)
slot = 0
if is_multifunction:
# search for the first available slot in guest xml
slot = self._available_slot(dom)
with RollbackContext() as rollback:
# multifunction hotplug is a special case where all functions
# must be attached together within one xml file, the same does
# not happen to multifunction coldplug - where each function is
# attached individually
if DOM_STATE_MAP[dom.info()[0]] != 'shutoff' and is_multifunction:
xmlstr = self._get_pci_devices_xml(pci_infos, slot, driver)
try:
dom.attachDeviceFlags(xmlstr, device_flags)
except libvirt.libvirtError:
wok_log.error(
'Failed to attach mutifunction device VM %s: \n%s',
vmid, xmlstr)
raise
rollback.prependDefer(dom.detachDeviceFlags, xmlstr,
device_flags)
rollback.commitAll()
cb('OK', True)
return
for pci_info in pci_infos:
pci_info['detach_driver'] = driver
cb('Reading source device XML')
xmlstr = self._get_pci_device_xml(pci_info,
slot,
is_multifunction)
try:
cb('Attaching device to VM')
dom.attachDeviceFlags(xmlstr, device_flags)
except libvirt.libvirtError:
wok_log.error(
#.........這裏部分代碼省略.........
示例9: VMHostDevModel
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import lookup [as 別名]
class VMHostDevModel(object):
def __init__(self, **kargs):
self.conn = kargs['conn']
self.objstore = kargs['objstore']
self.events = kargs['eventsloop']
self.task = TaskModel(**kargs)
self.devs_model = DevicesModel(**kargs)
self.dev_model = DeviceModel(**kargs)
self._cb = None
self.events.registerDetachDevicesEvent(
self.conn,
self._event_devices,
self)
def lookup(self, vmid, dev_name):
dom = VMModel.get_vm(vmid, self.conn)
xmlstr = dom.XMLDesc(0)
root = objectify.fromstring(xmlstr)
try:
hostdev = root.devices.hostdev
except AttributeError:
raise NotFoundError('KCHVMHDEV0001E',
{'vmid': vmid, 'dev_name': dev_name})
for e in hostdev:
deduced_name = DeviceModel.deduce_dev_name(e, self.conn)
if deduced_name == dev_name:
dev_info = self.dev_model.lookup(dev_name)
return {'name': dev_name,
'type': e.attrib['type'],
'product': dev_info.get('product', None),
'vendor': dev_info.get('vendor', None),
'multifunction': dev_info.get('multifunction', None),
'vga3d': dev_info.get('vga3d', None)}
raise NotFoundError('KCHVMHDEV0001E',
{'vmid': vmid, 'dev_name': dev_name})
def delete(self, vmid, dev_name):
dom = VMModel.get_vm(vmid, self.conn)
xmlstr = dom.XMLDesc(0)
root = objectify.fromstring(xmlstr)
try:
hostdev = root.devices.hostdev
except AttributeError:
raise NotFoundError('KCHVMHDEV0001E',
{'vmid': vmid, 'dev_name': dev_name})
task_params = {'vmid': vmid,
'dev_name': dev_name,
'dom': dom,
'hostdev': hostdev,
'lock': threading.RLock()}
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 _event_devices(self, conn, dom, alias, opaque):
"""
Callback to handle add/remove devices event
"""
if opaque._cb is None:
wok_log.error('opaque must be valid')
return
wok_log.info("Device %s removed successfuly" % alias)
opaque._cb('OK', True)
def _detach_device(self, cb, params):
cb('Detaching device')
self._cb = cb
vmid = params['vmid']
dev_name = params['dev_name']
dom = params['dom']
hostdev = params['hostdev']
lock = params['lock']
with lock:
pci_devs = [(DeviceModel.deduce_dev_name(e, self.conn), e)
for e in hostdev if e.attrib['type'] == 'pci']
dev_info = self.dev_model.lookup(dev_name)
is_3D_device = self.dev_model.is_device_3D_controller(dev_info)
if is_3D_device and DOM_STATE_MAP[dom.info()[0]] != "shutoff":
raise InvalidOperation('KCHVMHDEV0006E',
{'name': dev_info['name']})
if self._hotunplug_multifunction_pci(dom, hostdev, dev_name):
if is_3D_device:
devsmodel = VMHostDevsModel(conn=self.conn)
devsmodel.update_mmio_guest(vmid, False)
if DOM_STATE_MAP[dom.info()[0]] == "shutoff":
cb('OK', True)
return
#.........這裏部分代碼省略.........
示例10: VMHostDevModel
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import lookup [as 別名]
class VMHostDevModel(object):
def __init__(self, **kargs):
self.conn = kargs['conn']
self.objstore = kargs['objstore']
self.events = kargs['eventsloop']
self.task = TaskModel(**kargs)
self.devs_model = DevicesModel(**kargs)
self.dev_model = DeviceModel(**kargs)
self._cb = None
self.events.registerDetachDevicesEvent(
self.conn, self._event_devices, self)
def lookup(self, vmid, dev_name):
dom = VMModel.get_vm(vmid, self.conn)
xmlstr = dom.XMLDesc(0)
root = objectify.fromstring(xmlstr)
try:
hostdev = root.devices.hostdev
except AttributeError:
raise NotFoundError('KCHVMHDEV0001E', {
'vmid': vmid, 'dev_name': dev_name})
for e in hostdev:
deduced_name = DeviceModel.deduce_dev_name(e, self.conn)
if deduced_name == dev_name:
dev_info = self.dev_model.lookup(dev_name)
return {
'name': dev_name,
'type': e.attrib['type'],
'product': dev_info.get('product', None),
'vendor': dev_info.get('vendor', None),
'multifunction': dev_info.get('multifunction', None),
'vga3d': dev_info.get('vga3d', None),
}
raise NotFoundError('KCHVMHDEV0001E', {
'vmid': vmid, 'dev_name': dev_name})
def delete(self, vmid, dev_name):
dom = VMModel.get_vm(vmid, self.conn)
xmlstr = dom.XMLDesc(0)
root = objectify.fromstring(xmlstr)
try:
hostdev = root.devices.hostdev
except AttributeError:
raise NotFoundError('KCHVMHDEV0001E', {
'vmid': vmid, 'dev_name': dev_name})
task_params = {
'vmid': vmid,
'dev_name': dev_name,
'dom': dom,
'hostdev': hostdev,
'lock': threading.RLock(),
}
task_uri = u'/plugins/kimchi/vms/%s/hostdevs/%s' % (
VMModel.get_vm(vmid, self.conn).name(),
dev_name,
)
taskid = AsyncTask(task_uri, self._detach_device, task_params).id
return self.task.lookup(taskid)
def _event_devices(self, conn, dom, alias, opaque):
"""
Callback to handle add/remove devices event
"""
if opaque._cb is None:
wok_log.error('opaque must be valid')
return
wok_log.info('Device %s removed successfully' % alias)
# Re-attach device to host if it's not managed mode
if not opaque._managed:
try:
dev = conn.get().nodeDeviceLookupByName(alias)
dev.reAttach()
except libvirt.libvirtError as e:
wok_log.error(
'Unable to attach device %s back to host. Error: %s', alias, str(
e)
)
else:
wok_log.info(
"Device %s was attached in 'managed' mode. "
'Skipping re-attach().' % alias
)
opaque._cb('OK', True)
def _detach_device(self, cb, params):
cb('Detaching device')
self._cb = cb
vmid = params['vmid']
dev_name = params['dev_name']
dom = params['dom']
hostdev = params['hostdev']
lock = params['lock']
#.........這裏部分代碼省略.........
示例11: StoragePoolsModel
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import lookup [as 別名]
#.........這裏部分代碼省略.........
# 1 error reading VGDA
# 2 volume group doesn't exist
# 3 not all physical volumes of volume group online
# 4 volume group not found
# 5 no volume groups found at all
# 6 error reading VGDA from lvmtab
if from_vg and returncode in [2, 4, 5]:
raise InvalidOperation('KCHPOOL0038E', {'name': name})
if not from_vg and returncode not in [2, 4, 5]:
raise InvalidOperation('KCHPOOL0036E', {'name': name})
def create(self, params):
task_id = None
conn = self.conn.get()
from_vg = params.get('source', {}).get('from_vg', False)
try:
name = params['name']
if name == ISO_POOL_NAME:
raise InvalidOperation('KCHPOOL0031E')
# The user may want to create a logical pool with the same name
# used before but a volume group will already exist with this name
# So check the volume group does not exist to create the pool
if params['type'] == 'logical':
self._check_lvm(name, from_vg)
if params['type'] == 'kimchi-iso':
task_id = self._do_deep_scan(params)
if params['type'] == 'scsi':
adapter_name = params['source']['adapter_name']
extra_params = self.device.lookup(adapter_name)
# Adds name, adapter_type, wwpn and wwnn to source information
params['source'].update(extra_params)
params['fc_host_support'] = self.caps.fc_host_support
poolDef = StoragePoolDef.create(params)
poolDef.prepare(conn)
xml = poolDef.xml
except KeyError as item:
raise MissingParameter(
'KCHPOOL0004E', {'item': str(item), 'name': name})
if name in self.get_list():
raise InvalidOperation('KCHPOOL0001E', {'name': name})
try:
if task_id:
# Create transient pool for deep scan
conn.storagePoolCreateXML(xml, 0)
return name
pool = conn.storagePoolDefineXML(xml, 0)
except libvirt.libvirtError as e:
wok_log.error(f'Problem creating Storage Pool: {str(e)}')
raise OperationFailed(
'KCHPOOL0007E', {'name': name, 'err': e.get_error_message()}
)
# Build and set autostart value to pool
# Ignore error as the pool was already successfully created
# The build process fails when the pool directory already exists
try:
if params['type'] in ['logical', 'dir', 'netfs', 'scsi']: