[pve-devel] [PATCH manager v4 09/19] ceph/destroypool: optionally remove storages

Fabian Grünbichler f.gruenbichler at proxmox.com
Tue Sep 5 14:59:38 CEST 2017


only storages which don't have the 'monhost' option set are removed

Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
changes since v3:
- use monhost instead of pveceph

changes since v2:
- adapted for $get_storages changes
- inlined $remove_storage

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 | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index 82b0c852..53483dde 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;
     }});
 
-- 
2.11.0





More information about the pve-devel mailing list