Source code for virttest.libvirt_xml.devices.rng

"""
random number generator device support class(es)

http://libvirt.org/formatdomain.html#elementsRng
"""

from virttest.libvirt_xml import accessors, xcepts
from virttest.libvirt_xml.devices import base


[docs]class Rng(base.UntypedDeviceBase): __slots__ = ('rng_model', 'rate', 'backend') def __init__(self, virsh_instance=base.base.virsh): accessors.XMLAttribute('rng_model', self, parent_xpath='/', tag_name='rng', attribute='model') accessors.XMLElementDict('rate', self, parent_xpath='/', tag_name='rate') accessors.XMLElementNest('backend', self, parent_xpath='/', tag_name='backend', subclass=self.Backend, subclass_dargs={ 'virsh_instance': virsh_instance}) super(Rng, self).__init__(device_tag='rng', virsh_instance=virsh_instance) self.xml = '<rng/>'
[docs] class Backend(base.base.LibvirtXMLBase): """ Rng backend xml class. Properties: model: string. backend model type: string. backend type """ __slots__ = ('backend_model', 'backend_type', 'backend_dev', 'source', 'backend_protocol') def __init__(self, virsh_instance=base.base.virsh): accessors.XMLAttribute(property_name="backend_model", libvirtxml=self, forbidden=None, parent_xpath='/', tag_name='backend', attribute='model') accessors.XMLAttribute(property_name="backend_type", libvirtxml=self, forbidden=None, parent_xpath='/', tag_name='backend', attribute='type') accessors.XMLElementText('backend_dev', self, parent_xpath='/', tag_name='backend') accessors.XMLElementList(property_name='source', libvirtxml=self, parent_xpath='/', marshal_from=self.marshal_from_source, marshal_to=self.marshal_to_source) accessors.XMLAttribute(property_name="backend_protocol", libvirtxml=self, forbidden=None, parent_xpath='/', tag_name='protocol', attribute='type') super(self.__class__, self).__init__(virsh_instance=virsh_instance) self.xml = '<backend/>' @staticmethod
[docs] def marshal_from_source(item, index, libvirtxml): """Convert a dictionary into a tag + attributes""" del index # not used del libvirtxml # not used if not isinstance(item, dict): raise xcepts.LibvirtXMLError("Expected a dictionary of host " "attributes, not a %s" % str(item)) return ('source', dict(item)) # return copy of dict, not reference
@staticmethod
[docs] def marshal_to_source(tag, attr_dict, index, libvirtxml): """Convert a tag + attributes into a dictionary""" del index # not used del libvirtxml # not used if tag != 'source': return None # skip this one return dict(attr_dict) # return copy of dict, not reference