[pve-devel] [v2 manager 18/27] ceph/destroypool: optionally remove storages

Fabian Gr├╝nbichler f.gruenbichler at proxmox.com
Tue Aug 29 13:04:40 CEST 2017


Signed-off-by: Fabian Gr├╝nbichler <f.gruenbichler at proxmox.com>
---
changes since v1:
- die if any of the storages could not be removed
- move storage retrieval into lower if (refactoring was dropped in v2)

 PVE/API2/Ceph.pm | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index 1cdc2723..45477f4b 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -1991,7 +1991,13 @@ __PACKAGE__->register_method ({
 		type => 'boolean',
 		optional => 1,
 		default => 0,
-	    }
+	    },
+	    remove_storages => {
+		description => "Remove all pveceph-managed storages configured for this pool",
+		type => 'boolean',
+		optional => 1,
+		default => 0,
+	    },
 	},
     },
     returns => { type => 'null' },
@@ -2000,6 +2006,11 @@ __PACKAGE__->register_method ({
 
 	PVE::CephTools::check_ceph_inited();
 
+	my $rpcenv = PVE::RPCEnvironment::get();
+	my $user = $rpcenv->get_user();
+	$rpcenv->check($user, '/storage', ['Datastore.Allocate'])
+	    if $param->{remove_storages};
+
 	my $pool = $param->{name};
 
 	# if not forced, destroy ceph pool only when no
@@ -2028,6 +2039,20 @@ __PACKAGE__->register_method ({
 	    format => 'plain',
         });
 
+	if ($param->{remove_storages}) {
+	    my $err;
+	    my $storages = $get_storages->($pool);
+	    foreach my $storeid (keys %$storages) {
+		eval { $remove_storage->($storeid); };
+		if ($@) {
+		    warn "failed to remove storage '$storeid': $@\n";
+		    $err = 1;
+		}
+	    }
+	    die "failed to remove (some) storages - check log and remove manually!\n"
+		if $err;
+	}
+
 	return undef;
     }});
 
-- 
2.11.0




More information about the pve-devel mailing list