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 <[email protected]>
---
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 7514d933..14b8823e 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -1755,7 +1755,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' },
@@ -1771,6 +1776,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;
@@ -1816,6 +1829,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


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

Reply via email to