diff --git a/virttest/libvirt_xml/devices/disk.py b/virttest/libvirt_xml/devices/disk.py index 98b0112f8c..39b44b482f 100644 --- a/virttest/libvirt_xml/devices/disk.py +++ b/virttest/libvirt_xml/devices/disk.py @@ -103,6 +103,7 @@ class Disk(base.TypedDeviceBase): "auth", "reservations", "backingstore", + "datastore", "driver_metadatacache", "driver_iothreads", "sharebacking", @@ -234,6 +235,14 @@ def __init__(self, type_name="file", virsh_instance=base.base.virsh): subclass=self.BackingStore, subclass_dargs={"virsh_instance": virsh_instance}, ) + accessors.XMLElementNest( + "datastore", + self, + parent_xpath="/", + tag_name="dataStore", + subclass=Disk.dataStore, + subclass_dargs={"virsh_instance": virsh_instance}, + ) super(Disk, self).__init__( device_tag="disk", type_name=type_name, virsh_instance=virsh_instance ) @@ -348,6 +357,15 @@ def _get_next_backingstore(elem): return backingstore_list + def new_datastore(self, **dargs): + """ + Return a new disk datastore instance and set properties from dargs + """ + new_one = self.dataStore(virsh_instance=self.virsh) + for key, value in list(dargs.items()): + setattr(new_one, key, value) + return new_one + # For convenience Address = librarian.get("address") @@ -374,6 +392,7 @@ class DiskSource(base.base.LibvirtXMLBase): "config_file", "snapshot_name", "address", + "dataStore", ) def __init__(self, virsh_instance=base.base.virsh): @@ -442,6 +461,14 @@ def __init__(self, virsh_instance=base.base.virsh): accessors.XMLElementDict( "address", self, parent_xpath="/", tag_name="address" ) + accessors.XMLElementNest( + "dataStore", + self, + parent_xpath="/", + tag_name="dataStore", + subclass=Disk.dataStore , + subclass_dargs={"virsh_instance": virsh_instance}, + ) super(self.__class__, self).__init__(virsh_instance=virsh_instance) self.xml = "" @@ -885,9 +912,11 @@ class Source(base.base.LibvirtXMLBase): dict, nested xml of backingStore/source tag file: string, attribute of backingStore/source tag + datastore: + dict, nexted xml of backingStore/source/dataStore tag """ - __slots__ = ("attrs", "dev", "protocol", "name", "host", "file", "auth") + __slots__ = ("attrs", "protocol", "name", "host", "auth", "datastore") def __init__(self, virsh_instance=base.base.virsh): accessors.XMLElementDict( @@ -909,9 +938,6 @@ def __init__(self, virsh_instance=base.base.virsh): accessors.XMLElementDict( "host", self, parent_xpath="/", tag_name="host" ) - accessors.XMLAttribute( - "file", self, parent_xpath="/", tag_name="source", attribute="file" - ) accessors.XMLElementNest( "auth", self, @@ -920,6 +946,14 @@ def __init__(self, virsh_instance=base.base.virsh): subclass=Disk.Auth, subclass_dargs={"virsh_instance": virsh_instance}, ) + accessors.XMLElementNest( + "datastore", + self, + parent_xpath="/", + tag_name="dataStore", + subclass=Disk.dataStore, + subclass_dargs={"virsh_instance": virsh_instance}, + ) super(self.__class__, self).__init__(virsh_instance=virsh_instance) self.xml = "" @@ -952,3 +986,106 @@ def __init__(self, virsh_instance=base.base.virsh): ) super(self.__class__, self).__init__(virsh_instance=virsh_instance) self.xml = "" + + class dataStore(base.base.LibvirtXMLBase): + + """ + DataStore device XML class + + type: + string, attribute of dataStore tag + index: + string, attribute of dataStore tag + format: + dict, key-attribute of dataStore tag + source: + nested xml of dataStore tag + """ + + __slots__ = ("type", "index", "format", "source") + + def __init__(self, virsh_instance=base.base.virsh): + accessors.XMLAttribute( + "type", + self, + parent_xpath="/", + tag_name="dataStore", + attribute="type", + ) + accessors.XMLAttribute( + "index", + self, + parent_xpath="/", + tag_name="dataStore", + attribute="index", + ) + accessors.XMLElementDict( + "format", self, parent_xpath="/", tag_name="format" + ) + accessors.XMLElementNest( + "source", + self, + parent_xpath="/", + tag_name="source", + subclass=self.Source, + subclass_dargs={"virsh_instance": virsh_instance}, + ) + super(self.__class__, self).__init__(virsh_instance=virsh_instance) + self.xml = "" + + def new_source(self, **dargs): + """ + Create new source for dataStore + + """ + new_one = self.Source(virsh_instance=self.virsh) + for key, value in list(dargs.items()): + setattr(new_one, key, value) + return new_one + + class Source(base.base.LibvirtXMLBase): + """ + Source of datastore xml class + + dev: + string, attribute of dataStore/source tag + protocal: + string, attribute of dataStore/source tag + name: + string, attribute of dataStore/source tag + host: + dict, nested xml of dataStore/source tag + file: + string, attribute of dataStore/source tag + """ + + __slots__ = ("attrs", "protocol", "name", "host", "auth") + + def __init__(self, virsh_instance=base.base.virsh): + accessors.XMLElementDict( + "attrs", self, parent_xpath="/", tag_name="source" + ) + accessors.XMLAttribute( + "protocol", + self, + parent_xpath="/", + tag_name="source", + attribute="protocol", + ) + accessors.XMLAttribute( + "name", self, parent_xpath="/", tag_name="source", attribute="name" + ) + accessors.XMLElementDict( + "host", self, parent_xpath="/", tag_name="host" + ) + accessors.XMLElementNest( + "auth", + self, + parent_xpath="/", + tag_name="auth", + subclass=Disk.Auth, + subclass_dargs={"virsh_instance": virsh_instance}, + ) + + super(self.__class__, self).__init__(virsh_instance=virsh_instance) + self.xml = ""