[pve-devel] [PATCH qemu-server v3 1/1] add hookscripts to vms

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Jan 30 08:22:24 CET 2019


On 1/29/19 4:28 PM, Dominik Csapak wrote:
> this adds a new config option for it, and executes it on four
> points in time:
> 
> 'pre-start'
> 'post-start'
> 'pre-stop'
> 'post-stop'
> 
> on pre-start we abort if the script fails
> and pre-stop will not be called if the vm crashes or if
> the vm gets powered off from inside the guest
> 
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
> changes from v2:
> * use check hookscript from GuestHelpers
>  PVE/API2/Qemu.pm  |  8 ++++++++
>  PVE/CLI/qm.pm     |  2 ++
>  PVE/QemuServer.pm | 12 ++++++++++++
>  3 files changed, 22 insertions(+)
> 
> diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
> index 148ea1a..4b6269f 100644
> --- a/PVE/API2/Qemu.pm
> +++ b/PVE/API2/Qemu.pm
> @@ -1100,6 +1100,14 @@ my $update_vm_api  = sub {
>  	    if ($param->{$opt} eq '1') {
>  		$param->{$opt} = PVE::QemuServer::generate_uuid();
>  	    }
> +	} elsif ($opt eq 'hookscript') {
> +	    eval {
> +		PVE::GuestHelpers::check_hookscript_volume_id($param->{$opt}, $storecfg);
> +	    };
> +
> +	    if (my $err = $@) {
> +		raise_param_exc({ $opt => $err });
> +	    }

Maybe just do:
	eval { PVE::GuestHelpers::check_hookscript($param->{$opt}, $storecfg) };
	raise_param_exc({ $opt => $@ }) if $@;

? same but more concise and a common pattern in PVE. If you only do two things its not
really useful to bloat them up to >2 times the lines needed. As with my reply to
guest-common 2/2 this is a 'if a vN+1 is needed, else I'll gladly fix it up thing :)

>  	}
>      }
>  




More information about the pve-devel mailing list