Vinzenz Feenstra has uploaded a new change for review.
Change subject: vdsm: Get underlying device info moved to Device classes
......................................................................
vdsm: Get underlying device info moved to Device classes
Change-Id: I8f797baece3601b885777784f611b420523828f7
Signed-off-by: Vinzenz Feenstra <vfeenstr(a)redhat.com>
---
M vdsm/vm.py
1 file changed, 379 insertions(+), 396 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/32/19732/1
diff --git a/vdsm/vm.py b/vdsm/vm.py
index 4f2f35d..d23cd21 100644
--- a/vdsm/vm.py
+++ b/vdsm/vm.py
@@ -1196,6 +1196,98 @@
element.setAttrs(**elemAttrs)
return element
+ @classmethod
+ def _getDeviceAlias(cls, device):
+ return
device.getElementsByTagName('alias')[0].getAttribute('name')
+
+ @classmethod
+ def _getDeviceAddress(cls, device):
+ """
+ Obtain device's address from libvirt
+ """
+ address = {}
+ dom = device.getElementsByTagName('address')[0]
+ # Parse address to create proper dictionary.
+ # Libvirt device's address definition is:
+ # PCI = {'type':'pci', 'domain':'0x0000',
'bus':'0x00',
+ # 'slot':'0x0c', 'function':'0x0'}
+ # IDE = {'type':'drive', 'controller':'0',
'bus':'0', 'unit':'0'}
+ for key in dom.attributes.keys():
+ address[key.strip()] = dom.getAttribute(key).strip()
+
+ return address
+
+ @classmethod
+ def _defaultUpdate(cls, element, type, desc, devices, conf, **kwargs):
+ getAddress = kwargs.get('address', True)
+ getAddressRequired = False
+ if 'getAddressRequired' in kwargs:
+ getAddressRequired = kwargs.get('aliasRequired')
+ getAddress = getAddressRequired
+
+ default = desc.getElementsByTagName(element)
+ for x in default:
+ if getAddressRequired:
+ if not x.getElementsByTagName('address'):
+ continue
+
+ address = None
+ if getAddress:
+ address = cls._getDeviceAddress(x)
+
+ alias = cls._getDeviceAliasName(x)
+
+ for x in devices[type]:
+ if address and not hasattr(x, 'address'):
+ x.address = address
+ if alias and not hasattr(x, 'alias'):
+ x.alias = alias
+
+ for dev in conf['devices']:
+ if dev['type'] == type:
+ if address and not dev.get('address'):
+ dev['address'] = address
+ if alias and not dev.get('alias'):
+ dev['alias'] = alias
+
+ @classmethod
+ def updateFromDesc(cls, desc, devices, conf):
+ pass
+
+
+class UnknownDevice(VmDevice):
+ @classmethod
+ def updateFromDesc(cls, desc, devices, conf):
+ """
+ Obtain unknown devices info from libvirt.
+
+ Unknown device is a device that has an address but wasn't
+ passed during VM creation request.
+ """
+ def isKnownDevice(alias):
+ for dev in conf['devices']:
+ if dev.get('alias') == alias:
+ return True
+ return False
+
+ for x in desc.childNodes:
+ # Ignore empty nodes and devices without address
+ if (x.nodeName == '#text' or
+ not x.getElementsByTagName('address')):
+ continue
+
+ alias = cls._getDeviceAliasName(x)
+ if not isKnownDevice(alias):
+ address = cls._getDeviceAddress(x)
+ # I general case we assume that device has attribute 'type',
+ # if it hasn't getAttribute returns ''.
+ device = x.getAttribute('type')
+ newDev = {'type': x.nodeName,
+ 'alias': alias,
+ 'device': device,
+ 'address': address}
+ conf['devices'].append(newDev)
+
class GeneralDevice(VmDevice):
@@ -1219,6 +1311,52 @@
return ctrl
+ @classmethod
+ def updateFromDesc(cls, desc, devices, conf):
+ """
+ Obtain controller devices info from libvirt.
+ """
+ controllers = desc.getElementsByTagName('controller')
+ for x in controllers:
+ # Ignore controller devices without address
+ if not x.getElementsByTagName('address'):
+ continue
+ alias = cls._getDeviceAliasName(x)
+ device = x.getAttribute('type')
+ # Get model and index. Relevant for USB controllers.
+ model = x.getAttribute('model')
+ index = x.getAttribute('index')
+
+ # Get controller address
+ address = cls._getDeviceAddress(x)
+
+ # In case the controller has index and/or model, they
+ # are compared. Currently relevant for USB controllers.
+ for ctrl in devices[CONTROLLER_DEVICES]:
+ if ((ctrl.device == device) and
+ (not hasattr(ctrl, 'index') or ctrl.index == index) and
+ (not hasattr(ctrl, 'model') or ctrl.model == model)):
+ ctrl.alias = alias
+ ctrl.address = address
+ # Update vm's conf with address for known controller devices
+ # In case the controller has index and/or model, they
+ # are compared. Currently relevant for USB controllers.
+ knownDev = False
+ for dev in conf['devices']:
+ if ((dev['type'] == CONTROLLER_DEVICES) and
+ (dev['device'] == device) and
+ (not 'index' in dev or dev['index'] == index)
and
+ (not 'model' in dev or dev['model'] == model)):
+ dev['address'] = address
+ dev['alias'] = alias
+ knownDev = True
+ # Add unknown controller device to vm's conf
+ if not knownDev:
+ conf['devices'].append({'type': CONTROLLER_DEVICES,
+ 'device': device,
+ 'address': address,
+ 'alias': alias})
+
class VideoDevice(VmDevice):
@@ -1235,6 +1373,34 @@
video.appendChildWithArgs('model', type=self.device, **sourceAttrs)
return video
+ @classmethod
+ def updateFromDesc(cls, desc, devices, conf):
+ """
+ Obtain video devices info from libvirt.
+ """
+ videos = desc.getElementsByTagName('video')
+ for x in videos:
+ alias = cls._getDeviceAliasName(x)
+ # Get video card address
+ address = cls._getDeviceAddress(x)
+
+ # FIXME. We have an identification problem here.
+ # Video card device has not unique identifier, except the alias
+ # (but backend not aware to device's aliases). So, for now
+ # we can only assign the address according to devices order.
+ for vc in devices[VIDEO_DEVICES]:
+ if not hasattr(vc, 'address') or not hasattr(vc,
'alias'):
+ vc.alias = alias
+ vc.address = address
+ break
+ # Update vm's conf with address
+ for dev in conf['devices']:
+ if ((dev['type'] == VIDEO_DEVICES) and
+ (not dev.get('address') or not
dev.get('alias'))):
+ dev['address'] = address
+ dev['alias'] = alias
+ break
+
class SoundDevice(VmDevice):
@@ -1245,6 +1411,34 @@
sound = self.createXmlElem('sound', None, ['address'])
sound.setAttrs(model=self.device)
return sound
+
+ @classmethod
+ def updateFromDesc(cls, desc, devices, conf):
+ """
+ Obtain sound devices info from libvirt.
+ """
+ soundDevices = desc.getElementsByTagName('sound')
+ for x in soundDevices:
+ alias = cls._getDeviceAliasName(x)
+ # Get sound card address
+ address = cls._getDeviceAddress(x)
+
+ # FIXME. We have an identification problem here.
+ # Sound device has not unique identifier, except the alias
+ # (but backend not aware to device's aliases). So, for now
+ # we can only assign the address according to devices order.
+ for sc in devices[SOUND_DEVICES]:
+ if not hasattr(sc, 'address') or not hasattr(sc,
'alias'):
+ sc.alias = alias
+ sc.address = address
+ break
+ # Update vm's conf with address
+ for dev in conf['devices']:
+ if ((dev['type'] == SOUND_DEVICES) and
+ (not dev.get('address') or not
dev.get('alias'))):
+ dev['address'] = address
+ dev['alias'] = alias
+ break
class NetworkInterfaceDevice(VmDevice):
@@ -1337,6 +1531,73 @@
bandwidth.appendChildWithArgs('outbound', **outbound)
iface.appendChild(bandwidth)
return iface
+
+ @classmethod
+ def updateFromDesc(cls, desc, devices, conf):
+ """
+ Obtain network interface info from libvirt.
+ """
+ # TODO use xpath instead of parseString (here and elsewhere)
+ interfaces = desc.getElementsByTagName('interface')
+ for x in interfaces:
+ devType = x.getAttribute('type')
+ mac =
x.getElementsByTagName('mac')[0].getAttribute('address')
+ alias = cls._getDeviceAliasName(x)
+ if devType == 'hostdev':
+ name = alias
+ model = 'passthrough'
+ else:
+ name =
x.getElementsByTagName('target')[0].getAttribute('dev')
+ model =
x.getElementsByTagName('model')[0].getAttribute('type')
+
+ network = None
+ try:
+ if
x.getElementsByTagName('link')[0].getAttribute('state') == \
+ 'down':
+ linkActive = False
+ else:
+ linkActive = True
+ except IndexError:
+ linkActive = True
+ source = x.getElementsByTagName('source')
+ if source:
+ network = source[0].getAttribute('bridge')
+ if not network:
+ network = source[0].getAttribute('network')
+ network = network[len(netinfo.LIBVIRT_NET_PREFIX):]
+
+ # Get nic address
+ address = cls._getDeviceAddress(x)
+ for nic in devices[NIC_DEVICES]:
+ if nic.macAddr.lower() == mac.lower():
+ nic.name = name
+ nic.alias = alias
+ nic.address = address
+ nic.linkActive = linkActive
+ # Update vm's conf with address for known nic devices
+ knownDev = False
+ for dev in conf['devices']:
+ if (dev['type'] == NIC_DEVICES and
+ dev['macAddr'].lower() == mac.lower()):
+ dev['address'] = address
+ dev['alias'] = alias
+ dev['name'] = name
+ dev['linkActive'] = linkActive
+ knownDev = True
+ # Add unknown nic device to vm's conf
+ if not knownDev:
+ nicDev = {'type': NIC_DEVICES,
+ 'device': devType,
+ 'macAddr': mac,
+ 'nicModel': model,
+ 'address': address,
+ 'alias': alias,
+ 'name': name,
+ 'linkActive': linkActive}
+ if network:
+ nicDev['network'] = network
+ conf['devices'].append(nicDev)
+
class Drive(VmDevice):
@@ -1625,6 +1886,71 @@
return diskelem
+ @classmethod
+ def updateFromDesc(cls, desc, devices, conf):
+ """
+ Obtain block devices info from libvirt.
+ """
+ disks = desc.getElementsByTagName('disk')
+ # FIXME! We need to gather as much info as possible from the libvirt.
+ # In the future we can return this real data to management instead of
+ # vm's conf
+ for x in disks:
+ sources = x.getElementsByTagName('source')
+ if sources:
+ devPath = (sources[0].getAttribute('file') or
+ sources[0].getAttribute('dev'))
+ else:
+ devPath = ''
+
+ target = x.getElementsByTagName('target')
+ name = target[0].getAttribute('dev') if target else ''
+ alias = cls._getDeviceAliasName(x)
+ readonly = bool(x.getElementsByTagName('readonly'))
+ boot = x.getElementsByTagName('boot')
+ bootOrder = boot[0].getAttribute('order') if boot else ''
+
+ devType = x.getAttribute('device')
+ if devType == 'disk':
+ # raw/qcow2
+ drv =
x.getElementsByTagName('driver')[0].getAttribute('type')
+ else:
+ drv = 'raw'
+ # Get disk address
+ address = cls._getDeviceAddress(x)
+
+ for d in devices[DISK_DEVICES]:
+ if d.path == devPath:
+ d.name = name
+ d.type = devType
+ d.drv = drv
+ d.alias = alias
+ d.address = address
+ d.readonly = readonly
+ if bootOrder:
+ d.bootOrder = bootOrder
+ # Update vm's conf with address for known disk devices
+ knownDev = False
+ for dev in conf['devices']:
+ if dev['type'] == DISK_DEVICES and dev['path'] ==
devPath:
+ dev['name'] = name
+ dev['address'] = address
+ dev['alias'] = alias
+ dev['readonly'] = str(readonly)
+ if bootOrder:
+ dev['bootOrder'] = bootOrder
+ knownDev = True
+ # Add unknown disk device to vm's conf
+ if not knownDev:
+ iface = 'ide' if address['type'] == 'drive' else
'pci'
+ diskDev = {'type': DISK_DEVICES, 'device': devType,
+ 'iface': iface, 'path': devPath,
'name': name,
+ 'address': address, 'alias': alias,
+ 'readonly': str(readonly)}
+ if bootOrder:
+ diskDev['bootOrder'] = bootOrder
+ conf['devices'].append(diskDev)
+
class BalloonDevice(VmDevice):
@@ -1640,6 +1966,15 @@
m = self.createXmlElem(self.device, None, ['address'])
m.setAttrs(model=self.specParams['model'])
return m
+
+ @classmethod
+ def updateFromDesc(cls, desc, devices, conf):
+ """
+ Obtain balloon device info from libvirt.
+ """
+ balloon = desc.getElementsByTagName('memballoon')
+ cls._defaultUpdate('watchdog', WATCHDOG_DEVICES, desc, devices, conf,
+ addressRequired=False)
class WatchdogDevice(VmDevice):
@@ -1657,6 +1992,14 @@
action=self.specParams['action'])
return m
+ @classmethod
+ def updateFromDesc(cls, desc, devices, conf):
+ """
+ Obtain watchdog device info from libvirt.
+ """
+ cls._defaultUpdate('watchdog', WATCHDOG_DEVICES, desc, devices, conf,
+ addressRequired=True)
+
class SmartCardDevice(VmDevice):
def getXML(self):
@@ -1673,6 +2016,13 @@
sourceAttrs['type'] = self.specParams['type']
card.setAttrs(**sourceAttrs)
return card
+
+ @classmethod
+ def updateFromDesc(cls, desc, devices, conf):
+ """
+ Obtain smartcard device info from libvirt.
+ """
+ cls._defaultUpdate('smartcard', SMARTCARD_DEVICES, desc, devices, conf)
class RedirDevice(VmDevice):
@@ -1700,6 +2050,13 @@
m.appendChildWithArgs('target', type='virtio', port='0')
return m
+ @classmethod
+ def updateFromDesc(cls, desc, devices, conf):
+ """
+ Obtain the alias for the console device from libvirt
+ """
+ cls._defaultUpdate('console', CONSOLE_DEVICES, desc, devices, conf,
+ address=False)
class Vm(object):
"""
@@ -1713,6 +2070,18 @@
# limit threads number until the libvirt lock will be fixed
_ongoingCreations = threading.BoundedSemaphore(4)
MigrationSourceThreadClass = MigrationSourceThread
+ DeviceMapping = ((DISK_DEVICES, Drive),
+ (NIC_DEVICES, NetworkInterfaceDevice),
+ (SOUND_DEVICES, SoundDevice),
+ (VIDEO_DEVICES, VideoDevice),
+ (CONTROLLER_DEVICES, ControllerDevice),
+ (GENERAL_DEVICES, GeneralDevice),
+ (BALLOON_DEVICES, BalloonDevice),
+ (WATCHDOG_DEVICES, WatchdogDevice),
+ (CONSOLE_DEVICES, ConsoleDevice),
+ (REDIR_DEVICES, RedirDevice),
+ (SMARTCARD_DEVICES, SmartCardDevice))
+
def _makeChannelPath(self, deviceName):
return constants.P_LIBVIRT_VMCHANNELS + self.id + '.' + deviceName
@@ -2747,7 +3116,7 @@
self._qemuguestSocketFile.decode('utf-8'),
_QEMU_GA_DEVICE_NAME)
domxml.appendInput()
- domxml.appendGraphics()
+ domxml.appendGraphics()
self._appendDevices(domxml)
@@ -2785,19 +3154,12 @@
Obtain underlying vm's devices info from libvirt.
"""
devicesXml = self._getDevicesXml()
- self._getUnderlyingNetworkInterfaceInfo(devicesXml=devicesXml)
- self._getUnderlyingDriveInfo(devicesXml=devicesXml)
+ for _, cls in self.DeviceMapping:
+ cls.updateFromDesc(devicesXml, self._devices, self.conf)
self._getUnderlyingDisplayPort(xml=self._lastXMLDesc.dom())
- self._getUnderlyingSoundDeviceInfo(devicesXml=devicesXml)
- self._getUnderlyingVideoDeviceInfo(devicesXml=devicesXml)
- self._getUnderlyingControllerDeviceInfo(devicesXml=devicesXml)
- self._getUnderlyingBalloonDeviceInfo(devicesXml=devicesXml)
- self._getUnderlyingWatchdogDeviceInfo(devicesXml=devicesXml)
- self._getUnderlyingSmartcardDeviceInfo(devicesXml=devicesXml)
- self._getUnderlyingConsoleDeviceInfo(devicesXml=devicesXml)
self._updateAgentChannels(devicesXml=devicesXml)
# Obtain info of all unknown devices. Must be last!
- self._getUnderlyingUnknownDeviceInfo(devicesXml=devicesXml)
+ UnknownDevice.updateFromDesc(devicesXml, self._devices, self.conf)
def _updateAgentChannels(self, devicesXml):
"""
@@ -2914,19 +3276,7 @@
else:
devices = self.getConfDevices()
- devMap = {DISK_DEVICES: Drive,
- NIC_DEVICES: NetworkInterfaceDevice,
- SOUND_DEVICES: SoundDevice,
- VIDEO_DEVICES: VideoDevice,
- CONTROLLER_DEVICES: ControllerDevice,
- GENERAL_DEVICES: GeneralDevice,
- BALLOON_DEVICES: BalloonDevice,
- WATCHDOG_DEVICES: WatchdogDevice,
- REDIR_DEVICES: RedirDevice,
- CONSOLE_DEVICES: ConsoleDevice,
- SMARTCARD_DEVICES: SmartCardDevice}
-
- for devType, devClass in devMap.items():
+ for devType, devClass in self.DeviceMapping:
for dev in devices[devType]:
self._devices[devType].append(devClass(self.conf, self.log,
**dev))
@@ -3066,10 +3416,9 @@
with self._confLock:
self.conf['devices'].append(nicParams)
self.saveState()
- self._getUnderlyingNetworkInterfaceInfo(
- devicesXml=self._getDevicesXml())
- hooks.after_nic_hotplug(nicXml, self.conf,
- params=customProps)
+ NetworkInterfaceDevice.updateFromDesc(self._getDevicesXml(),
+ self._devices, self.conf)
+ hooks.after_nic_hotplug(nicXml, self.conf, params=customProps)
if hasattr(nic, 'portMirroring'):
mirroredNetworks = []
@@ -3327,7 +3676,8 @@
with self._confLock:
self.conf['devices'].append(diskParams)
self.saveState()
- self._getUnderlyingDriveInfo(devicesXml=self._getDevicesXml())
+ Drive.updateFromDesc(self._getDevicesXml(), self._devices,
+ self.conf)
hooks.after_disk_hotplug(driveXml, self.conf,
params=customProps)
@@ -4397,308 +4747,6 @@
self.saveState()
return {'status': doneCode}
- def _getUnderlyingDeviceAliasName(self, devXml):
- return
devXml.getElementsByTagName('alias')[0].getAttribute('name')
-
- def _getUnderlyingDeviceAddress(self, devXml):
- """
- Obtain device's address from libvirt
- """
- address = {}
- adrXml = devXml.getElementsByTagName('address')[0]
- # Parse address to create proper dictionary.
- # Libvirt device's address definition is:
- # PCI = {'type':'pci', 'domain':'0x0000',
'bus':'0x00',
- # 'slot':'0x0c', 'function':'0x0'}
- # IDE = {'type':'drive', 'controller':'0',
'bus':'0', 'unit':'0'}
- for key in adrXml.attributes.keys():
- address[key.strip()] = adrXml.getAttribute(key).strip()
-
- return address
-
- def _getUnderlyingUnknownDeviceInfo(self, devicesXml):
- """
- Obtain unknown devices info from libvirt.
-
- Unknown device is a device that has an address but wasn't
- passed during VM creation request.
- """
- def isKnownDevice(alias):
- for dev in self.conf['devices']:
- if dev.get('alias') == alias:
- return True
- return False
-
- for x in devicesXml.childNodes:
- # Ignore empty nodes and devices without address
- if (x.nodeName == '#text' or
- not x.getElementsByTagName('address')):
- continue
-
- alias = self._getUnderlyingDeviceAliasName(x)
- if not isKnownDevice(alias):
- address = self._getUnderlyingDeviceAddress(x)
- # I general case we assume that device has attribute 'type',
- # if it hasn't getAttribute returns ''.
- device = x.getAttribute('type')
- newDev = {'type': x.nodeName,
- 'alias': alias,
- 'device': device,
- 'address': address}
- self.conf['devices'].append(newDev)
-
- def _getUnderlyingControllerDeviceInfo(self, devicesXml):
- """
- Obtain controller devices info from libvirt.
- """
- ctrlsxml = devicesXml.getElementsByTagName('controller')
- for x in ctrlsxml:
- # Ignore controller devices without address
- if not x.getElementsByTagName('address'):
- continue
- alias = self._getUnderlyingDeviceAliasName(x)
- device = x.getAttribute('type')
- # Get model and index. Relevant for USB controllers.
- model = x.getAttribute('model')
- index = x.getAttribute('index')
-
- # Get controller address
- address = self._getUnderlyingDeviceAddress(x)
-
- # In case the controller has index and/or model, they
- # are compared. Currently relevant for USB controllers.
- for ctrl in self._devices[CONTROLLER_DEVICES]:
- if ((ctrl.device == device) and
- (not hasattr(ctrl, 'index') or ctrl.index == index) and
- (not hasattr(ctrl, 'model') or ctrl.model == model)):
- ctrl.alias = alias
- ctrl.address = address
- # Update vm's conf with address for known controller devices
- # In case the controller has index and/or model, they
- # are compared. Currently relevant for USB controllers.
- knownDev = False
- for dev in self.conf['devices']:
- if ((dev['type'] == CONTROLLER_DEVICES) and
- (dev['device'] == device) and
- (not 'index' in dev or dev['index'] == index)
and
- (not 'model' in dev or dev['model'] == model)):
- dev['address'] = address
- dev['alias'] = alias
- knownDev = True
- # Add unknown controller device to vm's conf
- if not knownDev:
- self.conf['devices'].append({'type': CONTROLLER_DEVICES,
- 'device': device,
- 'address': address,
- 'alias': alias})
-
- def _getUnderlyingBalloonDeviceInfo(self, devicesXml):
- """
- Obtain balloon device info from libvirt.
- """
- balloonxml = devicesXml.getElementsByTagName('memballoon')
- for x in balloonxml:
- # Ignore balloon devices without address.
- if not x.getElementsByTagName('address'):
- address = None
- else:
- address = self._getUnderlyingDeviceAddress(x)
- alias = self._getUnderlyingDeviceAliasName(x)
-
- for dev in self._devices[BALLOON_DEVICES]:
- if address and not hasattr(dev, 'address'):
- dev.address = address
- if not hasattr(dev, 'alias'):
- dev.alias = alias
-
- for dev in self.conf['devices']:
- if dev['type'] == BALLOON_DEVICES:
- if address and not dev.get('address'):
- dev['address'] = address
- if not dev.get('alias'):
- dev['alias'] = alias
-
- def _getUnderlyingConsoleDeviceInfo(self, devicesXml):
- """
- Obtain the alias for the console device from libvirt
- """
- consolexml = devicesXml.getElementsByTagName('console')
- for x in consolexml:
- # All we care about is the alias
- alias = self._getUnderlyingDeviceAliasName(x)
- for dev in self._devices[CONSOLE_DEVICES]:
- if not hasattr(dev, 'alias'):
- dev.alias = alias
-
- for dev in self.conf['devices']:
- if dev['device'] == CONSOLE_DEVICES and \
- not dev.get('alias'):
- dev['alias'] = alias
-
- def _getUnderlyingSmartcardDeviceInfo(self, devicesXml):
- """
- Obtain smartcard device info from libvirt.
- """
- smartcardxml = devicesXml.getElementsByTagName('smartcard')
- for x in smartcardxml:
- if not x.getElementsByTagName('address'):
- continue
-
- address = self._getUnderlyingDeviceAddress(x)
- alias = self._getUnderlyingDeviceAliasName(x)
-
- for dev in self._devices[SMARTCARD_DEVICES]:
- if not hasattr(dev, 'address'):
- dev.address = address
- dev.alias = alias
-
- for dev in self.conf['devices']:
- if dev['device'] == SMARTCARD_DEVICES and \
- not dev.get('address'):
- dev['address'] = address
- dev['alias'] = alias
-
- def _getUnderlyingWatchdogDeviceInfo(self, devicesXml):
- """
- Obtain watchdog device info from libvirt.
- """
- watchdogxml = devicesXml.getElementsByTagName('watchdog')
- for x in watchdogxml:
-
- # PCI watchdog has "address" different from ISA watchdog
- if x.getElementsByTagName('address'):
- address = self._getUnderlyingDeviceAddress(x)
- alias = self._getUnderlyingDeviceAliasName(x)
-
- for wd in self._devices[WATCHDOG_DEVICES]:
- if not hasattr(wd, 'address') or not hasattr(wd,
'alias'):
- wd.address = address
- wd.alias = alias
-
- for dev in self.conf['devices']:
- if ((dev['type'] == WATCHDOG_DEVICES) and
- (not dev.get('address') or not
dev.get('alias'))):
- dev['address'] = address
- dev['alias'] = alias
-
- def _getUnderlyingVideoDeviceInfo(self, devicesXml):
- """
- Obtain video devices info from libvirt.
- """
- videosxml = devicesXml.getElementsByTagName('video')
- for x in videosxml:
- alias = self._getUnderlyingDeviceAliasName(x)
- # Get video card address
- address = self._getUnderlyingDeviceAddress(x)
-
- # FIXME. We have an identification problem here.
- # Video card device has not unique identifier, except the alias
- # (but backend not aware to device's aliases). So, for now
- # we can only assign the address according to devices order.
- for vc in self._devices[VIDEO_DEVICES]:
- if not hasattr(vc, 'address') or not hasattr(vc,
'alias'):
- vc.alias = alias
- vc.address = address
- break
- # Update vm's conf with address
- for dev in self.conf['devices']:
- if ((dev['type'] == VIDEO_DEVICES) and
- (not dev.get('address') or not
dev.get('alias'))):
- dev['address'] = address
- dev['alias'] = alias
- break
-
- def _getUnderlyingSoundDeviceInfo(self, devicesXml):
- """
- Obtain sound devices info from libvirt.
- """
- soundsxml = devicesXml.getElementsByTagName('sound')
- for x in soundsxml:
- alias = self._getUnderlyingDeviceAliasName(x)
- # Get sound card address
- address = self._getUnderlyingDeviceAddress(x)
-
- # FIXME. We have an identification problem here.
- # Sound device has not unique identifier, except the alias
- # (but backend not aware to device's aliases). So, for now
- # we can only assign the address according to devices order.
- for sc in self._devices[SOUND_DEVICES]:
- if not hasattr(sc, 'address') or not hasattr(sc,
'alias'):
- sc.alias = alias
- sc.address = address
- break
- # Update vm's conf with address
- for dev in self.conf['devices']:
- if ((dev['type'] == SOUND_DEVICES) and
- (not dev.get('address') or not
dev.get('alias'))):
- dev['address'] = address
- dev['alias'] = alias
- break
-
- def _getUnderlyingDriveInfo(self, devicesXml):
- """
- Obtain block devices info from libvirt.
- """
- disksxml = devicesXml.getElementsByTagName('disk')
- # FIXME! We need to gather as much info as possible from the libvirt.
- # In the future we can return this real data to management instead of
- # vm's conf
- for x in disksxml:
- sources = x.getElementsByTagName('source')
- if sources:
- devPath = (sources[0].getAttribute('file') or
- sources[0].getAttribute('dev'))
- else:
- devPath = ''
-
- target = x.getElementsByTagName('target')
- name = target[0].getAttribute('dev') if target else ''
- alias = self._getUnderlyingDeviceAliasName(x)
- readonly = bool(x.getElementsByTagName('readonly'))
- boot = x.getElementsByTagName('boot')
- bootOrder = boot[0].getAttribute('order') if boot else ''
-
- devType = x.getAttribute('device')
- if devType == 'disk':
- # raw/qcow2
- drv =
x.getElementsByTagName('driver')[0].getAttribute('type')
- else:
- drv = 'raw'
- # Get disk address
- address = self._getUnderlyingDeviceAddress(x)
-
- for d in self._devices[DISK_DEVICES]:
- if d.path == devPath:
- d.name = name
- d.type = devType
- d.drv = drv
- d.alias = alias
- d.address = address
- d.readonly = readonly
- if bootOrder:
- d.bootOrder = bootOrder
- # Update vm's conf with address for known disk devices
- knownDev = False
- for dev in self.conf['devices']:
- if dev['type'] == DISK_DEVICES and dev['path'] ==
devPath:
- dev['name'] = name
- dev['address'] = address
- dev['alias'] = alias
- dev['readonly'] = str(readonly)
- if bootOrder:
- dev['bootOrder'] = bootOrder
- knownDev = True
- # Add unknown disk device to vm's conf
- if not knownDev:
- iface = 'ide' if address['type'] == 'drive' else
'pci'
- diskDev = {'type': DISK_DEVICES, 'device': devType,
- 'iface': iface, 'path': devPath,
'name': name,
- 'address': address, 'alias': alias,
- 'readonly': str(readonly)}
- if bootOrder:
- diskDev['bootOrder'] = bootOrder
- self.conf['devices'].append(diskDev)
-
def _getUnderlyingDisplayPort(self, xml):
"""
Obtain display port info from libvirt.
@@ -4710,71 +4758,6 @@
port = graphics.getAttribute('tlsPort')
if port:
self.conf['displaySecurePort'] = port
-
- def _getUnderlyingNetworkInterfaceInfo(self, devicesXml):
- """
- Obtain network interface info from libvirt.
- """
- # TODO use xpath instead of parseString (here and elsewhere)
- ifsxml = devicesXml.getElementsByTagName('interface')
- for x in ifsxml:
- devType = x.getAttribute('type')
- mac =
x.getElementsByTagName('mac')[0].getAttribute('address')
- alias = self._getUnderlyingDeviceAliasName(x)
- if devType == 'hostdev':
- name = alias
- model = 'passthrough'
- else:
- name =
x.getElementsByTagName('target')[0].getAttribute('dev')
- model =
x.getElementsByTagName('model')[0].getAttribute('type')
-
- network = None
- try:
- if
x.getElementsByTagName('link')[0].getAttribute('state') == \
- 'down':
- linkActive = False
- else:
- linkActive = True
- except IndexError:
- linkActive = True
- source = x.getElementsByTagName('source')
- if source:
- network = source[0].getAttribute('bridge')
- if not network:
- network = source[0].getAttribute('network')
- network = network[len(netinfo.LIBVIRT_NET_PREFIX):]
-
- # Get nic address
- address = self._getUnderlyingDeviceAddress(x)
- for nic in self._devices[NIC_DEVICES]:
- if nic.macAddr.lower() == mac.lower():
- nic.name = name
- nic.alias = alias
- nic.address = address
- nic.linkActive = linkActive
- # Update vm's conf with address for known nic devices
- knownDev = False
- for dev in self.conf['devices']:
- if (dev['type'] == NIC_DEVICES and
- dev['macAddr'].lower() == mac.lower()):
- dev['address'] = address
- dev['alias'] = alias
- dev['name'] = name
- dev['linkActive'] = linkActive
- knownDev = True
- # Add unknown nic device to vm's conf
- if not knownDev:
- nicDev = {'type': NIC_DEVICES,
- 'device': devType,
- 'macAddr': mac,
- 'nicModel': model,
- 'address': address,
- 'alias': alias,
- 'name': name,
- 'linkActive': linkActive}
- if network:
- nicDev['network'] = network
- self.conf['devices'].append(nicDev)
def _setWriteWatermarks(self):
"""
--
To view, visit
http://gerrit.ovirt.org/19732
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8f797baece3601b885777784f611b420523828f7
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Vinzenz Feenstra <vfeenstr(a)redhat.com>