本文整理匯總了Python中wok.plugins.kimchi.model.host.DeviceModel.is_device_3D_controller方法的典型用法代碼示例。如果您正苦於以下問題:Python DeviceModel.is_device_3D_controller方法的具體用法?Python DeviceModel.is_device_3D_controller怎麽用?Python DeviceModel.is_device_3D_controller使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wok.plugins.kimchi.model.host.DeviceModel
的用法示例。
在下文中一共展示了DeviceModel.is_device_3D_controller方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: delete
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import is_device_3D_controller [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: _detach_device
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import is_device_3D_controller [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)
示例3: VMHostDevsModel
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import is_device_3D_controller [as 別名]
#.........這裏部分代碼省略.........
try:
self._validate_pci_passthrough_env()
except InvalidOperation as e:
cb(e.message, False)
raise
dom = VMModel.get_vm(vmid, self.conn)
driver = 'vfio' if self.caps.kernel_vfio else 'kvm'
# 'vfio' systems requires a usb controller in order to support pci
# hotplug on Power.
if driver == 'vfio' and platform.machine().startswith('ppc') and \
DOM_STATE_MAP[dom.info()[0]] != "shutoff" and \
not self.have_usb_controller(vmid):
msg = WokMessage('KCHVMHDEV0008E', {'vmid': vmid})
cb(msg.get_text(), False)
raise InvalidOperation("KCHVMHDEV0008E", {'vmid': vmid})
# Attach all PCI devices in the same IOMMU group
affected_names = self.devs_model.get_list(
_passthrough_affected_by=dev_info['name'])
passthrough_names = self.devs_model.get_list(
_cap='pci', _passthrough='true')
group_names = list(set(affected_names) & set(passthrough_names))
pci_infos = [self.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 = self.dev_model.is_device_3D_controller(dev_info)
if is_3D_device and DOM_STATE_MAP[dom.info()[0]] != "shutoff":
msg = WokMessage('KCHVMHDEV0006E', {'name': dev_info['name']})
cb(msg.get_text(), False)
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:
msg = WokMessage('KCHVMHDEV0005E',
{'name': pci_info['name']})
cb(msg.get_text(), False)
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)
示例4: _attach_pci_device
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import is_device_3D_controller [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(
#.........這裏部分代碼省略.........
示例5: _attach_pci_device
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import is_device_3D_controller [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'))
if dev_model.is_device_3D_controller(dev_info) 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')
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 is_device_3D_controller [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
#.........這裏部分代碼省略.........
示例7: VMHostDevModel
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import is_device_3D_controller [as 別名]
#.........這裏部分代碼省略.........
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']
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 not pci_devs.get(dev_name):
raise NotFoundError(
'KCHVMHDEV0001E', {'vmid': vmid, 'dev_name': dev_name}
)
dev_name_elem = pci_devs[dev_name]
self._managed = dev_name_elem.get('managed', 'no') == 'yes'
# check for multifunction and detach all functions together
try:
multi = self.unplug_multifunction_pci(
dom, hostdev, dev_name_elem)
except libvirt.libvirtError:
multi = False
# successfully detached all functions: finish operation
if multi:
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
# detach individually
xmlstr = etree.tostring(dev_name_elem)
dom.detachDeviceFlags(xmlstr, get_vm_config_flag(dom, mode='all'))