1 package PVE
::Storage
::PBSPlugin
;
3 # Plugin to access Proxmox Backup Server
8 use Fcntl
qw(F_GETFD F_SETFD FD_CLOEXEC);
11 use MIME
::Base64
qw(decode_base64);
12 use POSIX
qw(mktime strftime ENOENT);
15 use PVE
::APIClient
::LWP
;
16 use PVE
::JSONSchema
qw(get_standard_option);
19 use PVE
::Storage
::Plugin
;
20 use PVE
::Tools
qw(run_command file_read_firstline trim dir_glob_regex dir_glob_foreach $IPV6RE);
22 use base
qw(PVE::Storage::Plugin);
32 content
=> [ {backup
=> 1, none
=> 1}, { backup
=> 1 }],
39 description
=> "Proxmox Backup Server datastore name.",
42 # openssl s_client -connect <host>:8007 2>&1 |openssl x509 -fingerprint -sha256
43 fingerprint
=> get_standard_option
('fingerprint-sha256'),
45 description
=> "Encryption key. Use 'autogen' to generate one automatically without passphrase.",
49 description
=> "Base64-encoded, PEM-formatted public RSA key. Used to encrypt a copy of the encryption-key which will be added to each encrypted backup.",
53 description
=> "For non default port.",
64 server
=> { fixed
=> 1 },
65 datastore
=> { fixed
=> 1 },
66 namespace
=> { optional
=> 1 },
67 port
=> { optional
=> 1 },
68 nodes
=> { optional
=> 1},
69 disable
=> { optional
=> 1},
70 content
=> { optional
=> 1},
71 username
=> { optional
=> 1 },
72 password
=> { optional
=> 1 },
73 'encryption-key' => { optional
=> 1 },
74 'master-pubkey' => { optional
=> 1 },
75 maxfiles
=> { optional
=> 1 },
76 'prune-backups' => { optional
=> 1 },
77 'max-protected-backups' => { optional
=> 1 },
78 fingerprint
=> { optional
=> 1 },
84 sub pbs_password_file_name
{
85 my ($scfg, $storeid) = @_;
87 return "/etc/pve/priv/storage/${storeid}.pw";
90 sub pbs_set_password
{
91 my ($scfg, $storeid, $password) = @_;
93 my $pwfile = pbs_password_file_name
($scfg, $storeid);
94 mkdir "/etc/pve/priv/storage";
96 PVE
::Tools
::file_set_contents
($pwfile, "$password\n");
99 sub pbs_delete_password
{
100 my ($scfg, $storeid) = @_;
102 my $pwfile = pbs_password_file_name
($scfg, $storeid);
107 sub pbs_get_password
{
108 my ($scfg, $storeid) = @_;
110 my $pwfile = pbs_password_file_name
($scfg, $storeid);
112 return PVE
::Tools
::file_read_firstline
($pwfile);
115 sub pbs_encryption_key_file_name
{
116 my ($scfg, $storeid) = @_;
118 return "/etc/pve/priv/storage/${storeid}.enc";
121 sub pbs_set_encryption_key
{
122 my ($scfg, $storeid, $key) = @_;
124 my $pwfile = pbs_encryption_key_file_name
($scfg, $storeid);
125 mkdir "/etc/pve/priv/storage";
127 PVE
::Tools
::file_set_contents
($pwfile, "$key\n");
130 sub pbs_delete_encryption_key
{
131 my ($scfg, $storeid) = @_;
133 my $pwfile = pbs_encryption_key_file_name
($scfg, $storeid);
135 if (!unlink $pwfile) {
136 return if $! == ENOENT
;
137 die "failed to delete encryption key! $!\n";
139 delete $scfg->{'encryption-key'};
142 sub pbs_get_encryption_key
{
143 my ($scfg, $storeid) = @_;
145 my $pwfile = pbs_encryption_key_file_name
($scfg, $storeid);
147 return PVE
::Tools
::file_get_contents
($pwfile);
150 # Returns a file handle if there is an encryption key, or `undef` if there is not. Dies on error.
151 sub pbs_open_encryption_key
{
152 my ($scfg, $storeid) = @_;
154 my $encryption_key_file = pbs_encryption_key_file_name
($scfg, $storeid);
157 if (!open($keyfd, '<', $encryption_key_file)) {
159 my $encryption_fp = $scfg->{'encryption-key'};
160 die "encryption configured ('$encryption_fp') but no encryption key file found!\n"
164 die "failed to open encryption key: $encryption_key_file: $!\n";
170 sub pbs_master_pubkey_file_name
{
171 my ($scfg, $storeid) = @_;
173 return "/etc/pve/priv/storage/${storeid}.master.pem";
176 sub pbs_set_master_pubkey
{
177 my ($scfg, $storeid, $key) = @_;
179 my $pwfile = pbs_master_pubkey_file_name
($scfg, $storeid);
180 mkdir "/etc/pve/priv/storage";
182 PVE
::Tools
::file_set_contents
($pwfile, "$key\n");
185 sub pbs_delete_master_pubkey
{
186 my ($scfg, $storeid) = @_;
188 my $pwfile = pbs_master_pubkey_file_name
($scfg, $storeid);
190 if (!unlink $pwfile) {
191 return if $! == ENOENT
;
192 die "failed to delete master public key! $!\n";
194 delete $scfg->{'master-pubkey'};
197 sub pbs_get_master_pubkey
{
198 my ($scfg, $storeid) = @_;
200 my $pwfile = pbs_master_pubkey_file_name
($scfg, $storeid);
202 return PVE
::Tools
::file_get_contents
($pwfile);
205 # Returns a file handle if there is a master key, or `undef` if there is not. Dies on error.
206 sub pbs_open_master_pubkey
{
207 my ($scfg, $storeid) = @_;
209 my $master_pubkey_file = pbs_master_pubkey_file_name
($scfg, $storeid);
212 if (!open($keyfd, '<', $master_pubkey_file)) {
213 return undef if $! == ENOENT
;
214 die "failed to open master public key: $master_pubkey_file: $!\n";
221 my ($storeid, $btype, $bid, $btime) = @_;
223 my $time_str = strftime
("%FT%TZ", gmtime($btime));
224 my $volname = "backup/${btype}/${bid}/${time_str}";
226 return "${storeid}:${volname}";
229 my sub ns
: prototype($$) {
230 my ($scfg, $name) = @_;
231 my $ns = $scfg->{namespace
};
232 return defined($ns) ?
($name, $ns) : ();
235 # essentially the inverse of print_volid
236 my sub api_param_from_volname
: prototype($$$) {
237 my ($class, $scfg, $volname) = @_;
239 my $name = ($class->parse_volname($volname))[1];
241 my ($btype, $bid, $timestr) = split('/', $name);
243 my @tm = (POSIX
::strptime
($timestr, "%FT%TZ"));
244 # expect sec, min, hour, mday, mon, year
245 die "error parsing time from '$volname'" if grep { !defined($_) } @tm[0..5];
249 local $ENV{TZ
} = 'UTC'; # $timestr is UTC
251 # Fill in isdst to avoid undef warning. No daylight saving time for UTC.
254 my $since_epoch = mktime
(@tm) or die "error converting time from '$volname'\n";
255 $btime = int($since_epoch);
260 'backup-type' => $btype,
262 'backup-time' => $btime,
266 my $USE_CRYPT_PARAMS = {
272 my $USE_MASTER_KEY = {
276 my sub do_raw_client_cmd
{
277 my ($scfg, $storeid, $client_cmd, $param, %opts) = @_;
279 my $use_crypto = $USE_CRYPT_PARAMS->{$client_cmd};
280 my $use_master = $USE_MASTER_KEY->{$client_cmd};
282 my $client_exe = '/usr/bin/proxmox-backup-client';
283 die "executable not found '$client_exe'! Proxmox backup client not installed?\n"
286 my $repo = PVE
::PBSClient
::get_repository
($scfg);
288 my $userns_cmd = delete $opts{userns_cmd
};
292 push @$cmd, @$userns_cmd if defined($userns_cmd);
294 push @$cmd, $client_exe, $client_cmd;
296 # This must live in the top scope to not get closed before the `run_command`
297 my ($keyfd, $master_fd);
299 if (defined($keyfd = pbs_open_encryption_key
($scfg, $storeid))) {
300 my $flags = fcntl($keyfd, F_GETFD
, 0)
301 // die "failed to get file descriptor flags: $!\n";
302 fcntl($keyfd, F_SETFD
, $flags & ~FD_CLOEXEC
)
303 or die "failed to remove FD_CLOEXEC from encryption key file descriptor\n";
304 push @$cmd, '--crypt-mode=encrypt', '--keyfd='.fileno($keyfd);
305 if ($use_master && defined($master_fd = pbs_open_master_pubkey
($scfg, $storeid))) {
306 my $flags = fcntl($master_fd, F_GETFD
, 0)
307 // die "failed to get file descriptor flags: $!\n";
308 fcntl($master_fd, F_SETFD
, $flags & ~FD_CLOEXEC
)
309 or die "failed to remove FD_CLOEXEC from master public key file descriptor\n";
310 push @$cmd, '--master-pubkey-fd='.fileno($master_fd);
313 push @$cmd, '--crypt-mode=none';
317 push @$cmd, @$param if defined($param);
319 push @$cmd, "--repository", $repo;
320 if ($client_cmd ne 'status' && defined(my $ns = $scfg->{namespace
})) {
321 push @$cmd, '--ns', $ns;
324 local $ENV{PBS_PASSWORD
} = pbs_get_password
($scfg, $storeid);
326 local $ENV{PBS_FINGERPRINT
} = $scfg->{fingerprint
};
328 # no ascii-art on task logs
329 local $ENV{PROXMOX_OUTPUT_NO_BORDER
} = 1;
330 local $ENV{PROXMOX_OUTPUT_NO_HEADER
} = 1;
332 if (my $logfunc = $opts{logfunc
}) {
333 $logfunc->("run: " . join(' ', @$cmd));
336 run_command
($cmd, %opts);
339 # FIXME: External perl code should NOT have access to this.
341 # There should be separate functions to
346 sub run_raw_client_cmd
{
347 my ($scfg, $storeid, $client_cmd, $param, %opts) = @_;
348 return do_raw_client_cmd
($scfg, $storeid, $client_cmd, $param, %opts);
352 my ($scfg, $storeid, $client_cmd, $param, $no_output) = @_;
355 my $outfunc = sub { $json_str .= "$_[0]\n" };
357 $param = [] if !defined($param);
358 $param = [ $param ] if !ref($param);
360 $param = [@$param, '--output-format=json'] if !$no_output;
362 do_raw_client_cmd
($scfg, $storeid, $client_cmd, $param,
363 outfunc
=> $outfunc, errmsg
=> 'proxmox-backup-client failed');
365 return undef if $no_output;
367 my $res = decode_json
($json_str);
372 # Storage implementation
374 sub extract_vzdump_config
{
375 my ($class, $scfg, $volname, $storeid) = @_;
377 my ($vtype, $name, $vmid, undef, undef, undef, $format) = $class->parse_volname($volname);
380 my $outfunc = sub { $config .= "$_[0]\n" };
383 if ($format eq 'pbs-vm') {
384 $config_name = 'qemu-server.conf';
385 } elsif ($format eq 'pbs-ct') {
386 $config_name = 'pct.conf';
388 die "unable to extract configuration for backup format '$format'\n";
391 do_raw_client_cmd
($scfg, $storeid, 'restore', [ $name, $config_name, '-' ],
392 outfunc
=> $outfunc, errmsg
=> 'proxmox-backup-client failed');
398 my ($class, $scfg, $storeid, $keep, $vmid, $type, $dryrun, $logfunc) = @_;
400 $logfunc //= sub { print "$_[1]\n" };
402 my $backups = $class->list_volumes($storeid, $scfg, $vmid, ['backup']);
404 $type = 'vm' if defined($type) && $type eq 'qemu';
405 $type = 'ct' if defined($type) && $type eq 'lxc';
407 my $backup_groups = {};
408 foreach my $backup (@{$backups}) {
409 (my $backup_type = $backup->{format
}) =~ s/^pbs-//;
411 next if defined($type) && $backup_type ne $type;
413 my $backup_group = "$backup_type/$backup->{vmid}";
414 $backup_groups->{$backup_group} = 1;
419 my $keep_all = delete $keep->{'keep-all'};
422 foreach my $opt (keys %{$keep}) {
423 next if $keep->{$opt} == 0;
424 push @param, "--$opt";
425 push @param, "$keep->{$opt}";
427 } else { # no need to pass anything to PBS
428 $keep = { 'keep-all' => 1 };
431 push @param, '--dry-run' if $dryrun;
436 foreach my $backup_group (keys %{$backup_groups}) {
437 $logfunc->('info', "running 'proxmox-backup-client prune' for '$backup_group'")
440 my $res = run_client_cmd
($scfg, $storeid, 'prune', [ $backup_group, @param ]);
442 foreach my $backup (@{$res}) {
443 die "result from proxmox-backup-client is not as expected\n"
444 if !defined($backup->{'backup-time'})
445 || !defined($backup->{'backup-type'})
446 || !defined($backup->{'backup-id'})
447 || !defined($backup->{'keep'});
449 my $ctime = $backup->{'backup-time'};
450 my $type = $backup->{'backup-type'};
451 my $vmid = $backup->{'backup-id'};
452 my $volid = print_volid
($storeid, $type, $vmid, $ctime);
454 my $mark = $backup->{keep
} ?
'keep' : 'remove';
455 $mark = 'protected' if $backup->{protected
};
457 push @{$prune_list}, {
460 type
=> $type eq 'vm' ?
'qemu' : 'lxc',
467 $logfunc->('err', "prune '$backup_group': $err\n");
471 die "error pruning backups - check log\n" if $failed;
476 my $autogen_encryption_key = sub {
477 my ($scfg, $storeid) = @_;
478 my $encfile = pbs_encryption_key_file_name
($scfg, $storeid);
480 rename $encfile, "$encfile.old";
482 my $cmd = ['proxmox-backup-client', 'key', 'create', '--kdf', 'none', $encfile];
483 run_command
($cmd, errmsg
=> 'failed to create encryption key');
484 return PVE
::Tools
::file_get_contents
($encfile);
488 my ($class, $storeid, $scfg, %param) = @_;
492 if (defined(my $password = $param{password
})) {
493 pbs_set_password
($scfg, $storeid, $password);
495 pbs_delete_password
($scfg, $storeid);
498 if (defined(my $encryption_key = $param{'encryption-key'})) {
500 if ($encryption_key eq 'autogen') {
501 $res->{'encryption-key'} = $autogen_encryption_key->($scfg, $storeid);
502 $decoded_key = decode_json
($res->{'encryption-key'});
504 $decoded_key = eval { decode_json
($encryption_key) };
505 if ($@ || !exists($decoded_key->{data
})) {
506 die "Value does not seems like a valid, JSON formatted encryption key!\n";
508 pbs_set_encryption_key
($scfg, $storeid, $encryption_key);
509 $res->{'encryption-key'} = $encryption_key;
511 $scfg->{'encryption-key'} = $decoded_key->{fingerprint
} || 1;
513 pbs_delete_encryption_key
($scfg, $storeid);
516 if (defined(my $master_key = delete $param{'master-pubkey'})) {
517 die "'master-pubkey' can only be used together with 'encryption-key'\n"
518 if !defined($scfg->{'encryption-key'});
520 my $decoded = decode_base64
($master_key);
521 pbs_set_master_pubkey
($scfg, $storeid, $decoded);
522 $scfg->{'master-pubkey'} = 1;
524 pbs_delete_master_pubkey
($scfg, $storeid);
531 my ($class, $storeid, $scfg, %param) = @_;
535 if (exists($param{password
})) {
536 if (defined($param{password
})) {
537 pbs_set_password
($scfg, $storeid, $param{password
});
539 pbs_delete_password
($scfg, $storeid);
543 if (exists($param{'encryption-key'})) {
544 if (defined(my $encryption_key = delete($param{'encryption-key'}))) {
546 if ($encryption_key eq 'autogen') {
547 $res->{'encryption-key'} = $autogen_encryption_key->($scfg, $storeid);
548 $decoded_key = decode_json
($res->{'encryption-key'});
550 $decoded_key = eval { decode_json
($encryption_key) };
551 if ($@ || !exists($decoded_key->{data
})) {
552 die "Value does not seems like a valid, JSON formatted encryption key!\n";
554 pbs_set_encryption_key
($scfg, $storeid, $encryption_key);
555 $res->{'encryption-key'} = $encryption_key;
557 $scfg->{'encryption-key'} = $decoded_key->{fingerprint
} || 1;
559 pbs_delete_encryption_key
($scfg, $storeid);
560 delete $scfg->{'encryption-key'};
564 if (exists($param{'master-pubkey'})) {
565 if (defined(my $master_key = delete($param{'master-pubkey'}))) {
566 my $decoded = decode_base64
($master_key);
568 pbs_set_master_pubkey
($scfg, $storeid, $decoded);
569 $scfg->{'master-pubkey'} = 1;
571 pbs_delete_master_pubkey
($scfg, $storeid);
579 my ($class, $storeid, $scfg) = @_;
581 pbs_delete_password
($scfg, $storeid);
582 pbs_delete_encryption_key
($scfg, $storeid);
583 pbs_delete_master_pubkey
($scfg, $storeid);
589 my ($class, $volname) = @_;
591 if ($volname =~ m!^backup/([^\s_]+)/([^\s_]+)/([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z)$!) {
595 my $format = "pbs-$btype";
597 my $name = "$btype/$bid/$btime";
599 if ($bid =~ m/^\d+$/) {
600 return ('backup', $name, $bid, undef, undef, undef, $format);
602 return ('backup', $name, undef, undef, undef, undef, $format);
606 die "unable to parse PBS volume name '$volname'\n";
610 my ($class, $scfg, $volname, $storeid, $snapname) = @_;
612 die "volume snapshot is not possible on pbs storage"
613 if defined($snapname);
615 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
617 my $repo = PVE
::PBSClient
::get_repository
($scfg);
619 # artificial url - we currently do not use that anywhere
620 my $path = "pbs://$repo/$name";
621 if (defined(my $ns = $scfg->{namespace
})) {
622 $ns =~ s
|/|%2f|g
; # other characters to escape aren't allowed in the namespace schema
626 return ($path, $vmid, $vtype);
630 my ($class, $storeid, $scfg, $volname) = @_;
632 die "can't create base images in pbs storage\n";
636 my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
638 die "can't clone images in pbs storage\n";
642 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
644 die "can't allocate space in pbs storage\n";
648 my ($class, $storeid, $scfg, $volname, $isBase) = @_;
650 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
652 run_client_cmd
($scfg, $storeid, "forget", [ $name ], 1);
659 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
666 my sub snapshot_files_encrypted
{
672 for my $file (@$files) {
673 my $fn = $file->{filename
};
674 next if $fn eq 'client.log.blob' || $fn eq 'index.json.blob';
676 my $crypt = $file->{'crypt-mode'};
678 $all = 0 if !$crypt || $crypt ne 'encrypt';
679 $any ||= defined($crypt) && $crypt eq 'encrypt';
684 # TODO: use a client with native rust/proxmox-backup bindings to profit from
685 # API schema checks and types
686 my sub pbs_api_connect
{
687 my ($scfg, $password) = @_;
691 my $user = $scfg->{username
} // 'root@pam';
693 if (my $tokenid = PVE
::AccessControl
::pve_verify_tokenid
($user, 1)) {
694 $params->{apitoken
} = "PBSAPIToken=${tokenid}:${password}";
696 $params->{password
} = $password;
697 $params->{username
} = $user;
700 if (my $fp = $scfg->{fingerprint
}) {
701 $params->{cached_fingerprints
}->{uc($fp)} = 1;
704 my $conn = PVE
::APIClient
::LWP-
>new(
706 host
=> $scfg->{server
},
707 port
=> $scfg->{port
} // 8007,
708 timeout
=> 7, # cope with a 401 (3s api delay) and high latency
709 cookie_name
=> 'PBSAuthCookie',
716 my ($class, $storeid, $scfg, $vmid, $content_types) = @_;
720 return $res if !grep { $_ eq 'backup' } @$content_types;
722 my $password = pbs_get_password
($scfg, $storeid);
723 my $conn = pbs_api_connect
($scfg, $password);
724 my $datastore = $scfg->{datastore
};
727 $param->{'backup-id'} = "$vmid" if defined($vmid);
728 $param->{'ns'} = "$scfg->{namespace}" if defined($scfg->{namespace
});
729 my $data = eval { $conn->get("/api2/json/admin/datastore/$datastore/snapshots", $param); };
730 die "error listing snapshots - $@" if $@;
732 foreach my $item (@$data) {
733 my $btype = $item->{"backup-type"};
734 my $bid = $item->{"backup-id"};
735 my $epoch = $item->{"backup-time"};
736 my $size = $item->{size
} // 1;
738 next if !($btype eq 'vm' || $btype eq 'ct');
739 next if $bid !~ m/^\d+$/;
740 next if defined($vmid) && $bid ne $vmid;
742 my $volid = print_volid
($storeid, $btype, $bid, $epoch);
746 format
=> "pbs-$btype",
751 subtype
=> $btype eq 'vm' ?
'qemu' : 'lxc', # convert to PVE backup type
754 $info->{verification
} = $item->{verification
} if defined($item->{verification
});
755 $info->{notes
} = $item->{comment
} if defined($item->{comment
});
756 $info->{protected
} = 1 if $item->{protected
};
757 if (defined($item->{fingerprint
})) {
758 $info->{encrypted
} = $item->{fingerprint
};
759 } elsif (snapshot_files_encrypted
($item->{files
})) {
760 $info->{encrypted
} = '1';
770 my ($class, $storeid, $scfg, $cache) = @_;
778 my $res = run_client_cmd
($scfg, $storeid, "status");
781 $total = $res->{total
};
782 $used = $res->{used
};
783 $free = $res->{avail
};
789 return ($total, $free, $used, $active);
792 # can also be used for not (yet) added storages, pass $scfg with
796 # port (optional default to 8007)
797 # fingerprint (optional for trusted certs)
799 sub scan_datastores
{
800 my ($scfg, $password) = @_;
802 my $conn = pbs_api_connect
($scfg, $password);
804 my $response = eval { $conn->get('/api2/json/admin/datastore', {}) };
805 die "error fetching datastores - $@" if $@;
810 sub activate_storage
{
811 my ($class, $storeid, $scfg, $cache) = @_;
813 my $password = pbs_get_password
($scfg, $storeid);
815 my $datastores = eval { scan_datastores
($scfg, $password) };
816 die "$storeid: $@" if $@;
818 my $datastore = $scfg->{datastore
};
820 for my $ds (@$datastores) {
821 if ($ds->{store
} eq $datastore) {
826 die "$storeid: Cannot find datastore '$datastore', check permissions and existence!\n";
829 sub deactivate_storage
{
830 my ($class, $storeid, $scfg, $cache) = @_;
834 sub activate_volume
{
835 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
837 die "volume snapshot is not possible on pbs device" if $snapname;
842 sub deactivate_volume
{
843 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
845 die "volume snapshot is not possible on pbs device" if $snapname;
850 # FIXME remove on the next APIAGE reset.
851 # Deprecated, use get_volume_attribute instead.
852 sub get_volume_notes
{
853 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
855 my (undef, $name, undef, undef, undef, undef, $format) = $class->parse_volname($volname);
857 my $data = run_client_cmd
($scfg, $storeid, "snapshot", [ "notes", "show", $name ]);
859 return $data->{notes
};
862 # FIXME remove on the next APIAGE reset.
863 # Deprecated, use update_volume_attribute instead.
864 sub update_volume_notes
{
865 my ($class, $scfg, $storeid, $volname, $notes, $timeout) = @_;
867 my (undef, $name, undef, undef, undef, undef, $format) = $class->parse_volname($volname);
869 run_client_cmd
($scfg, $storeid, "snapshot", [ "notes", "update", $name, $notes ], 1);
874 sub get_volume_attribute
{
875 my ($class, $scfg, $storeid, $volname, $attribute) = @_;
877 if ($attribute eq 'notes') {
878 return $class->get_volume_notes($scfg, $storeid, $volname);
881 if ($attribute eq 'protected') {
882 my $param = api_param_from_volname
($class, $scfg, $volname);
884 my $password = pbs_get_password
($scfg, $storeid);
885 my $conn = pbs_api_connect
($scfg, $password);
886 my $datastore = $scfg->{datastore
};
888 my $res = eval { $conn->get("/api2/json/admin/datastore/$datastore/$attribute", $param); };
890 return if $err->{code
} == 404; # not supported
899 sub update_volume_attribute
{
900 my ($class, $scfg, $storeid, $volname, $attribute, $value) = @_;
902 if ($attribute eq 'notes') {
903 return $class->update_volume_notes($scfg, $storeid, $volname, $value);
906 if ($attribute eq 'protected') {
907 my $param = api_param_from_volname
($class, $scfg, $volname);
908 $param->{$attribute} = $value;
910 my $password = pbs_get_password
($scfg, $storeid);
911 my $conn = pbs_api_connect
($scfg, $password);
912 my $datastore = $scfg->{datastore
};
914 eval { $conn->put("/api2/json/admin/datastore/$datastore/$attribute", $param); };
916 die "Server is not recent enough to support feature '$attribute'\n"
917 if $err->{code
} == 404;
923 die "attribute '$attribute' is not supported for storage type '$scfg->{type}'\n";
926 sub volume_size_info
{
927 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
929 my ($vtype, $name, undef, undef, undef, undef, $format) = $class->parse_volname($volname);
931 my $data = run_client_cmd
($scfg, $storeid, "files", [ $name ]);
934 foreach my $info (@$data) {
935 if ($info->{size
} && $info->{size
} =~ /^(\d+)$/) { # untaints
942 return wantarray ?
($size, $format, $used, undef) : $size;
946 my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
947 die "volume resize is not possible on pbs device";
950 sub volume_snapshot
{
951 my ($class, $scfg, $storeid, $volname, $snap) = @_;
952 die "volume snapshot is not possible on pbs device";
955 sub volume_snapshot_rollback
{
956 my ($class, $scfg, $storeid, $volname, $snap) = @_;
957 die "volume snapshot rollback is not possible on pbs device";
960 sub volume_snapshot_delete
{
961 my ($class, $scfg, $storeid, $volname, $snap) = @_;
962 die "volume snapshot delete is not possible on pbs device";
965 sub volume_has_feature
{
966 my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running) = @_;