From df351f8c8bb3a2c138600aebf6f87de94ad47b89 Mon Sep 17 00:00:00 2001 From: Sebastian Mitterle Date: Wed, 19 Jul 2023 03:40:18 -0400 Subject: [PATCH] nodedev_xml: extend MdevXML with attr elements Add support for attribute elements of the mediated device capability xml, e.g.: ``` ``` Signed-off-by: Sebastian Mitterle --- virttest/libvirt_xml/nodedev_xml.py | 53 ++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/virttest/libvirt_xml/nodedev_xml.py b/virttest/libvirt_xml/nodedev_xml.py index e81a71bdeff..b07973b6e92 100644 --- a/virttest/libvirt_xml/nodedev_xml.py +++ b/virttest/libvirt_xml/nodedev_xml.py @@ -152,16 +152,67 @@ class MdevXML(CAPXML): """ class for capability whose type is mdev """ - __slots__ = ('type_id', 'uuid') + __slots__ = ('type_id', 'uuid', 'attrs') def __init__(self, virsh_instance=base.virsh): accessors.XMLAttribute('type_id', self, parent_xpath='/', tag_name='type', attribute='id') accessors.XMLElementText('uuid', self, parent_xpath='/', tag_name='uuid') + accessors.XMLElementList(property_name='attrs', + libvirtxml=self, + parent_xpath='/', + marshal_from=self.marshal_from_attrs, + marshal_to=self.marshal_to_attrs, + has_subclass=True) super(MdevXML, self).__init__(virsh_instance=virsh_instance) self.xml = (' ') + @staticmethod + def marshal_from_attrs(item, index, libvirtxml): + """ + Convert an AttrXML object to attr tag and xml element. + """ + if isinstance(item, AttrXML): + return 'attr', item + elif isinstance(item, dict): + attr = AttrXML() + attr.setup_attrs(**item) + else: + raise xcepts.LibvirtXMLError("Expected a list of capability attr " + " not a %s" % item) + + @staticmethod + def marshal_to_attrs(tag, new_treefile, index, libvirtxml): + """ + Convert an attr tag xml element to an object of AttrXML. + """ + if tag != 'attr': + return None # Don't convert this item + newone = AttrXML(virsh_instance=libvirtxml.virsh) + newone.xmltreefile = new_treefile + return newone + + +class AttrXML(base.LibvirtXMLBase): + """ + Attribute elements of MdevXML + """ + __slots__ = ('attr', 'name', 'value') + + def __init__(self, virsh_instance=base.virsh): + accessors.XMLElementDict(property_name='attr', + libvirtxml=self, + parent_xpath='/', + tag_name='attr') + accessors.XMLAttribute('name', self, parent_xpath='/', + tag_name='attr', attribute='name') + accessors.XMLAttribute('value', self, parent_xpath='/', + tag_name='attr', attribute='value') + super(AttrXML, self).__init__(virsh_instance=virsh_instance) + self.xml = '' + + class StorageXML(CAPXML):