From b0537f7be94af3960d78de16b2834ba011cc8dd2 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 19 Nov 2013 13:25:36 +0100 Subject: [PATCH] add API for ceph pools --- PVE/API2/Ceph.pm | 114 +++++++++++++++++++++++++++++++++++++++++++++++ bin/pveceph | 10 +++++ 2 files changed, 124 insertions(+) diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm index ae32f73a..27e7f9a2 100644 --- a/PVE/API2/Ceph.pm +++ b/PVE/API2/Ceph.pm @@ -381,6 +381,7 @@ __PACKAGE__->register_method ({ { name => 'init' }, { name => 'mon' }, { name => 'osd' }, + { name => 'pools' }, { name => 'stop' }, { name => 'start' }, { name => 'status' }, @@ -860,6 +861,119 @@ __PACKAGE__->register_method ({ return &$run_ceph_cmd_json(['status'], quiet => 1); }}); +__PACKAGE__->register_method ({ + name => 'lspools', + path => 'pools', + method => 'GET', + description => "List all pools.", + proxyto => 'node', + protected => 1, + parameters => { + additionalProperties => 0, + properties => { + node => get_standard_option('pve-node'), + }, + }, + returns => { + type => 'array', + items => { + type => "object", + properties => { + pool => { type => 'integer' }, + pool_name => { type => 'string' }, + size => { type => 'integer' }, + }, + }, + links => [ { rel => 'child', href => "{pool_name}" } ], + }, + code => sub { + my ($param) = @_; + + &$check_ceph_inited(); + + my $res = &$run_ceph_cmd_json(['osd', 'dump'], quiet => 1); + + my $data = []; + foreach my $e (@{$res->{pools}}) { + my $d = {}; + foreach my $attr (qw(pool pool_name size min_size pg_num crush_ruleset)) { + $d->{$attr} = $e->{$attr} if defined($e->{$attr}); + } + push @$data, $d; + } + + return $data; + }}); + +__PACKAGE__->register_method ({ + name => 'createpool', + path => 'pools', + method => 'POST', + description => "Create POOL", + proxyto => 'node', + protected => 1, + parameters => { + additionalProperties => 0, + properties => { + node => get_standard_option('pve-node'), + name => { + description => "The name of the pool. It must be unique.", + type => 'string', + }, + pg_num => { + description => "Number of placement groups.", + type => 'integer', + default => 512, + optional => 1, + minimum => 8, + maximum => 32768, + }, + }, + }, + returns => { type => 'null' }, + code => sub { + my ($param) = @_; + + &$check_ceph_inited(); + + die "not fully configured - missing '$pve_ckeyring_path'\n" + if ! -f $pve_ckeyring_path; + + my $pg_num = $param->{pg_num} || 512; + + &$run_ceph_cmd(['osd', 'pool', 'create', $param->{name}, $pg_num]); + + return undef; + }}); + +__PACKAGE__->register_method ({ + name => 'destroypool', + path => 'pools/{name}', + method => 'DELETE', + description => "Destroy pool", + proxyto => 'node', + protected => 1, + parameters => { + additionalProperties => 0, + properties => { + node => get_standard_option('pve-node'), + name => { + description => "The name of the pool. It must be unique.", + type => 'string', + }, + }, + }, + returns => { type => 'null' }, + code => sub { + my ($param) = @_; + + &$check_ceph_inited(); + + &$run_ceph_cmd(['osd', 'pool', 'delete', $param->{name}, $param->{name}, '--yes-i-really-really-mean-it']); + + return undef; + }}); + __PACKAGE__->register_method ({ name => 'listosd', path => 'osd', diff --git a/bin/pveceph b/bin/pveceph index 21b0aeca..f9844604 100755 --- a/bin/pveceph +++ b/bin/pveceph @@ -114,6 +114,16 @@ __PACKAGE__->register_method ({ my $cmddef = { init => [ 'PVE::API2::Ceph', 'init', [], { node => $nodename } ], + lspools => [ 'PVE::API2::Ceph', 'lspools', [], { node => $nodename }, sub { + my $res = shift; + + printf("%-20s %10s %10s\n", "Name", "size", "pg_num"); + foreach my $p (sort {$a->{pool_name} cmp $b->{pool_name}} @$res) { + printf("%-20s %10d %10d\n", $p->{pool_name}, $p->{size}, $p->{pg_num}); + } + }], + createpool => [ 'PVE::API2::Ceph', 'createpool', ['name'], { node => $nodename }], + destroypool => [ 'PVE::API2::Ceph', 'destroypool', ['name'], { node => $nodename } ], createosd => [ 'PVE::API2::Ceph', 'createosd', ['dev'], { node => $nodename } ], destroyosd => [ 'PVE::API2::Ceph', 'destroyosd', ['osdid'], { node => $nodename } ], createmon => [ 'PVE::API2::Ceph', 'createmon', [], { node => $nodename } ],