Merge "libvirt: update LibvirtConfigGuestDeviceAddress to provide XML"
This commit is contained in:
@@ -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'>
|
||||
|
@@ -1158,6 +1158,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')
|
||||
@@ -1180,6 +1185,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')
|
||||
|
Reference in New Issue
Block a user