Change in vdsm[master]: virt: Move Vm._getUnderlyingDeviceAddress() to vmxml.py
mzamazal at redhat.com
mzamazal at redhat.com
Fri Feb 26 17:08:46 UTC 2016
Milan Zamazal has uploaded a new change for review.
Change subject: virt: Move Vm._getUnderlyingDeviceAddress() to vmxml.py
......................................................................
virt: Move Vm._getUnderlyingDeviceAddress() to vmxml.py
This is a preparation step for the next round of moving device handling
code out of Vm class. We want to move Vm._getUnderlying* methods out of
Vm, but not all at once. Most of the methods use
_getUnderlyingDeviceAddress() so we need to have this functionality
available in both Vm and the moved code and this is the reason for
having this preparation step.
Change-Id: Ib9868ca1df6650b1262e6f30d639a08b1f38304d
Signed-off-by: Milan Zamazal <mzamazal at redhat.com>
---
M vdsm/virt/vm.py
M vdsm/virt/vmxml.py
2 files changed, 33 insertions(+), 33 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/15/53615/5
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index c23f710..5833147 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -4011,22 +4011,6 @@
self.log.exception("Operation failed")
return response.error(key, msg)
- def _getUnderlyingDeviceAddress(self, devXml, index=0):
- """
- Obtain device's address from libvirt
- """
- address = {}
- adrXml = devXml.getElementsByTagName('address')[index]
- # 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):
"""
Obtain unknown devices info from libvirt.
@@ -4048,7 +4032,7 @@
alias = x.getElementsByTagName('alias')[0].getAttribute('name')
if not isKnownDevice(alias):
- address = self._getUnderlyingDeviceAddress(x)
+ address = vmxml.device_address(x)
# I general case we assume that device has attribute 'type',
# if it hasn't getAttribute returns ''.
device = x.getAttribute('type')
@@ -4073,7 +4057,7 @@
index = x.getAttribute('index')
# Get controller address
- address = self._getUnderlyingDeviceAddress(x)
+ address = vmxml.device_address(x)
# In case the controller has index and/or model, they
# are compared. Currently relevant for USB controllers.
@@ -4112,7 +4096,7 @@
if not x.getElementsByTagName('address'):
address = None
else:
- address = self._getUnderlyingDeviceAddress(x)
+ address = vmxml.device_address(x)
alias = x.getElementsByTagName('alias')[0].getAttribute('name')
for dev in self._devices[hwclass.BALLOON]:
@@ -4152,7 +4136,7 @@
if not x.getElementsByTagName('address'):
continue
- address = self._getUnderlyingDeviceAddress(x)
+ address = vmxml.device_address(x)
alias = x.getElementsByTagName('alias')[0].getAttribute('name')
for dev in self._devices[hwclass.SMARTCARD]:
@@ -4171,7 +4155,7 @@
Obtain rng device info from libvirt.
"""
for rng in self._domain.get_device_elements('rng'):
- address = self._getUnderlyingDeviceAddress(rng)
+ address = vmxml.device_address(rng)
alias = rng.getElementsByTagName('alias')[0].getAttribute('name')
source = rng.getElementsByTagName('backend')[0].firstChild.\
nodeValue
@@ -4193,7 +4177,7 @@
def _getUnderlyingHostDeviceUSBInfo(self, x):
alias = x.getElementsByTagName('alias')[0].getAttribute('name')
- address = self._getUnderlyingDeviceAddress(x)
+ address = vmxml.device_address(x)
# The routine is quite unusual because we cannot directly reconstruct
# the unique name. Therefore, we first look up correspondoing device
@@ -4222,16 +4206,16 @@
self._getUnderlyingHostDeviceUSBInfo(x)
continue
alias = x.getElementsByTagName('alias')[0].getAttribute('name')
- address = self._getUnderlyingDeviceAddress(x)
+ address = vmxml.device_address(x)
source = x.getElementsByTagName('source')[0]
device = hostdev.pci_address_to_name(
- **self._getUnderlyingDeviceAddress(source))
+ **vmxml.device_address(source))
# We can assume the device name to be correct since we're
# inspecting source element. For the address, we may look at
# both addresses and determine the correct one.
if (hostdev.pci_address_to_name(**address) == device):
- address = self._getUnderlyingDeviceAddress(x, 1)
+ address = vmxml.device_address(x, 1)
known_device = False
for dev in self.conf['devices']:
@@ -4247,7 +4231,7 @@
if not known_device:
device = hostdev.pci_address_to_name(
- **self._getUnderlyingDeviceAddress(source))
+ **vmxml.device_address(source))
hostdevice = {'type': hwclass.HOSTDEV,
'device': device,
@@ -4263,7 +4247,7 @@
# PCI watchdog has "address" different from ISA watchdog
if x.getElementsByTagName('address'):
- address = self._getUnderlyingDeviceAddress(x)
+ address = vmxml.device_address(x)
alias = x.getElementsByTagName('alias')[0].getAttribute('name')
for wd in self._devices[hwclass.WATCHDOG]:
@@ -4284,7 +4268,7 @@
for x in self._domain.get_device_elements('video'):
alias = x.getElementsByTagName('alias')[0].getAttribute('name')
# Get video card address
- address = self._getUnderlyingDeviceAddress(x)
+ address = vmxml.device_address(x)
# FIXME. We have an identification problem here.
# Video card device has not unique identifier, except the alias
@@ -4310,7 +4294,7 @@
for x in self._domain.get_device_elements('sound'):
alias = x.getElementsByTagName('alias')[0].getAttribute('name')
# Get sound card address
- address = self._getUnderlyingDeviceAddress(x)
+ address = vmxml.device_address(x)
# FIXME. We have an identification problem here.
# Sound device has not unique identifier, except the alias
@@ -4362,7 +4346,7 @@
else:
drv = 'raw'
# Get disk address
- address = self._getUnderlyingDeviceAddress(x)
+ address = vmxml.device_address(x)
# Keep data as dict for easier debugging
deviceDict = {'path': devPath, 'name': name,
@@ -4505,8 +4489,7 @@
# Get nic address
address = {}
- # TODO: fix _getUnderlyingDeviceAddress and its users to have this
- # TODO: code.
+ # TODO: fix vmxml.device_address and its users to have this code.
for child in x.childNodes:
if (child.nodeType != Node.TEXT_NODE and
child.tagName == 'address'):
@@ -4555,7 +4538,7 @@
for x in self._domain.get_device_elements('memory'):
alias = x.getElementsByTagName('alias')[0].getAttribute('name')
# Get device address
- address = self._getUnderlyingDeviceAddress(x)
+ address = vmxml.device_address(x)
for mem in self._devices[hwclass.MEMORY]:
if not hasattr(mem, 'address') or not hasattr(mem, 'alias'):
diff --git a/vdsm/virt/vmxml.py b/vdsm/virt/vmxml.py
index ff1accb..8e65d3a 100644
--- a/vdsm/virt/vmxml.py
+++ b/vdsm/virt/vmxml.py
@@ -63,6 +63,23 @@
yield deviceXML, alias
+def device_address(devXml, index=0):
+ """
+ Obtain device's address from libvirt
+ """
+ address = {}
+ adrXml = devXml.getElementsByTagName('address')[index]
+ # 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
+
+
class Device(object):
# since we're inheriting all VM devices from this class, __slots__ must
# be initialized here in order to avoid __dict__ creation
--
To view, visit https://gerrit.ovirt.org/53615
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib9868ca1df6650b1262e6f30d639a08b1f38304d
Gerrit-PatchSet: 5
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Milan Zamazal <mzamazal at redhat.com>
Gerrit-Reviewer: Francesco Romani <fromani at redhat.com>
Gerrit-Reviewer: Milan Zamazal <mzamazal at redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation at ovirt.org>
More information about the vdsm-patches
mailing list