mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
virt.define_vol_xml_str variant using an existing libvirt connection
In order to avoid connection multiple times when reusing this function in the virt module, create _define_vol_xml_str not caring about the connection opening and closing.
This commit is contained in:
parent
2fd1556819
commit
a038269738
1 changed files with 20 additions and 7 deletions
|
@ -3174,6 +3174,19 @@ def define_xml_path(path, **kwargs):
|
|||
return False
|
||||
|
||||
|
||||
def _define_vol_xml_str(conn, xml, pool=None): # pylint: disable=redefined-outer-name
|
||||
"""
|
||||
Same function than define_vml_xml_str but using an already opened libvirt connection
|
||||
"""
|
||||
default_pool = "default" if conn.getType() != "ESX" else "0"
|
||||
poolname = (
|
||||
pool if pool else __salt__["config.get"]("virt:storagepool", default_pool)
|
||||
)
|
||||
pool = conn.storagePoolLookupByName(six.text_type(poolname))
|
||||
ret = pool.createXML(xml, 0) is not None
|
||||
return ret
|
||||
|
||||
|
||||
def define_vol_xml_str(
|
||||
xml, pool=None, **kwargs
|
||||
): # pylint: disable=redefined-outer-name
|
||||
|
@ -3211,13 +3224,13 @@ def define_vol_xml_str(
|
|||
storagepool: mine
|
||||
"""
|
||||
conn = __get_conn(**kwargs)
|
||||
default_pool = "default" if conn.getType() != "ESX" else "0"
|
||||
poolname = (
|
||||
pool if pool else __salt__["config.get"]("virt:storagepool", default_pool)
|
||||
)
|
||||
pool = conn.storagePoolLookupByName(six.text_type(poolname))
|
||||
ret = pool.createXML(xml, 0) is not None
|
||||
conn.close()
|
||||
ret = False
|
||||
try:
|
||||
ret = _define_vol_xml_str(conn, xml, pool=pool)
|
||||
except libvirtError as err:
|
||||
raise CommandExecutionError(err.get_error_message())
|
||||
finally:
|
||||
conn.close()
|
||||
return ret
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue