rados block plugin update

config file
-----------
rbd: rbdtest
        monhost 10.3.94.27:6789;10.3.94.28:6789;10.3.94.29:6789
        pool pool2
        username admin
        authsupported cephx;none
        content images

key for user admin must be specified in:
---------------------------------------
/etc/pve/priv/ceph/storeid.username.key

/etc/pve/priv/ceph/rbdtest.admin.key   for this exemple.

(so we can have multiple users key by storage and multiple storage with same username)

I change "sub path" in Storage.pm to pass $storeid as third argument.

I rename property id to username, to be more clear.

removal of rbd_ prefix.

removal of trailing whitespace

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
This commit is contained in:
Alexandre Derumier
2012-06-01 15:52:56 +02:00
committed by Dietmar Maurer
parent 0509010d6e
commit e5427b0097
2 changed files with 36 additions and 43 deletions

View File

@ -236,7 +236,7 @@ sub path {
my $scfg = storage_config($cfg, $storeid); my $scfg = storage_config($cfg, $storeid);
my $plugin = PVE::Storage::Plugin->lookup($scfg->{type}); my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
my ($path, $owner, $vtype) = $plugin->path($scfg, $volname); my ($path, $owner, $vtype) = $plugin->path($scfg, $volname, $storeid);
return wantarray ? ($path, $owner, $vtype) : $path; return wantarray ? ($path, $owner, $vtype) : $path;
} }

View File

