Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 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
81 changes: 81 additions & 0 deletions salt/modules/virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,9 @@ def _gen_xml(
consoles=None,
stop_on_reboot=False,
host_devices=None,
stop_on_crash=False,
stop_on_poweroff=False,
stop_on_lockfailure=False,
**kwargs
):
"""
Expand All @@ -958,6 +961,9 @@ def _gen_xml(
"hypervisor_features": hypervisor_features or {},
"clock": clock or {},
"on_reboot": "destroy" if stop_on_reboot else "restart",
"on_crash": "destroy" if stop_on_crash else "restart",
"on_poweroff": "destroy" if stop_on_poweroff else "restart",
"on_lockfailure": "destroy" if stop_on_lockfailure else "restart",
}

context["to_kib"] = lambda v: int(_handle_unit(v) / 1024)
Expand Down Expand Up @@ -2006,6 +2012,9 @@ def init(
consoles=None,
stop_on_reboot=False,
host_devices=None,
stop_on_crash=False,
stop_on_poweroff=False,
stop_on_lockfailure=False,
**kwargs
):
"""
Expand Down Expand Up @@ -2217,6 +2226,30 @@ def init(

.. versionadded:: 3003

:param stop_on_crash:
If set to ``True`` the guest will stop instead of rebooting.
This is specially useful when creating a virtual machine with an installation cdrom or
an autoinstallation needing a special first boot configuration.
Defaults to ``False``

.. versionadded:: ?

:param stop_on_poweroff:
If set to ``True`` the guest will stop instead of rebooting.
This is specially useful when creating a virtual machine with an installation cdrom or
an autoinstallation needing a special first boot configuration.
Defaults to ``False``

.. versionadded:: ?

:param stop_on_lockfailure:
If set to ``True`` the guest will stop instead of rebooting.
This is specially useful when creating a virtual machine with an installation cdrom or
an autoinstallation needing a special first boot configuration.
Defaults to ``False``

.. versionadded:: ?

:param boot:
Specifies kernel, initial ramdisk and kernel command line parameters for the virtual machine.
This is an optional parameter, all of the keys are optional within the dictionary. The structure of
Expand Down Expand Up @@ -2912,6 +2945,9 @@ def seeder(path):
consoles,
stop_on_reboot,
host_devices,
stop_on_crash,
stop_on_poweroff,
stop_on_lockfailure,
**kwargs
)
log.debug("New virtual machine definition: %s", vm_xml)
Expand Down Expand Up @@ -3499,6 +3535,9 @@ def update(
stop_on_reboot=False,
host_devices=None,
autostart=False,
stop_on_crash=False,
stop_on_poweroff=False,
stop_on_lockfailure=False,
**kwargs
):
"""
Expand Down Expand Up @@ -3619,6 +3658,30 @@ def update(

.. versionadded:: 3003

:param stop_on_crash:
If set to ``True`` the guest will stop instead of rebooting.
This is specially useful when creating a virtual machine with an installation cdrom or
an autoinstallation needing a special first boot configuration.
Defaults to ``False``

.. versionadded:: ?

:param stop_on_poweroff:
If set to ``True`` the guest will stop instead of rebooting.
This is specially useful when creating a virtual machine with an installation cdrom or
an autoinstallation needing a special first boot configuration.
Defaults to ``False``

.. versionadded:: ?

:param stop_on_lockfailure:
If set to ``True`` the guest will stop instead of rebooting.
This is specially useful when creating a virtual machine with an installation cdrom or
an autoinstallation needing a special first boot configuration.
Defaults to ``False``

.. versionadded:: ?

:param test: run in dry-run mode if set to True

.. versionadded:: 3001
Expand Down Expand Up @@ -3761,6 +3824,9 @@ def update(
consoles=consoles,
stop_on_reboot=stop_on_reboot,
host_devices=host_devices,
stop_on_crash=stop_on_crash,
stop_on_poweroff=stop_on_poweroff,
stop_on_lockfailure=stop_on_lockfailure,
**kwargs
)
)
Expand Down Expand Up @@ -3886,6 +3952,21 @@ def _set_cpuset(node, value):
"xpath": "on_reboot",
"convert": lambda v: "destroy" if v else "restart",
},
{
"path": "stop_on_crash",
"xpath": "on_crash",
"convert": lambda v: "destroy" if v else "restart",
},
{
"path": "stop_on_poweroff",
"xpath": "on_poweroff",
"convert": lambda v: "destroy" if v else "restart",
},
{
"path": "stop_on_lockfailure",
"xpath": "on_lockfailure",
"convert": lambda v: "destroy" if v else "restart",
},
{"path": "boot:kernel", "xpath": "os/kernel"},
{"path": "boot:initrd", "xpath": "os/initrd"},
{"path": "boot:cmdline", "xpath": "os/cmdline"},
Expand Down
63 changes: 63 additions & 0 deletions salt/states/virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ def defined(
live=True,
host_devices=None,
autostart=False,
stop_on_crash=False,
stop_on_poweroff=False,
stop_on_lockfailure=False,
):
"""
Starts an existing guest, or defines and starts a new VM with specified arguments.
Expand Down Expand Up @@ -586,6 +589,30 @@ def defined(

.. versionadded:: 3003

:param stop_on_crash:
If set to ``True`` the guest will stop instead of rebooting.
This is specially useful when creating a virtual machine with an installation cdrom or
an autoinstallation needing a special first boot configuration.
Defaults to ``False``

.. versionadded:: ?

:param stop_on_poweroff:
If set to ``True`` the guest will stop instead of rebooting.
This is specially useful when creating a virtual machine with an installation cdrom or
an autoinstallation needing a special first boot configuration.
Defaults to ``False``

.. versionadded:: ?

:param stop_on_lockfailure:
If set to ``True`` the guest will stop instead of rebooting.
This is specially useful when creating a virtual machine with an installation cdrom or
an autoinstallation needing a special first boot configuration.
Defaults to ``False``

.. versionadded:: ?

:param live:
If set to ``False`` the changes will not be applied live to the running instance, but will
only apply at the next start. Note that reboot will not take those changes.
Expand Down Expand Up @@ -673,6 +700,9 @@ def defined(
stop_on_reboot=stop_on_reboot,
host_devices=host_devices,
autostart=autostart,
stop_on_crash=stop_on_crash,
stop_on_poweroff=stop_on_poweroff,
stop_on_lockfailure=stop_on_lockfailure,
)
ret["changes"][name] = status
if not status.get("definition"):
Expand Down Expand Up @@ -716,6 +746,9 @@ def defined(
clock=clock,
stop_on_reboot=stop_on_reboot,
host_devices=host_devices,
stop_on_crash=stop_on_crash,
stop_on_poweroff=stop_on_poweroff,
stop_on_lockfailure=stop_on_lockfailure,
)
ret["changes"][name] = {"definition": True}
ret["comment"] = "Domain {} defined".format(name)
Expand Down Expand Up @@ -756,6 +789,9 @@ def running(
stop_on_reboot=False,
host_devices=None,
autostart=False,
stop_on_crash=False,
stop_on_poweroff=False,
stop_on_lockfailure=False,
):
"""
Starts an existing guest, or defines and starts a new VM with specified arguments.
Expand Down Expand Up @@ -907,6 +943,30 @@ def running(

.. versionadded:: 3003

:param stop_on_crash:
If set to ``True`` the guest will stop instead of rebooting.
This is specially useful when creating a virtual machine with an installation cdrom or
an autoinstallation needing a special first boot configuration.
Defaults to ``False``

.. versionadded:: ?

:param stop_on_poweroff:
If set to ``True`` the guest will stop instead of rebooting.
This is specially useful when creating a virtual machine with an installation cdrom or
an autoinstallation needing a special first boot configuration.
Defaults to ``False``

.. versionadded:: ?

:param stop_on_lockfailure:
If set to ``True`` the guest will stop instead of rebooting.
This is specially useful when creating a virtual machine with an installation cdrom or
an autoinstallation needing a special first boot configuration.
Defaults to ``False``

.. versionadded:: ?

:param hypervisor_features:
Enable or disable hypervisor-specific features on the virtual machine.

Expand Down Expand Up @@ -1035,6 +1095,9 @@ def running(
consoles=consoles,
host_devices=host_devices,
autostart=autostart,
stop_on_crash=stop_on_crash,
stop_on_poweroff=stop_on_poweroff,
stop_on_lockfailure=stop_on_lockfailure,
)

result = True if not __opts__["test"] else None
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/modules/test_virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2635,6 +2635,9 @@ def test_update_existing_numatune_params(self):
<type arch='x86_64' machine='pc-i440fx-2.6'>hvm</type>
</os>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<on_poweroff>restart</on_poweroff>
<on_lockfailure>restart</on_lockfailure>
</domain>
"""
domain_mock = self.set_mock_vm("vm_with_numatune_param", xml_numatune)
Expand Down Expand Up @@ -3662,6 +3665,9 @@ def test_update_exist_memorybacking_params(self):
<type arch='x86_64' machine='pc-i440fx-2.6'>hvm</type>
</os>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<on_poweroff>restart</on_poweroff>
<on_lockfailure>restart</on_lockfailure>
</domain>
"""
domain_mock = self.set_mock_vm("vm_with_memback_param", xml_with_memback_params)
Expand Down