本文整理匯總了Python中wok.plugins.kimchi.model.host.DeviceModel.deduce_dev_name方法的典型用法代碼示例。如果您正苦於以下問題:Python DeviceModel.deduce_dev_name方法的具體用法?Python DeviceModel.deduce_dev_name怎麽用?Python DeviceModel.deduce_dev_name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wok.plugins.kimchi.model.host.DeviceModel
的用法示例。
在下文中一共展示了DeviceModel.deduce_dev_name方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: delete
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import deduce_dev_name [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
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import deduce_dev_name [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']
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)
break
else:
raise NotFoundError('KCHVMHDEV0001E',
{'vmid': vmid, 'dev_name': dev_name})
示例3: lookup
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import deduce_dev_name [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})
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})
示例4: _detach_device
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import deduce_dev_name [as 別名]
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'))
if dev_name_elem.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)
if DOM_STATE_MAP[dom.info()[0]] == 'shutoff':
cb('OK', True)
示例5: _detach_device
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import deduce_dev_name [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)
示例6: get_list
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import deduce_dev_name [as 別名]
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]
示例7: _count_3D_devices_attached
# 需要導入模塊: from wok.plugins.kimchi.model.host import DeviceModel [as 別名]
# 或者: from wok.plugins.kimchi.model.host.DeviceModel import deduce_dev_name [as 別名]
def _count_3D_devices_attached(self, dom):
counter = 0
root = objectify.fromstring(dom.XMLDesc(0))
try:
hostdev = root.devices.hostdev
except AttributeError:
return counter
for device in hostdev:
if device.attrib['type'] != 'pci':
continue
name = DeviceModel.deduce_dev_name(device, self.conn)
info = self.dev_model.lookup(name)
if 'vga3d' in info and info['vga3d']:
counter += 1
return counter