in order to get task log entries and easily accessible
task/error logs.

Signed-off-by: Fabian Grünbichler <[email protected]>
---
new in v2

note: git show -U1 -w is recommended to view this ;)

 PVE/API2/Ceph.pm | 148 ++++++++++++++++++++++++++++---------------------------
 1 file changed, 76 insertions(+), 72 deletions(-)

diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index 06c4bb8b..04c59c30 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -1763,7 +1763,7 @@ __PACKAGE__->register_method ({
            },
        },
     },
-    returns => { type => 'null' },
+    returns => { type => 'string' },
     code => sub {
        my ($param) = @_;
 
@@ -1775,10 +1775,10 @@ __PACKAGE__->register_method ({
            if ! -f $pve_ckeyring_path;
 
        my $pool = $param->{name};
+       my $rpcenv = PVE::RPCEnvironment::get();
+       my $user = $rpcenv->get_user();
 
        if ($param->{add_storages}) {
-           my $rpcenv = PVE::RPCEnvironment::get();
-           my $user = $rpcenv->get_user();
            $rpcenv->check($user, '/storage', ['Datastore.Allocate']);
            die "pool name contains characters which are illegal for storage 
naming\n"
                if !PVE::JSONSchema::parse_storage_id($pool);
@@ -1787,65 +1787,68 @@ __PACKAGE__->register_method ({
        my $pg_num = $param->{pg_num} || 64;
        my $size = $param->{size} || 3;
        my $min_size = $param->{min_size} || 2;
-       my $rados = PVE::RADOS->new();
        my $application = $param->{application} // 'rbd';
 
-       $rados->mon_command({
-           prefix => "osd pool create",
-           pool => $pool,
-           pg_num => int($pg_num),
-           format => 'plain',
-       });
-
-       $rados->mon_command({
-           prefix => "osd pool set",
-           pool => $pool,
-           var => 'min_size',
-           val => $min_size,
-           format => 'plain',
-       });
+       my $worker = sub {
 
-       $rados->mon_command({
-           prefix => "osd pool set",
-           pool => $pool,
-           var => 'size',
-           val => $size,
-           format => 'plain',
-       });
+           my $rados = PVE::RADOS->new();
+           $rados->mon_command({
+               prefix => "osd pool create",
+               pool => $pool,
+               pg_num => int($pg_num),
+               format => 'plain',
+           });
 
-       if (defined($param->{crush_rule})) {
            $rados->mon_command({
                prefix => "osd pool set",
                pool => $pool,
-               var => 'crush_rule',
-               val => $param->{crush_rule},
+               var => 'min_size',
+               val => $min_size,
                format => 'plain',
            });
-       }
 
-       $rados->mon_command({
-               prefix => "osd pool application enable",
+           $rados->mon_command({
+               prefix => "osd pool set",
                pool => $pool,
-               app => $application,
-       });
+               var => 'size',
+               val => $size,
+               format => 'plain',
+           });
 
-       if ($param->{add_storages}) {
-           my $err;
-           eval { $add_storage->($pool, "${pool}_vm", 0); };
-           if ($@) {
-               warn "failed to add VM storage: $@";
-               $err = 1;
+           if (defined($param->{crush_rule})) {
+               $rados->mon_command({
+                   prefix => "osd pool set",
+                   pool => $pool,
+                   var => 'crush_rule',
+                   val => $param->{crush_rule},
+                   format => 'plain',
+               });
            }
-           eval { $add_storage->($pool, "${pool}_ct", 1); };
-           if ($@) {
-               warn "failed to add CT storage: $@";
-               $err = 1;
+
+           $rados->mon_command({
+                   prefix => "osd pool application enable",
+                   pool => $pool,
+                   app => $application,
+           });
+
+           if ($param->{add_storages}) {
+               my $err;
+               eval { $add_storage->($pool, "${pool}_vm", 0); };
+               if ($@) {
+                   warn "failed to add VM storage: $@";
+                   $err = 1;
+               }
+               eval { $add_storage->($pool, "${pool}_ct", 1); };
+               if ($@) {
+                   warn "failed to add CT storage: $@";
+                   $err = 1;
+               }
+               die "adding storages for pool '$pool' failed, check log and add 
manually!\n"
+                   if $err;
            }
-           die "adding storages for pool '$pool' failed, check log and add 
manually!\n"
-               if $err;
-       }
+       };
 
-       return undef;
+       return $rpcenv->fork_worker('cephcreatepool', $pool,  $user, $worker);
     }});
 
 __PACKAGE__->register_method ({
@@ -2000,7 +2003,7 @@ __PACKAGE__->register_method ({
            },
        },
     },
-    returns => { type => 'null' },
+    returns => { type => 'string' },
     code => sub {
        my ($param) = @_;
 
@@ -2029,31 +2032,32 @@ __PACKAGE__->register_method ({
            }
        }
 
-       my $rados = PVE::RADOS->new();
-       # fixme: '--yes-i-really-really-mean-it'
-       $rados->mon_command({
-           prefix => "osd pool delete",
-           pool => $pool,
-           pool2 => $pool,
-           sure => '--yes-i-really-really-mean-it',
-           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;
+       my $worker = sub {
+               my $rados = PVE::RADOS->new();
+               # fixme: '--yes-i-really-really-mean-it'
+               $rados->mon_command({
+                   prefix => "osd pool delete",
+                   pool => $pool,
+                   pool2 => $pool,
+                   sure => '--yes-i-really-really-mean-it',
+                   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;
                }
-           }
-           die "failed to remove (some) storages - check log and remove 
manually!\n"
-               if $err;
-       }
-
-       return undef;
+       };
+       return $rpcenv->fork_worker('cephdestroypool', $pool,  $user, $worker);
     }});
 
 
-- 
2.11.0


_______________________________________________
pve-devel mailing list
[email protected]
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to