virt.volume_infos: output backing store as well

Since it could be useful to know whether a volume has a backing store,
output the path and format of the backing store if any is defined.
This commit is contained in:
Cédric Bosdonnat 2020-04-10 15:30:09 +02:00 committed by Daniel Wozniak
parent 142ca61644
commit 9b2d180e46
2 changed files with 42 additions and 2 deletions

View file

@ -6233,6 +6233,18 @@ def volume_infos(pool=None, volume=None, **kwargs):
types = ["file", "block", "dir", "network", "netdir", "ploop"]
infos = vol.info()
vol_xml = ElementTree.fromstring(vol.XMLDesc())
backing_store_path = vol_xml.find("./backingStore/path")
backing_store_format = vol_xml.find("./backingStore/format")
backing_store = None
if backing_store_path is not None:
backing_store = {
"path": backing_store_path.text,
"format": backing_store_format.get("type")
if backing_store_format is not None
else None,
}
# If we have a path, check its use.
used_by = []
if vol.path():
@ -6254,6 +6266,7 @@ def volume_infos(pool=None, volume=None, **kwargs):
"capacity": infos[1],
"allocation": infos[2],
"used_by": used_by,
"backing_store": backing_store,
}
pools = [

View file

@ -4013,7 +4013,7 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
backing_store = (
"""
<backingStore>
<format>qcow2</format>
<format type="qcow2"/>
<path>{0}</path>
</backingStore>
""".format(
@ -4026,7 +4026,7 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
<volume type='file'>
<name>{0}</name>
<target>
<format>qcow2</format>
<format type="qcow2"/>
<path>/path/to/{0}.qcow2</path>
</target>
{1}
@ -4082,6 +4082,7 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
"capacity": 12345,
"allocation": 1234,
"used_by": [],
"backing_store": None,
},
"vol2": {
"type": "file",
@ -4090,6 +4091,10 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
"capacity": 12345,
"allocation": 1234,
"used_by": ["vm2"],
"backing_store": {
"path": "/path/to/vol0.qcow2",
"format": "qcow2",
},
},
}
},
@ -4106,6 +4111,10 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
"capacity": 12345,
"allocation": 1234,
"used_by": ["vm2"],
"backing_store": {
"path": "/path/to/vol0.qcow2",
"format": "qcow2",
},
}
}
},
@ -4136,6 +4145,7 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
"capacity": 12345,
"allocation": 1234,
"used_by": [],
"backing_store": None,
},
"vol2": {
"type": "file",
@ -4144,6 +4154,10 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
"capacity": 12345,
"allocation": 1234,
"used_by": [],
"backing_store": {
"path": "/path/to/vol0.qcow2",
"format": "qcow2",
},
},
}
},
@ -4160,6 +4174,10 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
"capacity": 12345,
"allocation": 1234,
"used_by": [],
"backing_store": {
"path": "/path/to/vol0.qcow2",
"format": "qcow2",
},
}
}
},
@ -4191,6 +4209,7 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
"capacity": 12345,
"allocation": 1234,
"used_by": [],
"backing_store": None,
},
"vol2": {
"type": "file",
@ -4199,6 +4218,10 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
"capacity": 12345,
"allocation": 1234,
"used_by": [],
"backing_store": {
"path": "/path/to/vol0.qcow2",
"format": "qcow2",
},
},
}
},
@ -4215,6 +4238,10 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
"capacity": 12345,
"allocation": 1234,
"used_by": [],
"backing_store": {
"path": "/path/to/vol0.qcow2",
"format": "qcow2",
},
}
}
},