Add target path and type to virt.pool_info result

At times we need to know where the storage pool is pointing to and of
what type it is. virt.pool_info is a nice place for this.
This commit is contained in:
Cédric Bosdonnat 2018-06-21 16:35:23 +02:00
parent ac6868a532
commit f68d90ef4f
No known key found for this signature in database
GPG Key ID: 743CCED3EDD1578D
2 changed files with 26 additions and 2 deletions

View File

@ -4258,6 +4258,9 @@ def pool_info(name, **kwargs):
infos = pool.info()
states = ['inactive', 'building', 'running', 'degraded', 'inaccessible']
state = states[infos[0]] if infos[0] < len(states) else 'unknown'
desc = minidom.parseString(pool.XMLDesc())
pool_node = _get_xml_first_element_by_tag_name(desc, 'pool')
path_node = _get_xml_first_element_by_tag_name(desc, 'path')
result = {
'uuid': pool.UUIDString(),
'state': state,
@ -4265,7 +4268,9 @@ def pool_info(name, **kwargs):
'allocation': infos[2],
'free': infos[3],
'autostart': pool.autostart(),
'persistent': pool.isPersistent()
'persistent': pool.isPersistent(),
'target_path': _get_xml_element_text(path_node) if path_node else None,
'type': pool_node.getAttribute('type')
}
except libvirt.libvirtError as err:
log.debug('Silenced libvirt error: %s', str(err))

View File

@ -1573,6 +1573,23 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
pool_mock.info.return_value = [0, 1234, 5678, 123]
pool_mock.autostart.return_value = True
pool_mock.isPersistent.return_value = True
pool_mock.XMLDesc.return_value = '''<pool type='dir'>
<name>default</name>
<uuid>d92682d0-33cf-4e10-9837-a216c463e158</uuid>
<capacity unit='bytes'>854374301696</capacity>
<allocation unit='bytes'>596275986432</allocation>
<available unit='bytes'>258098315264</available>
<source>
</source>
<target>
<path>/srv/vms</path>
<permissions>
<mode>0755</mode>
<owner>0</owner>
<group>0</group>
</permissions>
</target>
</pool>'''
self.mock_conn.storagePoolLookupByName.return_value = pool_mock
# pylint: enable=no-member
@ -1584,7 +1601,9 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
'allocation': 5678,
'free': 123,
'autostart': True,
'persistent': True}, pool)
'persistent': True,
'type': 'dir',
'target_path': '/srv/vms'}, pool)
def test_pool_info_notfound(self):
'''