]> git.proxmox.com Git - pve-manager.git/commitdiff
ceph/destroypool: optionally remove storages
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Tue, 5 Sep 2017 12:59:38 +0000 (14:59 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 7 Sep 2017 09:38:20 +0000 (11:38 +0200)
only storages which don't have the 'monhost' option set are removed

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
PVE/API2/Ceph.pm

index 82b0c8526843f70a6eb8a07e4b1de0315cdd276d..53483ddedd293f9a9034908671fc1e25dc2055c2 100644 (file)
@@ -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;
     }});