libvirt: update LibvirtConfigGuestDeviceAddress to provide XML
This commit is adding a method format_dom() to the config object
LibvirtConfigGuestDeviceAddress. That in the aim to provide full
description of the controller used by the device.
Closes-Bug: #1686116
Change-Id: I9620feffa74b8f7bc932eed03e3a60f46533681d
(cherry picked from commit 724ca8227a
)
This commit is contained in:
parent
720611893b
commit
e1092323e2
|
@ -1027,6 +1027,18 @@ class LibvirtConfigGuestDiskTest(LibvirtConfigBaseTest):
|
|||
obj.device_addr.unit))
|
||||
self.assertIsNone(obj.device_addr.format_address())
|
||||
|
||||
def test_config_disk_device_address_drive(self):
|
||||
obj = config.LibvirtConfigGuestDeviceAddressDrive()
|
||||
obj.controller = 1
|
||||
obj.bus = 2
|
||||
obj.target = 3
|
||||
obj.unit = 4
|
||||
|
||||
xml = """
|
||||
<address type="drive" controller="1" bus="2" target="3" unit="4"/>
|
||||
"""
|
||||
self.assertXmlEqual(xml, obj.to_xml())
|
||||
|
||||
def test_config_disk_device_address_type_virtio_mmio(self):
|
||||
xml = """
|
||||
<disk type='file' device='disk'>
|
||||
|
|
|
@ -1138,6 +1138,11 @@ class LibvirtConfigGuestDeviceAddress(LibvirtConfigObject):
|
|||
root_name='address', **kwargs)
|
||||
self.type = type
|
||||
|
||||
def format_dom(self):
|
||||
xml = super(LibvirtConfigGuestDeviceAddress, self).format_dom()
|
||||
xml.set("type", self.type)
|
||||
return xml
|
||||
|
||||
@staticmethod
|
||||
def parse_dom(xmldoc):
|
||||
addr_type = xmldoc.get('type')
|
||||
|
@ -1160,6 +1165,20 @@ class LibvirtConfigGuestDeviceAddressDrive(LibvirtConfigGuestDeviceAddress):
|
|||
self.target = None
|
||||
self.unit = None
|
||||
|
||||
def format_dom(self):
|
||||
xml = super(LibvirtConfigGuestDeviceAddressDrive, self).format_dom()
|
||||
|
||||
if self.controller is not None:
|
||||
xml.set("controller", str(self.controller))
|
||||
if self.bus is not None:
|
||||
xml.set("bus", str(self.bus))
|
||||
if self.target is not None:
|
||||
xml.set("target", str(self.target))
|
||||
if self.unit is not None:
|
||||
xml.set("unit", str(self.unit))
|
||||
|
||||
return xml
|
||||
|
||||
def parse_dom(self, xmldoc):
|
||||
self.controller = xmldoc.get('controller')
|
||||
self.bus = xmldoc.get('bus')
|
||||
|
|
Loading…
Reference in New Issue