Skip to content

Commit

Permalink
nodedev_xml: extend MdevXML with attr elements
Browse files Browse the repository at this point in the history
Add support for attribute elements of the mediated device
capability xml, e.g.:

```
 <attr name='assign_adapter' value='3'/>
 <attr name='assign_domain' value='43'/>
```

Signed-off-by: Sebastian Mitterle <[email protected]>
  • Loading branch information
smitterl committed Aug 3, 2023
1 parent e20d6f4 commit 2daf499
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion virttest/libvirt_xml/nodedev_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,42 @@ 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=False)
super(MdevXML, self).__init__(virsh_instance=virsh_instance)
self.xml = (' <capability type=\'mdev\'></capability>')

@staticmethod
def marshal_from_attrs(item, index, libvirtxml):
"""Convert dictionary to an xml object"""
del index
del libvirtxml
if not isinstance(item, dict):
raise xcepts.LibvirtXMLError("Expected a dictionary of host"
" attributes, not a %s"
% str(item))
return ('attr', dict(item))

@staticmethod
def marshal_to_attrs(tag, attr_dict, index, libvirtxml):
"""Convert xml object to a dictionary"
del index
del libvirtxml
if tag != 'attr':
return None
return dict(attr_dict)
class StorageXML(CAPXML):
Expand Down

0 comments on commit 2daf499

Please sign in to comment.