[pve-devel] [PATCH manager v4 08/19] ceph/createpool: optionally add storages

Fabian Grünbichler f.gruenbichler at proxmox.com
Tue Sep 5 14:59:37 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 7b1f5293..82b0c852 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -1583,7 +1583,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' },
@@ -1599,6 +1604,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;
@@ -1644,6 +1657,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