Skip to content

Commit

Permalink
Disk: add new dataStore element to disk.py
Browse files Browse the repository at this point in the history
Signed-off-by: Meina Li <[email protected]>
  • Loading branch information
meinaLi committed Jan 13, 2025
1 parent a9b09f4 commit 8cb2f99
Showing 1 changed file with 141 additions and 4 deletions.
145 changes: 141 additions & 4 deletions virttest/libvirt_xml/devices/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class Disk(base.TypedDeviceBase):
"auth",
"reservations",
"backingstore",
"datastore",
"driver_metadatacache",
"driver_iothreads",
"sharebacking",
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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")

Expand All @@ -374,6 +392,7 @@ class DiskSource(base.base.LibvirtXMLBase):
"config_file",
"snapshot_name",
"address",
"dataStore",
)

def __init__(self, virsh_instance=base.base.virsh):
Expand Down Expand Up @@ -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 = "<source/>"

Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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 = "<source/>"
Expand Down Expand Up @@ -952,3 +986,106 @@ def __init__(self, virsh_instance=base.base.virsh):
)
super(self.__class__, self).__init__(virsh_instance=virsh_instance)
self.xml = "<metadata_cache/>"

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 = "<dataStore/>"

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 = "<source/>"

0 comments on commit 8cb2f99

Please sign in to comment.