From f6144f3493a83268bc92477c21c1a3d80198625f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Tue, 5 Sep 2017 14:59:38 +0200 Subject: [PATCH] ceph/destroypool: optionally remove storages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit only storages which don't have the 'monhost' option set are removed Signed-off-by: Fabian Grünbichler --- PVE/API2/Ceph.pm | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm index 82b0c8526..53483dded 100644 --- a/PVE/API2/Ceph.pm +++ b/PVE/API2/Ceph.pm @@ -1819,7 +1819,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' }, @@ -1828,7 +1834,13 @@ __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}; + my $storages = $get_storages->($pool); # if not forced, destroy ceph pool only when no # vm disks are on it anymore @@ -1856,6 +1868,21 @@ __PACKAGE__->register_method ({ format => 'plain', }); + if ($param->{remove_storages}) { + my $err; + foreach my $storeid (keys %$storages) { + # skip external clusters, not managed by pveceph + next if $storages->{$storeid}->{monhost}; + eval { PVE::API2::Storage::Config->delete({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; }});