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)) {
158 return undef if $! == ENOENT
;
159 die "failed to open encryption key: $encryption_key_file: $!\n";
165 sub pbs_master_pubkey_file_name
{
166 my ($scfg, $storeid) = @_;
168 return "/etc/pve/priv/storage/${storeid}.master.pem";
171 sub pbs_set_master_pubkey
{
172 my ($scfg, $storeid, $key) = @_;
174 my $pwfile = pbs_master_pubkey_file_name
($scfg, $storeid);
175 mkdir "/etc/pve/priv/storage";
177 PVE
::Tools
::file_set_contents
($pwfile, "$key\n");
180 sub pbs_delete_master_pubkey
{
181 my ($scfg, $storeid) = @_;
183 my $pwfile = pbs_master_pubkey_file_name
($scfg, $storeid);
185 if (!unlink $pwfile) {
186 return if $! == ENOENT
;
187 die "failed to delete master public key! $!\n";
189 delete $scfg->{'master-pubkey'};
192 sub pbs_get_master_pubkey
{
193 my ($scfg, $storeid) = @_;
195 my $pwfile = pbs_master_pubkey_file_name
($scfg, $storeid);
197 return PVE
::Tools
::file_get_contents
($pwfile);
200 # Returns a file handle if there is a master key, or `undef` if there is not. Dies on error.
201 sub pbs_open_master_pubkey
{
202 my ($scfg, $storeid) = @_;
204 my $master_pubkey_file = pbs_master_pubkey_file_name
($scfg, $storeid);
207 if (!open($keyfd, '<', $master_pubkey_file)) {
208 return undef if $! == ENOENT
;
209 die "failed to open master public key: $master_pubkey_file: $!\n";
216 my ($storeid, $btype, $bid, $btime) = @_;
218 my $time_str = strftime
("%FT%TZ", gmtime($btime));
219 my $volname = "backup/${btype}/${bid}/${time_str}";
221 return "${storeid}:${volname}";
224 my sub ns
: prototype($$) {
225 my ($scfg, $name) = @_;
226 my $ns = $scfg->{namespace
};
227 return defined($ns) ?
($name, $ns) : ();
230 # essentially the inverse of print_volid
231 my sub api_param_from_volname
: prototype($$$) {
232 my ($class, $scfg, $volname) = @_;
234 my $name = ($class->parse_volname($volname))[1];
236 my ($btype, $bid, $timestr) = split('/', $name);
238 my @tm = (POSIX
::strptime
($timestr, "%FT%TZ"));
239 # expect sec, min, hour, mday, mon, year
240 die "error parsing time from '$volname'" if grep { !defined($_) } @tm[0..5];
244 local $ENV{TZ
} = 'UTC'; # $timestr is UTC
246 # Fill in isdst to avoid undef warning. No daylight saving time for UTC.
249 my $since_epoch = mktime
(@tm) or die "error converting time from '$volname'\n";
250 $btime = int($since_epoch);
255 'backup-type' => $btype,
257 'backup-time' => $btime,
261 my $USE_CRYPT_PARAMS = {
267 my $USE_MASTER_KEY = {
271 my sub do_raw_client_cmd
{
272 my ($scfg, $storeid, $client_cmd, $param, %opts) = @_;
274 my $use_crypto = $USE_CRYPT_PARAMS->{$client_cmd};
275 my $use_master = $USE_MASTER_KEY->{$client_cmd};
277 my $client_exe = '/usr/bin/proxmox-backup-client';
278 die "executable not found '$client_exe'! Proxmox backup client not installed?\n"
281 my $repo = PVE
::PBSClient
::get_repository
($scfg);
283 my $userns_cmd = delete $opts{userns_cmd
};
287 push @$cmd, @$userns_cmd if defined($userns_cmd);
289 push @$cmd, $client_exe, $client_cmd;
291 # This must live in the top scope to not get closed before the `run_command`
292 my ($keyfd, $master_fd);
294 if (defined($keyfd = pbs_open_encryption_key
($scfg, $storeid))) {
295 my $flags = fcntl($keyfd, F_GETFD
, 0)
296 // die "failed to get file descriptor flags: $!\n";
297 fcntl($keyfd, F_SETFD
, $flags & ~FD_CLOEXEC
)
298 or die "failed to remove FD_CLOEXEC from encryption key file descriptor\n";
299 push @$cmd, '--crypt-mode=encrypt', '--keyfd='.fileno($keyfd);
300 if ($use_master && defined($master_fd = pbs_open_master_pubkey
($scfg, $storeid))) {
301 my $flags = fcntl($master_fd, F_GETFD
, 0)
302 // die "failed to get file descriptor flags: $!\n";
303 fcntl($master_fd, F_SETFD
, $flags & ~FD_CLOEXEC
)
304 or die "failed to remove FD_CLOEXEC from master public key file descriptor\n";
305 push @$cmd, '--master-pubkey-fd='.fileno($master_fd);
308 push @$cmd, '--crypt-mode=none';
312 push @$cmd, @$param if defined($param);
314 push @$cmd, "--repository", $repo;
315 if ($client_cmd ne 'status' && defined(my $ns = $scfg->{namespace
})) {
316 push @$cmd, '--ns', $ns;
319 local $ENV{PBS_PASSWORD
} = pbs_get_password
($scfg, $storeid);
321 local $ENV{PBS_FINGERPRINT
} = $scfg->{fingerprint
};
323 # no ascii-art on task logs
324 local $ENV{PROXMOX_OUTPUT_NO_BORDER
} = 1;
325 local $ENV{PROXMOX_OUTPUT_NO_HEADER
} = 1;
327 if (my $logfunc = $opts{logfunc
}) {
328 $logfunc->("run: " . join(' ', @$cmd));
331 run_command
($cmd, %opts);
334 # FIXME: External perl code should NOT have access to this.
336 # There should be separate functions to
341 sub run_raw_client_cmd
{
342 my ($scfg, $storeid, $client_cmd, $param, %opts) = @_;
343 return do_raw_client_cmd
($scfg, $storeid, $client_cmd, $param, %opts);
347 my ($scfg, $storeid, $client_cmd, $param, $no_output) = @_;
350 my $outfunc = sub { $json_str .= "$_[0]\n" };
352 $param = [] if !defined($param);
353 $param = [ $param ] if !ref($param);
355 $param = [@$param, '--output-format=json'] if !$no_output;
357 do_raw_client_cmd
($scfg, $storeid, $client_cmd, $param,
358 outfunc
=> $outfunc, errmsg
=> 'proxmox-backup-client failed');
360 return undef if $no_output;
362 my $res = decode_json
($json_str);
367 # Storage implementation
369 sub extract_vzdump_config
{
370 my ($class, $scfg, $volname, $storeid) = @_;
372 my ($vtype, $name, $vmid, undef, undef, undef, $format) = $class->parse_volname($volname);
375 my $outfunc = sub { $config .= "$_[0]\n" };
378 if ($format eq 'pbs-vm') {
379 $config_name = 'qemu-server.conf';
380 } elsif ($format eq 'pbs-ct') {
381 $config_name = 'pct.conf';
383 die "unable to extract configuration for backup format '$format'\n";
386 do_raw_client_cmd
($scfg, $storeid, 'restore', [ $name, $config_name, '-' ],
387 outfunc
=> $outfunc, errmsg
=> 'proxmox-backup-client failed');
393 my ($class, $scfg, $storeid, $keep, $vmid, $type, $dryrun, $logfunc) = @_;
395 $logfunc //= sub { print "$_[1]\n" };
397 my $backups = $class->list_volumes($storeid, $scfg, $vmid, ['backup']);
399 $type = 'vm' if defined($type) && $type eq 'qemu';
400 $type = 'ct' if defined($type) && $type eq 'lxc';
402 my $backup_groups = {};
403 foreach my $backup (@{$backups}) {
404 (my $backup_type = $backup->{format
}) =~ s/^pbs-//;
406 next if defined($type) && $backup_type ne $type;
408 my $backup_group = "$backup_type/$backup->{vmid}";
409 $backup_groups->{$backup_group} = 1;
414 my $keep_all = delete $keep->{'keep-all'};
417 foreach my $opt (keys %{$keep}) {
418 next if $keep->{$opt} == 0;
419 push @param, "--$opt";
420 push @param, "$keep->{$opt}";
422 } else { # no need to pass anything to PBS
423 $keep = { 'keep-all' => 1 };
426 push @param, '--dry-run' if $dryrun;
431 foreach my $backup_group (keys %{$backup_groups}) {
432 $logfunc->('info', "running 'proxmox-backup-client prune' for '$backup_group'")
435 my $res = run_client_cmd
($scfg, $storeid, 'prune', [ $backup_group, @param ]);
437 foreach my $backup (@{$res}) {
438 die "result from proxmox-backup-client is not as expected\n"
439 if !defined($backup->{'backup-time'})
440 || !defined($backup->{'backup-type'})
441 || !defined($backup->{'backup-id'})
442 || !defined($backup->{'keep'});
444 my $ctime = $backup->{'backup-time'};
445 my $type = $backup->{'backup-type'};
446 my $vmid = $backup->{'backup-id'};
447 my $volid = print_volid
($storeid, $type, $vmid, $ctime);
449 my $mark = $backup->{keep
} ?
'keep' : 'remove';
450 $mark = 'protected' if $backup->{protected
};
452 push @{$prune_list}, {
455 type
=> $type eq 'vm' ?
'qemu' : 'lxc',
462 $logfunc->('err', "prune '$backup_group': $err\n");
466 die "error pruning backups - check log\n" if $failed;
471 my $autogen_encryption_key = sub {
472 my ($scfg, $storeid) = @_;
473 my $encfile = pbs_encryption_key_file_name
($scfg, $storeid);
475 rename $encfile, "$encfile.old";
477 my $cmd = ['proxmox-backup-client', 'key', 'create', '--kdf', 'none', $encfile];
478 run_command
($cmd, errmsg
=> 'failed to create encryption key');
479 return PVE
::Tools
::file_get_contents
($encfile);
483 my ($class, $storeid, $scfg, %param) = @_;
487 if (defined(my $password = $param{password
})) {
488 pbs_set_password
($scfg, $storeid, $password);
490 pbs_delete_password
($scfg, $storeid);
493 if (defined(my $encryption_key = $param{'encryption-key'})) {
495 if ($encryption_key eq 'autogen') {
496 $res->{'encryption-key'} = $autogen_encryption_key->($scfg, $storeid);
497 $decoded_key = decode_json
($res->{'encryption-key'});
499 $decoded_key = eval { decode_json
($encryption_key) };
500 if ($@ || !exists($decoded_key->{data
})) {
501 die "Value does not seems like a valid, JSON formatted encryption key!\n";
503 pbs_set_encryption_key
($scfg, $storeid, $encryption_key);
504 $res->{'encryption-key'} = $encryption_key;
506 $scfg->{'encryption-key'} = $decoded_key->{fingerprint
} || 1;
508 pbs_delete_encryption_key
($scfg, $storeid);
511 if (defined(my $master_key = delete $param{'master-pubkey'})) {
512 die "'master-pubkey' can only be used together with 'encryption-key'\n"
513 if !defined($scfg->{'encryption-key'});
515 my $decoded = decode_base64
($master_key);
516 pbs_set_master_pubkey
($scfg, $storeid, $decoded);
517 $scfg->{'master-pubkey'} = 1;
519 pbs_delete_master_pubkey
($scfg, $storeid);
526 my ($class, $storeid, $scfg, %param) = @_;
530 if (exists($param{password
})) {
531 if (defined($param{password
})) {
532 pbs_set_password
($scfg, $storeid, $param{password
});
534 pbs_delete_password
($scfg, $storeid);
538 if (exists($param{'encryption-key'})) {
539 if (defined(my $encryption_key = delete($param{'encryption-key'}))) {
541 if ($encryption_key eq 'autogen') {
542 $res->{'encryption-key'} = $autogen_encryption_key->($scfg, $storeid);
543 $decoded_key = decode_json
($res->{'encryption-key'});
545 $decoded_key = eval { decode_json
($encryption_key) };
546 if ($@ || !exists($decoded_key->{data
})) {
547 die "Value does not seems like a valid, JSON formatted encryption key!\n";
549 pbs_set_encryption_key
($scfg, $storeid, $encryption_key);
550 $res->{'encryption-key'} = $encryption_key;
552 $scfg->{'encryption-key'} = $decoded_key->{fingerprint
} || 1;
554 pbs_delete_encryption_key
($scfg, $storeid);
555 delete $scfg->{'encryption-key'};
559 if (exists($param{'master-pubkey'})) {
560 if (defined(my $master_key = delete($param{'master-pubkey'}))) {
561 my $decoded = decode_base64
($master_key);
563 pbs_set_master_pubkey
($scfg, $storeid, $decoded);
564 $scfg->{'master-pubkey'} = 1;
566 pbs_delete_master_pubkey
($scfg, $storeid);
574 my ($class, $storeid, $scfg) = @_;
576 pbs_delete_password
($scfg, $storeid);
577 pbs_delete_encryption_key
($scfg, $storeid);
578 pbs_delete_master_pubkey
($scfg, $storeid);
584 my ($class, $volname) = @_;
586 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)$!) {
590 my $format = "pbs-$btype";
592 my $name = "$btype/$bid/$btime";
594 if ($bid =~ m/^\d+$/) {
595 return ('backup', $name, $bid, undef, undef, undef, $format);
597 return ('backup', $name, undef, undef, undef, undef, $format);
601 die "unable to parse PBS volume name '$volname'\n";
605 my ($class, $scfg, $volname, $storeid, $snapname) = @_;
607 die "volume snapshot is not possible on pbs storage"
608 if defined($snapname);
610 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
612 my $repo = PVE
::PBSClient
::get_repository
($scfg);
614 # artificial url - we currently do not use that anywhere
615 my $path = "pbs://$repo/$name";
616 if (defined(my $ns = $scfg->{namespace
})) {
617 $ns =~ s
|/|%2f|g
; # other characters to escape aren't allowed in the namespace schema
621 return ($path, $vmid, $vtype);
625 my ($class, $storeid, $scfg, $volname) = @_;
627 die "can't create base images in pbs storage\n";
631 my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
633 die "can't clone images in pbs storage\n";
637 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
639 die "can't allocate space in pbs storage\n";
643 my ($class, $storeid, $scfg, $volname, $isBase) = @_;
645 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
647 run_client_cmd
($scfg, $storeid, "forget", [ $name ], 1);
654 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
661 my sub snapshot_files_encrypted
{
667 for my $file (@$files) {
668 my $fn = $file->{filename
};
669 next if $fn eq 'client.log.blob' || $fn eq 'index.json.blob';
671 my $crypt = $file->{'crypt-mode'};
673 $all = 0 if !$crypt || $crypt ne 'encrypt';
674 $any ||= defined($crypt) && $crypt eq 'encrypt';
679 # TODO: use a client with native rust/proxmox-backup bindings to profit from
680 # API schema checks and types
681 my sub pbs_api_connect
{
682 my ($scfg, $password) = @_;
686 my $user = $scfg->{username
} // 'root@pam';
688 if (my $tokenid = PVE
::AccessControl
::pve_verify_tokenid
($user, 1)) {
689 $params->{apitoken
} = "PBSAPIToken=${tokenid}:${password}";
691 $params->{password
} = $password;
692 $params->{username
} = $user;
695 if (my $fp = $scfg->{fingerprint
}) {
696 $params->{cached_fingerprints
}->{uc($fp)} = 1;
699 my $conn = PVE
::APIClient
::LWP-
>new(
701 host
=> $scfg->{server
},
702 port
=> $scfg->{port
} // 8007,
703 timeout
=> 7, # cope with a 401 (3s api delay) and high latency
704 cookie_name
=> 'PBSAuthCookie',
711 my ($class, $storeid, $scfg, $vmid, $content_types) = @_;
715 return $res if !grep { $_ eq 'backup' } @$content_types;
717 my $password = pbs_get_password
($scfg, $storeid);
718 my $conn = pbs_api_connect
($scfg, $password);
719 my $datastore = $scfg->{datastore
};
722 $param->{'backup-id'} = "$vmid" if defined($vmid);
723 my $data = eval { $conn->get("/api2/json/admin/datastore/$datastore/snapshots", $param); };
724 die "error listing snapshots - $@" if $@;
726 foreach my $item (@$data) {
727 my $btype = $item->{"backup-type"};
728 my $bid = $item->{"backup-id"};
729 my $epoch = $item->{"backup-time"};
730 my $size = $item->{size
} // 1;
732 next if !($btype eq 'vm' || $btype eq 'ct');
733 next if $bid !~ m/^\d+$/;
734 next if defined($vmid) && $bid ne $vmid;
736 my $volid = print_volid
($storeid, $btype, $bid, $epoch);
740 format
=> "pbs-$btype",
745 subtype
=> $btype eq 'vm' ?
'qemu' : 'lxc', # convert to PVE backup type
748 $info->{verification
} = $item->{verification
} if defined($item->{verification
});
749 $info->{notes
} = $item->{comment
} if defined($item->{comment
});
750 $info->{protected
} = 1 if $item->{protected
};
751 if (defined($item->{fingerprint
})) {
752 $info->{encrypted
} = $item->{fingerprint
};
753 } elsif (snapshot_files_encrypted
($item->{files
})) {
754 $info->{encrypted
} = '1';
764 my ($class, $storeid, $scfg, $cache) = @_;
772 my $res = run_client_cmd
($scfg, $storeid, "status");
775 $total = $res->{total
};
776 $used = $res->{used
};
777 $free = $res->{avail
};
783 return ($total, $free, $used, $active);
786 # can also be used for not (yet) added storages, pass $scfg with
790 # port (optional default to 8007)
791 # fingerprint (optional for trusted certs)
793 sub scan_datastores
{
794 my ($scfg, $password) = @_;
796 my $conn = pbs_api_connect
($scfg, $password);
798 my $response = eval { $conn->get('/api2/json/admin/datastore', {}) };
799 die "error fetching datastores - $@" if $@;
804 sub activate_storage
{
805 my ($class, $storeid, $scfg, $cache) = @_;
807 my $password = pbs_get_password
($scfg, $storeid);
809 my $datastores = eval { scan_datastores
($scfg, $password) };
810 die "$storeid: $@" if $@;
812 my $datastore = $scfg->{datastore
};
814 for my $ds (@$datastores) {
815 if ($ds->{store
} eq $datastore) {
820 die "$storeid: Cannot find datastore '$datastore', check permissions and existence!\n";
823 sub deactivate_storage
{
824 my ($class, $storeid, $scfg, $cache) = @_;
828 sub activate_volume
{
829 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
831 die "volume snapshot is not possible on pbs device" if $snapname;
836 sub deactivate_volume
{
837 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
839 die "volume snapshot is not possible on pbs device" if $snapname;
844 # FIXME remove on the next APIAGE reset.
845 # Deprecated, use get_volume_attribute instead.
846 sub get_volume_notes
{
847 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
849 my (undef, $name, undef, undef, undef, undef, $format) = $class->parse_volname($volname);
851 my $data = run_client_cmd
($scfg, $storeid, "snapshot", [ "notes", "show", $name ]);
853 return $data->{notes
};
856 # FIXME remove on the next APIAGE reset.
857 # Deprecated, use update_volume_attribute instead.
858 sub update_volume_notes
{
859 my ($class, $scfg, $storeid, $volname, $notes, $timeout) = @_;
861 my (undef, $name, undef, undef, undef, undef, $format) = $class->parse_volname($volname);
863 run_client_cmd
($scfg, $storeid, "snapshot", [ "notes", "update", $name, $notes ], 1);
868 sub get_volume_attribute
{
869 my ($class, $scfg, $storeid, $volname, $attribute) = @_;
871 if ($attribute eq 'notes') {
872 return $class->get_volume_notes($scfg, $storeid, $volname);
875 if ($attribute eq 'protected') {
876 my $param = api_param_from_volname
($class, $scfg, $volname);
878 my $password = pbs_get_password
($scfg, $storeid);
879 my $conn = pbs_api_connect
($scfg, $password);
880 my $datastore = $scfg->{datastore
};
882 my $res = eval { $conn->get("/api2/json/admin/datastore/$datastore/$attribute", $param); };
884 return if $err->{code
} == 404; # not supported
893 sub update_volume_attribute
{
894 my ($class, $scfg, $storeid, $volname, $attribute, $value) = @_;
896 if ($attribute eq 'notes') {
897 return $class->update_volume_notes($scfg, $storeid, $volname, $value);
900 if ($attribute eq 'protected') {
901 my $param = api_param_from_volname
($class, $scfg, $volname);
902 $param->{$attribute} = $value;
904 my $password = pbs_get_password
($scfg, $storeid);
905 my $conn = pbs_api_connect
($scfg, $password);
906 my $datastore = $scfg->{datastore
};
908 eval { $conn->put("/api2/json/admin/datastore/$datastore/$attribute", $param); };
910 die "Server is not recent enough to support feature '$attribute'\n"
911 if $err->{code
} == 404;
917 die "attribute '$attribute' is not supported for storage type '$scfg->{type}'\n";
920 sub volume_size_info
{
921 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
923 my ($vtype, $name, undef, undef, undef, undef, $format) = $class->parse_volname($volname);
925 my $data = run_client_cmd
($scfg, $storeid, "files", [ $name ]);
928 foreach my $info (@$data) {
929 if ($info->{size
} && $info->{size
} =~ /^(\d+)$/) { # untaints
936 return wantarray ?
($size, $format, $used, undef) : $size;
940 my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
941 die "volume resize is not possible on pbs device";
944 sub volume_snapshot
{
945 my ($class, $scfg, $storeid, $volname, $snap) = @_;
946 die "volume snapshot is not possible on pbs device";
949 sub volume_snapshot_rollback
{
950 my ($class, $scfg, $storeid, $volname, $snap) = @_;
951 die "volume snapshot rollback is not possible on pbs device";
954 sub volume_snapshot_delete
{
955 my ($class, $scfg, $storeid, $volname, $snap) = @_;
956 die "volume snapshot delete is not possible on pbs device";
959 sub volume_has_feature
{
960 my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running) = @_;