@ -11,13 +11,13 @@ use base qw(PVE::Storage::Plugin);
sub rbd_ls{ sub rbd_ls{
my ($scfg) = @_; my ($scfg, $storeid) = @_;
my $rbdpool = $scfg->{rbd_pool}; my $rbdpool = $scfg->{pool};
my $monhost = $scfg->{rbd_monhost}; my $monhost = $scfg->{monhost};
$monhost =~ s/;/,/g; $monhost =~ s/;/,/g;
my $cmd = ['/usr/bin/rbd', '-p', $rbdpool, '-m', $monhost, '-n', "client.".$scfg->{rbd_id} ,'--key',$scfg->{rbd_key} ,'ls' ]; my $cmd = ['/usr/bin/rbd', '-p', $rbdpool, '-m', $monhost, '-n', "client.".$scfg->{username} ,'--keyfile', '/etc/pve/priv/ceph/'.$storeid.'.'.$scfg->{username}.'.key', '--auth_supported',$scfg->{authsupported}, 'ls' ];
my $list = {}; my $list = {};
run_command($cmd, errfunc => sub {},outfunc => sub { run_command($cmd, errfunc => sub {},outfunc => sub {
my $line = shift; my $line = shift;
@ -46,8 +46,8 @@ sub addslashes {
# Configuration # Configuration
PVE::JSONSchema::register_format('pve-storage-rbd-mon', \&parse_rbd_mon); PVE::JSONSchema::register_format('pve-storage-monhost', \&parse_monhost);
sub parse_rbd_mon { sub parse_monhost {
my ($name, $noerr) = @_; my ($name, $noerr) = @_;
if ($name !~ m/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i) { if ($name !~ m/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i) {
@ -71,23 +71,19 @@ sub plugindata {
sub properties { sub properties {
return { return {
rbd_monhost => { monhost => {
description => "Monitors daemon ips.", description => "Monitors daemon ips.",
type => 'string', type => 'string',
}, },
rbd_pool => { pool => {
description => "RBD Pool.", description => "Pool.",
type => 'string', type => 'string',
}, },
rbd_id => { username => {
description => "RBD Id.", description => "RBD Id.",
type => 'string', type => 'string',
}, },
rbd_key => { authsupported => {
description => "Key.",
type => 'string',
},
rbd_authsupported => {
description => "Authsupported.", description => "Authsupported.",
type => 'string', type => 'string',
}, },
@ -96,11 +92,10 @@ sub properties {
sub options { sub options {
return { return {
rbd_monhost => { fixed => 1 }, monhost => { fixed => 1 },
rbd_pool => { fixed => 1 }, pool => { fixed => 1 },
rbd_id => { fixed => 1 }, username => { fixed => 1 },
rbd_key => { fixed => 1 }, authsupported => { fixed => 1 },
rbd_authsupported => { fixed => 1 },
content => { optional => 1 }, content => { optional => 1 },
}; };
} }
@ -118,17 +113,16 @@ sub parse_volname {
} }
sub path { sub path {
my ($class, $scfg, $volname) = @_; my ($class, $scfg, $volname, $storeid) = @_;
my ($vtype, $name, $vmid) = $class->parse_volname($volname); my ($vtype, $name, $vmid) = $class->parse_volname($volname);
my $monhost = addslashes($scfg->{rbd_monhost}); my $monhost = addslashes($scfg->{monhost});
my $pool = $scfg->{rbd_pool}; my $pool = $scfg->{pool};
my $id = $scfg->{rbd_id}; my $username = $scfg->{username};
my $key = $scfg->{rbd_key}; my $authsupported = addslashes($scfg->{authsupported});
my $authsupported = addslashes($scfg->{rbd_authsupported});
my $path = "rbd:$pool/$name:id=$id:key=$key:auth_supported=$authsupported:mon_host=$monhost"; my $path = "rbd:$pool/$name:id=$username:auth_supported=$authsupported:keyfile=/etc/pve/priv/ceph/$storeid.$username.key:mon_host=$monhost";
return ($path, $vmid, $vtype); return ($path, $vmid, $vtype);
} }
@ -139,12 +133,12 @@ sub alloc_image {
die "illegal name '$name' - sould be 'vm-$vmid-*'\n" die "illegal name '$name' - sould be 'vm-$vmid-*'\n"
if $name && $name !~ m/^vm-$vmid-/; if $name && $name !~ m/^vm-$vmid-/;
my $rbdpool = $scfg->{rbd_pool}; my $rbdpool = $scfg->{pool};
my $monhost = $scfg->{rbd_monhost}; my $monhost = $scfg->{monhost};
$monhost =~ s/;/,/g; $monhost =~ s/;/,/g;
if (!$name) { if (!$name) {
my $rdb = rbd_ls($scfg); my $rdb = rbd_ls($scfg, $storeid);
for (my $i = 1; $i < 100; $i++) { for (my $i = 1; $i < 100; $i++) {
my $tn = "vm-$vmid-disk-$i"; my $tn = "vm-$vmid-disk-$i";
@ -158,7 +152,7 @@ sub alloc_image {
die "unable to allocate an image name for VM $vmid in storage '$storeid'\n" die "unable to allocate an image name for VM $vmid in storage '$storeid'\n"
if !$name; if !$name;
my $cmd = ['/usr/bin/rbd', '-p', $rbdpool, '-m', $monhost, '-n', "client.".$scfg->{rbd_id}, '--key', $scfg->{rbd_key}, 'create', '--size', ($size/1024), $name ]; my $cmd = ['/usr/bin/rbd', '-p', $rbdpool, '-m', $monhost, '-n', "client.".$scfg->{username}, '--keyfile','/etc/pve/priv/ceph/'.$storeid.'.'.$scfg->{username}.'.key','--auth_supported', $scfg->{authsupported}, 'create', '--size', ($size/1024), $name ];
run_command($cmd, errmsg => "rbd create $name' error"); run_command($cmd, errmsg => "rbd create $name' error");
return $name; return $name;
@ -167,11 +161,11 @@ sub alloc_image {
sub free_image { sub free_image {
my ($class, $storeid, $scfg, $volname) = @_; my ($class, $storeid, $scfg, $volname) = @_;
my $rbdpool = $scfg->{rbd_pool}; my $rbdpool = $scfg->{pool};
my $monhost = $scfg->{rbd_monhost}; my $monhost = $scfg->{monhost};
$monhost =~ s/;/,/g; $monhost =~ s/;/,/g;
my $cmd = ['/usr/bin/rbd', '-p', $rbdpool, '-m', $monhost, '-n', "client.".$scfg->{rbd_id}, '--key',$scfg->{rbd_key}, 'rm', $volname ]; my $cmd = ['/usr/bin/rbd', '-p', $rbdpool, '-m', $monhost, '-n', "client.".$scfg->{username}, '--keyfile','/etc/pve/priv/ceph/'.$storeid.'.'.$scfg->{username}.'.key','--auth_supported',$scfg->{authsupported}, 'rm', $volname ];
run_command($cmd, errmsg => "rbd rm $volname' error"); run_command($cmd, errmsg => "rbd rm $volname' error");
return undef; return undef;
@ -180,8 +174,8 @@ sub free_image {
sub list_images { sub list_images {
my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_; my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
$cache->{rbd} = rbd_ls($scfg) if !$cache->{rbd}; $cache->{rbd} = rbd_ls($scfg, $storeid) if !$cache->{rbd};
my $rbdpool = $scfg->{rbd_pool}; my $rbdpool = $scfg->{pool};
my $res = []; my $res = [];
if (my $dat = $cache->{rbd}->{$rbdpool}) { if (my $dat = $cache->{rbd}->{$rbdpool}) {
@ -214,7 +208,6 @@ sub list_images {
sub status { sub status {
my ($class, $storeid, $scfg, $cache) = @_; my ($class, $storeid, $scfg, $cache) = @_;
my $total = 0; my $total = 0;
my $free = 0; my $free = 0;
my $used = 0; my $used = 0;