ceph: make create/destroypool API paths async

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

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2017-09-05 14:59:40 +02:00 committed by Wolfgang Bumiller
parent c75f019a55
commit 8c42620460

View File

@ -1591,7 +1591,7 @@ __PACKAGE__->register_method ({
}, },
}, },
}, },
returns => { type => 'null' }, returns => { type => 'string' },
code => sub { code => sub {
my ($param) = @_; my ($param) = @_;
@ -1603,10 +1603,10 @@ __PACKAGE__->register_method ({
if ! -f $pve_ckeyring_path; if ! -f $pve_ckeyring_path;
my $pool = $param->{name}; my $pool = $param->{name};
my $rpcenv = PVE::RPCEnvironment::get();
my $user = $rpcenv->get_user();
if ($param->{add_storages}) { if ($param->{add_storages}) {
my $rpcenv = PVE::RPCEnvironment::get();
my $user = $rpcenv->get_user();
$rpcenv->check($user, '/storage', ['Datastore.Allocate']); $rpcenv->check($user, '/storage', ['Datastore.Allocate']);
die "pool name contains characters which are illegal for storage naming\n" die "pool name contains characters which are illegal for storage naming\n"
if !PVE::JSONSchema::parse_storage_id($pool); if !PVE::JSONSchema::parse_storage_id($pool);
@ -1615,65 +1615,68 @@ __PACKAGE__->register_method ({
my $pg_num = $param->{pg_num} || 64; my $pg_num = $param->{pg_num} || 64;
my $size = $param->{size} || 3; my $size = $param->{size} || 3;
my $min_size = $param->{min_size} || 2; my $min_size = $param->{min_size} || 2;
my $rados = PVE::RADOS->new();
my $application = $param->{application} // 'rbd'; my $application = $param->{application} // 'rbd';
$rados->mon_command({ my $worker = sub {
prefix => "osd pool create",
pool => $pool,
pg_num => int($pg_num),
format => 'plain',
});
$rados->mon_command({ my $rados = PVE::RADOS->new();
prefix => "osd pool set", $rados->mon_command({
pool => $pool, prefix => "osd pool create",
var => 'min_size', pool => $pool,
val => $min_size, pg_num => int($pg_num),
format => 'plain', format => 'plain',
}); });
$rados->mon_command({
prefix => "osd pool set",
pool => $pool,
var => 'size',
val => $size,
format => 'plain',
});
if (defined($param->{crush_rule})) {
$rados->mon_command({ $rados->mon_command({
prefix => "osd pool set", prefix => "osd pool set",
pool => $pool, pool => $pool,
var => 'crush_rule', var => 'min_size',
val => $param->{crush_rule}, val => $min_size,
format => 'plain', format => 'plain',
}); });
}
$rados->mon_command({ $rados->mon_command({
prefix => "osd pool application enable", prefix => "osd pool set",
pool => $pool, pool => $pool,
app => $application, var => 'size',
}); val => $size,
format => 'plain',
});
if ($param->{add_storages}) { if (defined($param->{crush_rule})) {
my $err; $rados->mon_command({
eval { $add_storage->($pool, "${pool}_vm", 0); }; prefix => "osd pool set",
if ($@) { pool => $pool,
warn "failed to add VM storage: $@"; var => 'crush_rule',
$err = 1; val => $param->{crush_rule},
format => 'plain',
});
} }
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;
}
return undef; $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;
}
};
return $rpcenv->fork_worker('cephcreatepool', $pool, $user, $worker);
}}); }});
__PACKAGE__->register_method ({ __PACKAGE__->register_method ({
@ -1828,7 +1831,7 @@ __PACKAGE__->register_method ({
}, },
}, },
}, },
returns => { type => 'null' }, returns => { type => 'string' },
code => sub { code => sub {
my ($param) = @_; my ($param) = @_;
@ -1856,32 +1859,33 @@ __PACKAGE__->register_method ({
} }
} }
my $rados = PVE::RADOS->new(); my $worker = sub {
# fixme: '--yes-i-really-really-mean-it' my $rados = PVE::RADOS->new();
$rados->mon_command({ # fixme: '--yes-i-really-really-mean-it'
prefix => "osd pool delete", $rados->mon_command({
pool => $pool, prefix => "osd pool delete",
pool2 => $pool, pool => $pool,
sure => '--yes-i-really-really-mean-it', pool2 => $pool,
format => 'plain', sure => '--yes-i-really-really-mean-it',
}); format => 'plain',
});
if ($param->{remove_storages}) { if ($param->{remove_storages}) {
my $err; my $err;
foreach my $storeid (keys %$storages) { foreach my $storeid (keys %$storages) {
# skip external clusters, not managed by pveceph # skip external clusters, not managed by pveceph
next if $storages->{$storeid}->{monhost}; next if $storages->{$storeid}->{monhost};
eval { PVE::API2::Storage::Config->delete({storage => $storeid}) }; eval { PVE::API2::Storage::Config->delete({storage => $storeid}) };
if ($@) { if ($@) {
warn "failed to remove storage '$storeid': $@\n"; warn "failed to remove storage '$storeid': $@\n";
$err = 1; $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 $rpcenv->fork_worker('cephdestroypool', $pool, $user, $worker);
}
return undef;
}}); }});