Skip to content

Commit

Permalink
Add virt.network_get_xml function
Browse files Browse the repository at this point in the history
Users may want to see the full XML definition of a network.
  • Loading branch information
cbosdo committed Jan 7, 2020
1 parent ed9dd37 commit 03d912c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
24 changes: 24 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
10 changes: 10 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

0 comments on commit 03d912c

Please sign in to comment.