Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add virt.(pool|network)_get_xml functions #55762

Merged
merged 2 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions salt/modules/virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4584,6 +4584,30 @@ def _net_get_leases(net):
return result


def network_get_xml(name, **kwargs):
'''
Return the XML definition of a virtual network

:param name: libvirt network name
:param connection: libvirt connection URI, overriding defaults
:param username: username to connect with, overriding defaults
:param password: password to connect with, overriding defaults

.. versionadded:: Neon

CLI Example:

.. code-block:: bash

salt '*' virt.network_get_xml default
'''
conn = __get_conn(**kwargs)
try:
return conn.networkLookupByName(name).XMLDesc()
finally:
conn.close()


def network_start(name, **kwargs):
'''
Start a defined virtual network.
Expand Down Expand Up @@ -5328,6 +5352,30 @@ def _pool_extract_infos(pool):
return result


def pool_get_xml(name, **kwargs):
'''
Return the XML definition of a virtual storage pool

:param name: libvirt storage pool name
:param connection: libvirt connection URI, overriding defaults
:param username: username to connect with, overriding defaults
:param password: password to connect with, overriding defaults

.. versionadded:: Neon

CLI Example:

.. code-block:: bash

salt '*' virt.pool_get_xml default
'''
conn = __get_conn(**kwargs)
try:
return conn.storagePoolLookupByName(name).XMLDesc()
finally:
conn.close()


def pool_start(name, **kwargs):
'''
Start a defined libvirt storage pool.
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/modules/test_virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2348,6 +2348,16 @@ def test_network_info_notfound(self):
net = virt.network_info('foo')
self.assertEqual({}, net)

def test_network_get_xml(self):
'''
Test virt.network_get_xml
'''
network_mock = MagicMock()
network_mock.XMLDesc.return_value = '<net>Raw XML</net>'
self.mock_conn.networkLookupByName.return_value = network_mock

self.assertEqual('<net>Raw XML</net>', virt.network_get_xml('default'))

def test_pool(self):
'''
Test virt._gen_pool_xml()
Expand Down Expand Up @@ -2750,6 +2760,16 @@ def test_pool_info_all(self):
}
}, pool)

def test_pool_get_xml(self):
'''
Test virt.pool_get_xml
'''
pool_mock = MagicMock()
pool_mock.XMLDesc.return_value = '<pool>Raw XML</pool>'
self.mock_conn.storagePoolLookupByName.return_value = pool_mock

self.assertEqual('<pool>Raw XML</pool>', virt.pool_get_xml('default'))

def test_pool_list_volumes(self):
'''
Test virt.pool_list_volumes
Expand Down