[pve-devel] [storage V4] Add option check if the image can safely remove

Wolfgang Link w.link at proxmox.com
Tue Nov 13 11:57:24 CET 2018


If an image has a <vmid> encoded in the image name
and the guest does not exist in the cluster
we can safely delete it on the GUI.

Also, if a config exists on another node and the storage is local
we can delete it too.

In all other cases, a rescan must manual performed
to add it back to the guest config.

Note: It is possible when a replication job exists
to removes the target image of the replica.
This will force new initial sync of this image.
---
 PVE/API2/Storage/Content.pm | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/PVE/API2/Storage/Content.pm b/PVE/API2/Storage/Content.pm
index e941cb6..3c251ce 100644
--- a/PVE/API2/Storage/Content.pm
+++ b/PVE/API2/Storage/Content.pm
@@ -285,6 +285,11 @@ __PACKAGE__->register_method ({
 		type => 'string',
 		completion => \&PVE::Storage::complete_volume,
 	    },
+	    check => {
+		description => "Check if the image can remove safely",
+		type => 'boolean',
+		optional => 1,
+	    },
 	},
     },
     returns => { type => 'null' },
@@ -306,6 +311,24 @@ __PACKAGE__->register_method ({
 	    $rpcenv->check($authuser, "/storage/$storeid", ['Datastore.Allocate']);
 	}
 
+	if ($param->{check} && defined($ownervm)) {
+
+		my $vms = PVE::Cluster::get_vmlist();
+		my $localnode = PVE::INotify::nodename();
+
+		my $guest_exist = defined($vms->{ids}->{$ownervm});
+		my $guest_on_localhost = $guest_exist
+			&& $vms->{ids}->{$ownervm}->{node} eq $localnode;
+
+		my $storage_is_shared = defined($cfg->{ids}->{$storeid}->{shared});
+
+		die "Guest: $ownervm exist on local node. Remove image from guest Hardware.\n"
+			if $guest_on_localhost ;
+
+		die "Guest: $ownervm exist and storage: $storeid is shared.\n"
+			if $guest_exist && $storage_is_shared;
+	}
+
 	PVE::Storage::vdisk_free ($cfg, $volid);
 
 	return undef;
-- 
2.11.0





More information about the pve-devel mailing list