[pve-devel] [PATCH manager v3 12/20] ceph: make create/destroypool API paths async
Fabian Grünbichler
f.gruenbichler at proxmox.com
Thu Aug 31 11:38:15 CEST 2017
in order to get task log entries and easily accessible
task/error logs.
Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
rebased for v3
new in v2
note: git show -U1 -w is recommended to view this ;)
PVE/API2/Ceph.pm | 146 ++++++++++++++++++++++++++++---------------------------
1 file changed, 75 insertions(+), 71 deletions(-)
diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index a462056f..e4443bf7 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -1592,7 +1592,7 @@ __PACKAGE__->register_method ({
},
},
},
- returns => { type => 'null' },
+ returns => { type => 'string' },
code => sub {
my ($param) = @_;
@@ -1604,10 +1604,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);
@@ -1616,65 +1616,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 ({
@@ -1829,7 +1832,7 @@ __PACKAGE__->register_method ({
},
},
},
- returns => { type => 'null' },
+ returns => { type => 'string' },
code => sub {
my ($param) = @_;
@@ -1857,31 +1860,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;
- foreach my $storeid (keys %$storages) {
- next if !$storages->{$storeid}->{pveceph};
- eval { PVE::API2::Storage::Config->delete({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;
+ foreach my $storeid (keys %$storages) {
+ next if !$storages->{$storeid}->{pveceph};
+ 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;
}
- 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
More information about the pve-devel
mailing list