]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/SheepdogPlugin.pm
1 package PVE
::Storage
::SheepdogPlugin
;
6 use PVE
::Tools
qw(run_command trim);
7 use PVE
::Storage
::Plugin
;
8 use PVE
::JSONSchema
qw(get_standard_option);
10 use base
qw(PVE::Storage::Plugin);
12 my $collie_cmd = sub {
13 my ($scfg, $class, $op, @options) = @_;
15 my $portal = $scfg->{portal
};
16 my ($server, $port) = split(':', $portal);
17 my $cmd = ['/usr/sbin/collie', $class, $op, '-a', $server];
18 push @$cmd, '-p', $port if $port;
20 push @$cmd, @options if scalar(@options);
26 my ($scfg, $storeid) = @_;
28 my $cmd = &$collie_cmd($scfg, 'vdi', 'list', '-r');
32 run_command
($cmd, outfunc
=> sub {
35 if ($line =~ /= (vm-(\d+)-\S+)\s+(\d+)\s+(\d+)\s(\d+)\s(\d+)\s/) {
40 $list->{$storeid}->{$image} = {
60 content
=> [ {images
=> 1}, { images
=> 1 }],
67 portal
=> { fixed
=> 1 },
68 content
=> { optional
=> 1 },
72 # Storage implementation
75 my ($class, $volname) = @_;
77 if ($volname =~ m/^(vm-(\d+)-\S+)$/) {
78 return ('images', $1, $2);
81 die "unable to parse rbd volume name '$volname'\n";
85 my ($class, $scfg, $volname, $storeid) = @_;
87 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
89 my $portal = $scfg->{portal
};
90 my ($server, $port) = split(':', $portal);
91 $port = 7000 if !$port;
93 my $path = "sheepdog:$server:$port:$name";
95 return ($path, $vmid, $vtype);
99 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
102 die "illegal name '$name' - sould be 'vm-$vmid-*'\n"
103 if $name && $name !~ m/^vm-$vmid-/;
106 my $sheepdog = sheepdog_ls
($scfg, $storeid);
108 for (my $i = 1; $i < 100; $i++) {
109 my $tn = "vm-$vmid-disk-$i";
110 if (!defined ($sheepdog->{$storeid}->{$tn})) {
117 die "unable to allocate an image name for VM $vmid in storage '$storeid'\n"
120 my $cmd = &$collie_cmd($scfg, 'vdi', 'create', $name , "${size}KB");
122 run_command
($cmd, errmsg
=> "sheepdog create $name' error");
128 my ($class, $storeid, $scfg, $volname) = @_;
130 my $cmd = &$collie_cmd($scfg, 'vdi', 'delete' , $volname);
132 run_command
($cmd, errmsg
=> "sheepdog delete $volname' error");
138 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
140 $cache->{sheepdog
} = sheepdog_ls
($scfg, $storeid) if !$cache->{sheepdog
};
143 if (my $dat = $cache->{sheepdog
}->{$storeid}) {
144 foreach my $image (keys %$dat) {
146 my $volname = $dat->{$image}->{name
};
148 my $volid = "$storeid:$volname";
150 my $owner = $dat->{$volname}->{vmid
};
152 my $found = grep { $_ eq $volid } @$vollist;
155 next if defined ($vmid) && ($owner ne $vmid);
158 my $info = $dat->{$volname};
159 $info->{volid
} = $volid;
160 $info->{format
} = 'raw';
170 my ($class, $storeid, $scfg, $cache) = @_;
177 my $cmd = &$collie_cmd($scfg, 'node', 'info' , '-r');
181 if ($line =~ m/^Total\s(\d+)\s(\d+)\s/) {
184 $free = $total - $used;
188 run_command
($cmd, outfunc
=> $parser, errmsg
=> "sheepdog node info error");
190 return ($total,$free,$used,$active);
195 sub activate_storage
{
196 my ($class, $storeid, $scfg, $cache) = @_;
200 sub deactivate_storage
{
201 my ($class, $storeid, $scfg, $cache) = @_;
205 sub activate_volume
{
206 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
210 sub deactivate_volume
{
211 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;