sheepdog: use '-r' to get sizes in bytes, code cleanup
Use a common method collie_cmd() to assemble command using correct server/port settings.
This commit is contained in:
@ -9,21 +9,30 @@ use PVE::JSONSchema qw(get_standard_option);
|
|||||||
|
|
||||||
use base qw(PVE::Storage::Plugin);
|
use base qw(PVE::Storage::Plugin);
|
||||||
|
|
||||||
|
my $collie_cmd = sub {
|
||||||
sub sheepdog_ls{
|
my ($scfg, $class, $op, @options) = @_;
|
||||||
my ($scfg, $storeid) = @_;
|
|
||||||
|
|
||||||
my $portal = $scfg->{portal};
|
my $portal = $scfg->{portal};
|
||||||
my ($server, $port) = split(':', $portal);
|
my ($server, $port) = split(':', $portal);
|
||||||
my $cmd = ['/usr/sbin/collie', 'vdi', 'list', '-a', $server ];
|
my $cmd = ['/usr/sbin/collie', $class, $op, '-a', $server];
|
||||||
|
push @$cmd, '-p', $port if $port;
|
||||||
|
|
||||||
|
push @$cmd, @options if scalar(@options);
|
||||||
|
|
||||||
|
return $cmd;
|
||||||
|
};
|
||||||
|
|
||||||
|
sub sheepdog_ls {
|
||||||
|
my ($scfg, $storeid) = @_;
|
||||||
|
|
||||||
|
my $cmd = &$collie_cmd($scfg, 'vdi', 'list', '-r');
|
||||||
|
|
||||||
my $list = {};
|
my $list = {};
|
||||||
|
|
||||||
|
run_command($cmd, outfunc => sub {
|
||||||
run_command($cmd,outfunc => sub {
|
|
||||||
my $line = shift;
|
my $line = shift;
|
||||||
$line = trim($line);
|
$line = trim($line);
|
||||||
if( $line =~ /(vm-(\d+)-\S+)\s+(\d+)\s+([\.0-9]*)\s(\w+)\s+([\.0-9]*)\s(\w+)\W+([\.0-9]*)\s(\w+)\s+([\-0-9]*)\s([:0-9]*)\W+/ ) {
|
if ($line =~ /= (vm-(\d+)-\S+)\s+(\d+)\s+(\d+)\s(\d+)\s(\d+)\s/) {
|
||||||
|
|
||||||
my $image = $1;
|
my $image = $1;
|
||||||
my $owner = $2;
|
my $owner = $2;
|
||||||
my $size = $4;
|
my $size = $4;
|
||||||
@ -33,14 +42,10 @@ sub sheepdog_ls{
|
|||||||
size => $size,
|
size => $size,
|
||||||
vmid => $owner
|
vmid => $owner
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return $list;
|
return $list;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
@ -94,8 +99,6 @@ 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 $portal = $scfg->{portal};
|
|
||||||
my ($server, $port) = split(':', $portal);
|
|
||||||
|
|
||||||
if (!$name) {
|
if (!$name) {
|
||||||
my $sheepdog = sheepdog_ls($scfg, $storeid);
|
my $sheepdog = sheepdog_ls($scfg, $storeid);
|
||||||
@ -111,7 +114,9 @@ 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/sbin/collie', 'vdi', 'create' , $name , $size.'KB', '-a', $server ];
|
|
||||||
|
my $cmd = &$collie_cmd($scfg, 'vdi', 'create', $name , "${size}KB");
|
||||||
|
|
||||||
run_command($cmd, errmsg => "sheepdog create $name' error");
|
run_command($cmd, errmsg => "sheepdog create $name' error");
|
||||||
|
|
||||||
return $name;
|
return $name;
|
||||||
@ -120,10 +125,7 @@ sub alloc_image {
|
|||||||
sub free_image {
|
sub free_image {
|
||||||
my ($class, $storeid, $scfg, $volname) = @_;
|
my ($class, $storeid, $scfg, $volname) = @_;
|
||||||
|
|
||||||
my $portal = $scfg->{portal};
|
my $cmd = &$collie_cmd($scfg, 'vdi', 'delete' , $volname);
|
||||||
my ($server, $port) = split(':', $portal);
|
|
||||||
|
|
||||||
my $cmd = ['/usr/sbin/collie', 'vdi', 'delete' , $volname, '-a', $server ];
|
|
||||||
|
|
||||||
run_command($cmd, errmsg => "sheepdog delete $volname' error");
|
run_command($cmd, errmsg => "sheepdog delete $volname' error");
|
||||||
|
|
||||||
@ -154,7 +156,7 @@ sub list_images {
|
|||||||
|
|
||||||
my $info = $dat->{$volname};
|
my $info = $dat->{$volname};
|
||||||
$info->{volid} = $volid;
|
$info->{volid} = $volid;
|
||||||
|
$info->{format} = 'raw';
|
||||||
push @$res, $info;
|
push @$res, $info;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user