[pve-devel] [RFC v2 qemu-server] VM protection mode added

Thomas Lamprecht t.lamprecht at proxmox.com
Thu Sep 3 14:54:40 CEST 2015



On 09/03/2015 02:35 PM, Alen Grizonic wrote:
> used to forbid a virtual machine remove operation
>
> v2 changes: error message
> ---
>   PVE/API2/Qemu.pm  | 11 +++++++++++
>   PVE/QemuServer.pm |  6 ++++++
>   2 files changed, 17 insertions(+)
>
> diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
> index 20d73f7..a302d06 100644
> --- a/PVE/API2/Qemu.pm
> +++ b/PVE/API2/Qemu.pm
> @@ -299,6 +299,12 @@ __PACKAGE__->register_method({
>   		    type => 'string', format => 'pve-poolid',
>   		    description => "Add the VM to the specified pool.",
>   		},
> +		protection => {
> +		    optional => 1,
> +	            type => 'boolean',
> +	            description => "Enable/disable VM protection mode.",
> +	            default => 0,
> +                },
>   	    }),
>       },
>       returns => {
> @@ -325,6 +331,8 @@ __PACKAGE__->register_method({
>   
>   	my $pool = extract_param($param, 'pool');
>   
> +	my $protection = extract_param($param, 'protection');
> +
Why does the protection parameter gets extracted here when it's never 
used anywhere inside this method?
Further when extracted, the parameter gets deleted from the hash, thus 
not written to the config file, or am I mistaken?
>   	my $filename = PVE::QemuServer::config_file($vmid);
>   
>   	my $storecfg = PVE::Storage::config();
> @@ -1142,6 +1150,9 @@ __PACKAGE__->register_method({
>   
>   	my $storecfg = PVE::Storage::config();
>   
> +	die  "can't remove VM $vmid - protection mode enabled\n"
> +	    if ($conf->{protection} == 1);
> +
>   	die "unable to remove VM $vmid - used in HA resources\n"
>   	    if PVE::HA::Config::vm_is_ha_managed($vmid);
>   
> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
> index be53a1e..c82c052 100644
> --- a/PVE/QemuServer.pm
> +++ b/PVE/QemuServer.pm
> @@ -384,6 +384,12 @@ EODESCR
>   	maxLength => 256,
>   	optional => 1,
>       },
> +    protection => {
> +        optional => 1,
> +        type => 'boolean',
> +        description => "The enable/disable VM protection mode used to forbid a virtual machine remove operation.",
> +        default => 0,
> +    },
>   };
>   
>   # what about other qemu settings ?





More information about the pve-devel mailing list