diff --git a/salt/modules/virt.py b/salt/modules/virt.py index 1e671621c25f..a912885373af 100644 --- a/salt/modules/virt.py +++ b/salt/modules/virt.py @@ -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 ): """ @@ -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) @@ -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 ): """ @@ -2211,12 +2220,36 @@ def init( :param stop_on_reboot: 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. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. Defaults to ``False`` .. versionadded:: 3003 + :param stop_on_crash: + If set to ``True`` the guest will stop instead of rebooting. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: 3007 + + :param stop_on_poweroff: + If set to ``True`` the guest will stop instead of rebooting. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: 3007 + + :param stop_on_lockfailure: + If set to ``True`` the guest will stop instead of rebooting. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: 3007 + :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 @@ -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) @@ -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 ): """ @@ -3613,12 +3652,36 @@ def update( :param stop_on_reboot: 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. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. Defaults to ``False`` .. versionadded:: 3003 + :param stop_on_crash: + If set to ``True`` the guest will stop instead of rebooting. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: 3007 + + :param stop_on_poweroff: + If set to ``True`` the guest will stop instead of rebooting. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: 3007 + + :param stop_on_lockfailure: + If set to ``True`` the guest will stop instead of rebooting. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: 3007 + :param test: run in dry-run mode if set to True .. versionadded:: 3001 @@ -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 ) ) @@ -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"}, diff --git a/salt/states/virt.py b/salt/states/virt.py index 3b958e32d60a..5fbafac1e3b1 100644 --- a/salt/states/virt.py +++ b/salt/states/virt.py @@ -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. @@ -580,12 +583,36 @@ def defined( :param stop_on_reboot: 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. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. Defaults to ``False`` .. versionadded:: 3003 + :param stop_on_crash: + If set to ``True`` the guest will stop instead of rebooting. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: 3007 + + :param stop_on_poweroff: + If set to ``True`` the guest will stop instead of rebooting. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: 3007 + + :param stop_on_lockfailure: + If set to ``True`` the guest will stop instead of rebooting. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: 3007 + :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. @@ -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"): @@ -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) @@ -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. @@ -901,12 +937,36 @@ def running( :param stop_on_reboot: 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. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. Defaults to ``False`` .. versionadded:: 3003 + :param stop_on_crash: + If set to ``True`` the guest will stop instead of rebooting. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: 3007 + + :param stop_on_poweroff: + If set to ``True`` the guest will stop instead of rebooting. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: 3007 + + :param stop_on_lockfailure: + If set to ``True`` the guest will stop instead of rebooting. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: 3007 + :param hypervisor_features: Enable or disable hypervisor-specific features on the virtual machine. @@ -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 diff --git a/tests/unit/modules/test_virt.py b/tests/unit/modules/test_virt.py index 7e72d07b8e77..51b94161e00f 100644 --- a/tests/unit/modules/test_virt.py +++ b/tests/unit/modules/test_virt.py @@ -2635,6 +2635,9 @@ def test_update_existing_numatune_params(self): hvm restart + restart + restart + restart """ domain_mock = self.set_mock_vm("vm_with_numatune_param", xml_numatune) @@ -3662,6 +3665,9 @@ def test_update_exist_memorybacking_params(self): hvm restart + restart + restart + restart """ domain_mock = self.set_mock_vm("vm_with_memback_param", xml_with_memback_params)