[pve-devel] [PATCH manager v3 09/20] ceph/createpool: optionally add storages
Fabian Grünbichler
f.gruenbichler at proxmox.com
Thu Aug 31 11:38:12 CEST 2017
introduce new API parameter 'add_storages'. if set, one
storage each is configured using the created pool:
- for containers using KRBD
- for VMs using librbd
Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
rebased for v3
changes since v1:
- drop monitor info retrieval (no longer needed)
- die if any of the storages could not be added
PVE/API2/Ceph.pm | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index a2c094fd..a8ea2b39 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -1584,7 +1584,12 @@ __PACKAGE__->register_method ({
type => 'string',
enum => ['rbd', 'cephfs', 'rgw'],
optional => 1,
- }
+ },
+ add_storages => {
+ description => "Configure VM and CT storages using the new pool.",
+ type => 'boolean',
+ optional => 1,
+ },
},
},
returns => { type => 'null' },
@@ -1600,6 +1605,14 @@ __PACKAGE__->register_method ({
my $pool = $param->{name};
+ 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);
+ }
+
my $pg_num = $param->{pg_num} || 64;
my $size = $param->{size} || 3;
my $min_size = $param->{min_size} || 2;
@@ -1645,6 +1658,22 @@ __PACKAGE__->register_method ({
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 undef;
}});
--
2.11.0
More information about the pve-devel
mailing list