libvirt: parse alias out from device config
Libvirt assigns a device alias for each device in the domain and uses this identifier in the events related to these devices, like device detach. This patch extends the LibvirtConfigGuestInterface and the LibvirtConfigGuestDisk config object to parse the alias back from the domain config. The alias is intentionally not used during domain XML generation as it is expected that libvirt will populate and persist this field. This is part of the longer series trying to transform the existing device detach handling to use libvirt events. Change-Id: I16e7df6932bb7dff243706ee49338ba6b3782085 Related-Bug: #1882521
This commit is contained in:
parent
a634103b15
commit
96072a1ef1
|
@ -2285,6 +2285,21 @@ class LibvirtConfigGuestInterfaceTest(LibvirtConfigBaseTest):
|
|||
self.assertNotIsInstance(obj.device_addr,
|
||||
config.LibvirtConfigGuestDeviceAddressDrive)
|
||||
|
||||
def test_config_interface_alias(self):
|
||||
xml = """
|
||||
<interface type='network'>
|
||||
<mac address='52:54:00:14:6f:50'/>
|
||||
<source network='default' bridge='virbr0'/>
|
||||
<target dev='vnet0'/>
|
||||
<model type='virtio'/>
|
||||
<alias name='net0'/>
|
||||
</interface>"""
|
||||
|
||||
obj = config.LibvirtConfigGuestInterface()
|
||||
obj.parse_str(xml)
|
||||
|
||||
self.assertEqual('net0', obj.alias)
|
||||
|
||||
|
||||
class LibvirtConfigGuestFeatureTest(LibvirtConfigBaseTest):
|
||||
|
||||
|
@ -2813,6 +2828,21 @@ class LibvirtConfigGuestSnapshotTest(LibvirtConfigBaseTest):
|
|||
|
||||
self.assertTrue(obj.driver_iommu)
|
||||
|
||||
def test_config_alias_parse(self):
|
||||
xml = """
|
||||
<disk type="file" device="disk">
|
||||
<source file="/tmp/hello.qcow2"/>
|
||||
<target bus="virtio" dev="/dev/sda"/>
|
||||
<serial>7a97c4a3-6f59-41d4-bf47-191d7f97f8e9</serial>
|
||||
<alias name='virtio-disk0'/>
|
||||
</disk>"""
|
||||
xmldoc = etree.fromstring(xml)
|
||||
|
||||
obj = config.LibvirtConfigGuestDisk()
|
||||
obj.parse_dom(xmldoc)
|
||||
|
||||
self.assertEqual('virtio-disk0', obj.alias)
|
||||
|
||||
|
||||
class LibvirtConfigNodeDeviceTest(LibvirtConfigBaseTest):
|
||||
|
||||
|
|
|
@ -1037,6 +1037,7 @@ class LibvirtConfigGuestDisk(LibvirtConfigGuestDevice):
|
|||
self.boot_order = None
|
||||
self.mirror = None
|
||||
self.encryption = None
|
||||
self.alias = None
|
||||
|
||||
def _format_iotune(self, dev):
|
||||
iotune = etree.Element("iotune")
|
||||
|
@ -1246,6 +1247,8 @@ class LibvirtConfigGuestDisk(LibvirtConfigGuestDevice):
|
|||
e = LibvirtConfigGuestDiskEncryption()
|
||||
e.parse_dom(c)
|
||||
self.encryption = e
|
||||
elif c.tag == 'alias':
|
||||
self.alias = c.get('name')
|
||||
|
||||
|
||||
class LibvirtConfigGuestDiskBackingStore(LibvirtConfigObject):
|
||||
|
@ -1688,6 +1691,7 @@ class LibvirtConfigGuestInterface(LibvirtConfigGuestDevice):
|
|||
self.vlan = None
|
||||
self.device_addr = None
|
||||
self.mtu = None
|
||||
self.alias = None
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, LibvirtConfigGuestInterface):
|
||||
|
@ -1914,6 +1918,8 @@ class LibvirtConfigGuestInterface(LibvirtConfigGuestDevice):
|
|||
self.device_addr = obj
|
||||
elif c.tag == 'mtu':
|
||||
self.mtu = int(c.get('size'))
|
||||
elif c.tag == 'alias':
|
||||
self.alias = c.get('name')
|
||||
|
||||
def add_filter_param(self, key, value):
|
||||
self.filterparams.append({'key': key, 'value': value})
|
||||
|
|
Loading…
Reference in New Issue