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)) {
214 die "master public key configured but no key file found!\n"
215 if $scfg->{'master-pubkey'};
218 die "failed to open master public key: $master_pubkey_file: $!\n";
225 my ($storeid, $btype, $bid, $btime) = @_;
227 my $time_str = strftime
("%FT%TZ", gmtime($btime));
228 my $volname = "backup/${btype}/${bid}/${time_str}";
230 return "${storeid}:${volname}";
233 my sub ns
: prototype($$) {
234 my ($scfg, $name) = @_;
235 my $ns = $scfg->{namespace
};
236 return defined($ns) ?
($name, $ns) : ();
239 # essentially the inverse of print_volid
240 my sub api_param_from_volname
: prototype($$$) {
241 my ($class, $scfg, $volname) = @_;
243 my $name = ($class->parse_volname($volname))[1];
245 my ($btype, $bid, $timestr) = split('/', $name);
247 my @tm = (POSIX
::strptime
($timestr, "%FT%TZ"));
248 # expect sec, min, hour, mday, mon, year
249 die "error parsing time from '$volname'" if grep { !defined($_) } @tm[0..5];
253 local $ENV{TZ
} = 'UTC'; # $timestr is UTC
255 # Fill in isdst to avoid undef warning. No daylight saving time for UTC.
258 my $since_epoch = mktime
(@tm) or die "error converting time from '$volname'\n";
259 $btime = int($since_epoch);
264 'backup-type' => $btype,
266 'backup-time' => $btime,
270 my $USE_CRYPT_PARAMS = {
276 my $USE_MASTER_KEY = {
280 my sub do_raw_client_cmd
{
281 my ($scfg, $storeid, $client_cmd, $param, %opts) = @_;
283 my $use_crypto = $USE_CRYPT_PARAMS->{$client_cmd};
284 my $use_master = $USE_MASTER_KEY->{$client_cmd};
286 my $client_exe = '/usr/bin/proxmox-backup-client';
287 die "executable not found '$client_exe'! Proxmox backup client not installed?\n"
290 my $repo = PVE
::PBSClient
::get_repository
($scfg);
292 my $userns_cmd = delete $opts{userns_cmd
};
296 push @$cmd, @$userns_cmd if defined($userns_cmd);
298 push @$cmd, $client_exe, $client_cmd;
300 # This must live in the top scope to not get closed before the `run_command`
301 my ($keyfd, $master_fd);
303 if (defined($keyfd = pbs_open_encryption_key
($scfg, $storeid))) {
304 my $flags = fcntl($keyfd, F_GETFD
, 0)
305 // die "failed to get file descriptor flags: $!\n";
306 fcntl($keyfd, F_SETFD
, $flags & ~FD_CLOEXEC
)
307 or die "failed to remove FD_CLOEXEC from encryption key file descriptor\n";
308 push @$cmd, '--crypt-mode=encrypt', '--keyfd='.fileno($keyfd);
309 if ($use_master && defined($master_fd = pbs_open_master_pubkey
($scfg, $storeid))) {
310 my $flags = fcntl($master_fd, F_GETFD
, 0)
311 // die "failed to get file descriptor flags: $!\n";
312 fcntl($master_fd, F_SETFD
, $flags & ~FD_CLOEXEC
)
313 or die "failed to remove FD_CLOEXEC from master public key file descriptor\n";
314 push @$cmd, '--master-pubkey-fd='.fileno($master_fd);
317 push @$cmd, '--crypt-mode=none';
321 push @$cmd, @$param if defined($param);
323 push @$cmd, "--repository", $repo;
324 if ($client_cmd ne 'status' && defined(my $ns = $scfg->{namespace
})) {
325 push @$cmd, '--ns', $ns;
328 local $ENV{PBS_PASSWORD
} = pbs_get_password
($scfg, $storeid);
330 local $ENV{PBS_FINGERPRINT
} = $scfg->{fingerprint
};
332 # no ascii-art on task logs
333 local $ENV{PROXMOX_OUTPUT_NO_BORDER
} = 1;
334 local $ENV{PROXMOX_OUTPUT_NO_HEADER
} = 1;
336 if (my $logfunc = $opts{logfunc
}) {
337 $logfunc->("run: " . join(' ', @$cmd));
340 run_command
($cmd, %opts);
343 # FIXME: External perl code should NOT have access to this.
345 # There should be separate functions to
350 sub run_raw_client_cmd
{
351 my ($scfg, $storeid, $client_cmd, $param, %opts) = @_;
352 return do_raw_client_cmd
($scfg, $storeid, $client_cmd, $param, %opts);
356 my ($scfg, $storeid, $client_cmd, $param, $no_output) = @_;
359 my $outfunc = sub { $json_str .= "$_[0]\n" };
361 $param = [] if !defined($param);
362 $param = [ $param ] if !ref($param);
364 $param = [@$param, '--output-format=json'] if !$no_output;
366 do_raw_client_cmd
($scfg, $storeid, $client_cmd, $param,
367 outfunc
=> $outfunc, errmsg
=> 'proxmox-backup-client failed');
369 return undef if $no_output;
371 my $res = decode_json
($json_str);
376 # Storage implementation
378 sub extract_vzdump_config
{
379 my ($class, $scfg, $volname, $storeid) = @_;
381 my ($vtype, $name, $vmid, undef, undef, undef, $format) = $class->parse_volname($volname);
384 my $outfunc = sub { $config .= "$_[0]\n" };
387 if ($format eq 'pbs-vm') {
388 $config_name = 'qemu-server.conf';
389 } elsif ($format eq 'pbs-ct') {
390 $config_name = 'pct.conf';
392 die "unable to extract configuration for backup format '$format'\n";
395 do_raw_client_cmd
($scfg, $storeid, 'restore', [ $name, $config_name, '-' ],
396 outfunc
=> $outfunc, errmsg
=> 'proxmox-backup-client failed');
402 my ($class, $scfg, $storeid, $keep, $vmid, $type, $dryrun, $logfunc) = @_;
404 $logfunc //= sub { print "$_[1]\n" };
406 $type = 'vm' if defined($type) && $type eq 'qemu';
407 $type = 'ct' if defined($type) && $type eq 'lxc';
409 my $backup_groups = {};
411 if (defined($vmid) && defined($type)) {
412 # no need to get the list of volumes, we only got a single backup group anyway
413 $backup_groups->{"$type/$vmid"} = 1;
415 my $backups = eval { $class->list_volumes($storeid, $scfg, $vmid, ['backup']) };
416 die "failed to get list of all backups to prune - $@" if $@;
418 foreach my $backup (@{$backups}) {
419 (my $backup_type = $backup->{format
}) =~ s/^pbs-//;
420 next if defined($type) && $backup_type ne $type;
422 my $backup_group = "$backup_type/$backup->{vmid}";
423 $backup_groups->{$backup_group} = 1;
429 my $keep_all = delete $keep->{'keep-all'};
432 foreach my $opt (keys %{$keep}) {
433 next if $keep->{$opt} == 0;
434 push @param, "--$opt";
435 push @param, "$keep->{$opt}";
437 } else { # no need to pass anything to PBS
438 $keep = { 'keep-all' => 1 };
441 push @param, '--dry-run' if $dryrun;
446 foreach my $backup_group (keys %{$backup_groups}) {
447 $logfunc->('info', "running 'proxmox-backup-client prune' for '$backup_group'")
450 my $res = run_client_cmd
($scfg, $storeid, 'prune', [ $backup_group, @param ]);
452 foreach my $backup (@{$res}) {
453 die "result from proxmox-backup-client is not as expected\n"
454 if !defined($backup->{'backup-time'})
455 || !defined($backup->{'backup-type'})
456 || !defined($backup->{'backup-id'})
457 || !defined($backup->{'keep'});
459 my $ctime = $backup->{'backup-time'};
460 my $type = $backup->{'backup-type'};
461 my $vmid = $backup->{'backup-id'};
462 my $volid = print_volid
($storeid, $type, $vmid, $ctime);
464 my $mark = $backup->{keep
} ?
'keep' : 'remove';
465 $mark = 'protected' if $backup->{protected
};
467 push @{$prune_list}, {
470 type
=> $type eq 'vm' ?
'qemu' : 'lxc',
477 $logfunc->('err', "prune '$backup_group': $err\n");
481 die "error pruning backups - check log\n" if $failed;
486 my $autogen_encryption_key = sub {
487 my ($scfg, $storeid) = @_;
488 my $encfile = pbs_encryption_key_file_name
($scfg, $storeid);
490 rename $encfile, "$encfile.old";
492 my $cmd = ['proxmox-backup-client', 'key', 'create', '--kdf', 'none', $encfile];
493 run_command
($cmd, errmsg
=> 'failed to create encryption key');
494 return PVE
::Tools
::file_get_contents
($encfile);
498 my ($class, $storeid, $scfg, %param) = @_;
502 if (defined(my $password = $param{password
})) {
503 pbs_set_password
($scfg, $storeid, $password);
505 pbs_delete_password
($scfg, $storeid);
508 if (defined(my $encryption_key = $param{'encryption-key'})) {
510 if ($encryption_key eq 'autogen') {
511 $res->{'encryption-key'} = $autogen_encryption_key->($scfg, $storeid);
512 $decoded_key = decode_json
($res->{'encryption-key'});
514 $decoded_key = eval { decode_json
($encryption_key) };
515 if ($@ || !exists($decoded_key->{data
})) {
516 die "Value does not seems like a valid, JSON formatted encryption key!\n";
518 pbs_set_encryption_key
($scfg, $storeid, $encryption_key);
519 $res->{'encryption-key'} = $encryption_key;
521 $scfg->{'encryption-key'} = $decoded_key->{fingerprint
} || 1;
523 pbs_delete_encryption_key
($scfg, $storeid);
526 if (defined(my $master_key = delete $param{'master-pubkey'})) {
527 die "'master-pubkey' can only be used together with 'encryption-key'\n"
528 if !defined($scfg->{'encryption-key'});
530 my $decoded = decode_base64
($master_key);
531 pbs_set_master_pubkey
($scfg, $storeid, $decoded);
532 $scfg->{'master-pubkey'} = 1;
534 pbs_delete_master_pubkey
($scfg, $storeid);
541 my ($class, $storeid, $scfg, %param) = @_;
545 if (exists($param{password
})) {
546 if (defined($param{password
})) {
547 pbs_set_password
($scfg, $storeid, $param{password
});
549 pbs_delete_password
($scfg, $storeid);
553 if (exists($param{'encryption-key'})) {
554 if (defined(my $encryption_key = delete($param{'encryption-key'}))) {
556 if ($encryption_key eq 'autogen') {
557 $res->{'encryption-key'} = $autogen_encryption_key->($scfg, $storeid);
558 $decoded_key = decode_json
($res->{'encryption-key'});
560 $decoded_key = eval { decode_json
($encryption_key) };
561 if ($@ || !exists($decoded_key->{data
})) {
562 die "Value does not seems like a valid, JSON formatted encryption key!\n";
564 pbs_set_encryption_key
($scfg, $storeid, $encryption_key);
565 $res->{'encryption-key'} = $encryption_key;
567 $scfg->{'encryption-key'} = $decoded_key->{fingerprint
} || 1;
569 pbs_delete_encryption_key
($scfg, $storeid);
570 delete $scfg->{'encryption-key'};
574 if (exists($param{'master-pubkey'})) {
575 if (defined(my $master_key = delete($param{'master-pubkey'}))) {
576 my $decoded = decode_base64
($master_key);
578 pbs_set_master_pubkey
($scfg, $storeid, $decoded);
579 $scfg->{'master-pubkey'} = 1;
581 pbs_delete_master_pubkey
($scfg, $storeid);
589 my ($class, $storeid, $scfg) = @_;
591 pbs_delete_password
($scfg, $storeid);
592 pbs_delete_encryption_key
($scfg, $storeid);
593 pbs_delete_master_pubkey
($scfg, $storeid);
599 my ($class, $volname) = @_;
601 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)$!) {
605 my $format = "pbs-$btype";
607 my $name = "$btype/$bid/$btime";
609 if ($bid =~ m/^\d+$/) {
610 return ('backup', $name, $bid, undef, undef, undef, $format);
612 return ('backup', $name, undef, undef, undef, undef, $format);
616 die "unable to parse PBS volume name '$volname'\n";
620 my ($class, $scfg, $volname, $storeid, $snapname) = @_;
622 die "volume snapshot is not possible on pbs storage"
623 if defined($snapname);
625 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
627 my $repo = PVE
::PBSClient
::get_repository
($scfg);
629 # artificial url - we currently do not use that anywhere
630 my $path = "pbs://$repo/$name";
631 if (defined(my $ns = $scfg->{namespace
})) {
632 $ns =~ s
|/|%2f|g
; # other characters to escape aren't allowed in the namespace schema
636 return ($path, $vmid, $vtype);
640 my ($class, $storeid, $scfg, $volname) = @_;
642 die "can't create base images in pbs storage\n";
646 my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
648 die "can't clone images in pbs storage\n";
652 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
654 die "can't allocate space in pbs storage\n";
658 my ($class, $storeid, $scfg, $volname, $isBase) = @_;
660 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
662 run_client_cmd
($scfg, $storeid, "forget", [ $name ], 1);
669 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
676 my sub snapshot_files_encrypted
{
682 for my $file (@$files) {
683 my $fn = $file->{filename
};
684 next if $fn eq 'client.log.blob' || $fn eq 'index.json.blob';
686 my $crypt = $file->{'crypt-mode'};
688 $all = 0 if !$crypt || $crypt ne 'encrypt';
689 $any ||= defined($crypt) && $crypt eq 'encrypt';
694 # TODO: use a client with native rust/proxmox-backup bindings to profit from
695 # API schema checks and types
696 my sub pbs_api_connect
{
697 my ($scfg, $password, $timeout) = @_;
701 my $user = $scfg->{username
} // 'root@pam';
703 if (my $tokenid = PVE
::AccessControl
::pve_verify_tokenid
($user, 1)) {
704 $params->{apitoken
} = "PBSAPIToken=${tokenid}:${password}";
706 $params->{password
} = $password;
707 $params->{username
} = $user;
710 if (my $fp = $scfg->{fingerprint
}) {
711 $params->{cached_fingerprints
}->{uc($fp)} = 1;
714 my $conn = PVE
::APIClient
::LWP-
>new(
716 host
=> $scfg->{server
},
717 port
=> $scfg->{port
} // 8007,
718 timeout
=> ($timeout // 7), # cope with a 401 (3s api delay) and high latency
719 cookie_name
=> 'PBSAuthCookie',
726 my ($class, $storeid, $scfg, $vmid, $content_types) = @_;
730 return $res if !grep { $_ eq 'backup' } @$content_types;
732 my $password = pbs_get_password
($scfg, $storeid);
733 my $conn = pbs_api_connect
($scfg, $password, 120);
734 my $datastore = $scfg->{datastore
};
737 $param->{'backup-id'} = "$vmid" if defined($vmid);
738 $param->{'ns'} = "$scfg->{namespace}" if defined($scfg->{namespace
});
739 my $data = eval { $conn->get("/api2/json/admin/datastore/$datastore/snapshots", $param); };
740 die "error listing snapshots - $@" if $@;
742 foreach my $item (@$data) {
743 my $btype = $item->{"backup-type"};
744 my $bid = $item->{"backup-id"};
745 my $epoch = $item->{"backup-time"};
746 my $size = $item->{size
} // 1;
748 next if !($btype eq 'vm' || $btype eq 'ct');
749 next if $bid !~ m/^\d+$/;
750 next if defined($vmid) && $bid ne $vmid;
752 my $volid = print_volid
($storeid, $btype, $bid, $epoch);
756 format
=> "pbs-$btype",
761 subtype
=> $btype eq 'vm' ?
'qemu' : 'lxc', # convert to PVE backup type
764 $info->{verification
} = $item->{verification
} if defined($item->{verification
});
765 $info->{notes
} = $item->{comment
} if defined($item->{comment
});
766 $info->{protected
} = 1 if $item->{protected
};
767 if (defined($item->{fingerprint
})) {
768 $info->{encrypted
} = $item->{fingerprint
};
769 } elsif (snapshot_files_encrypted
($item->{files
})) {
770 $info->{encrypted
} = '1';
780 my ($class, $storeid, $scfg, $cache) = @_;
788 my $res = run_client_cmd
($scfg, $storeid, "status");
791 $total = $res->{total
};
792 $used = $res->{used
};
793 $free = $res->{avail
};
799 return ($total, $free, $used, $active);
802 # can also be used for not (yet) added storages, pass $scfg with
806 # port (optional default to 8007)
807 # fingerprint (optional for trusted certs)
809 sub scan_datastores
{
810 my ($scfg, $password) = @_;
812 my $conn = pbs_api_connect
($scfg, $password);
814 my $response = eval { $conn->get('/api2/json/admin/datastore', {}) };
815 die "error fetching datastores - $@" if $@;
820 sub activate_storage
{
821 my ($class, $storeid, $scfg, $cache) = @_;
823 my $password = pbs_get_password
($scfg, $storeid);
825 my $datastores = eval { scan_datastores
($scfg, $password) };
826 die "$storeid: $@" if $@;
828 my $datastore = $scfg->{datastore
};
830 for my $ds (@$datastores) {
831 if ($ds->{store
} eq $datastore) {
836 die "$storeid: Cannot find datastore '$datastore', check permissions and existence!\n";
839 sub deactivate_storage
{
840 my ($class, $storeid, $scfg, $cache) = @_;
844 sub activate_volume
{
845 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
847 die "volume snapshot is not possible on pbs device" if $snapname;
852 sub deactivate_volume
{
853 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
855 die "volume snapshot is not possible on pbs device" if $snapname;
860 # FIXME remove on the next APIAGE reset.
861 # Deprecated, use get_volume_attribute instead.
862 sub get_volume_notes
{
863 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
865 my (undef, $name, undef, undef, undef, undef, $format) = $class->parse_volname($volname);
867 my $data = run_client_cmd
($scfg, $storeid, "snapshot", [ "notes", "show", $name ]);
869 return $data->{notes
};
872 # FIXME remove on the next APIAGE reset.
873 # Deprecated, use update_volume_attribute instead.
874 sub update_volume_notes
{
875 my ($class, $scfg, $storeid, $volname, $notes, $timeout) = @_;
877 my (undef, $name, undef, undef, undef, undef, $format) = $class->parse_volname($volname);
879 run_client_cmd
($scfg, $storeid, "snapshot", [ "notes", "update", $name, $notes ], 1);
884 sub get_volume_attribute
{
885 my ($class, $scfg, $storeid, $volname, $attribute) = @_;
887 if ($attribute eq 'notes') {
888 return $class->get_volume_notes($scfg, $storeid, $volname);
891 if ($attribute eq 'protected') {
892 my $param = api_param_from_volname
($class, $scfg, $volname);
894 my $password = pbs_get_password
($scfg, $storeid);
895 my $conn = pbs_api_connect
($scfg, $password);
896 my $datastore = $scfg->{datastore
};
898 my $res = eval { $conn->get("/api2/json/admin/datastore/$datastore/$attribute", $param); };
900 return if $err->{code
} == 404; # not supported
909 sub update_volume_attribute
{
910 my ($class, $scfg, $storeid, $volname, $attribute, $value) = @_;
912 if ($attribute eq 'notes') {
913 return $class->update_volume_notes($scfg, $storeid, $volname, $value);
916 if ($attribute eq 'protected') {
917 my $param = api_param_from_volname
($class, $scfg, $volname);
918 $param->{$attribute} = $value;
920 my $password = pbs_get_password
($scfg, $storeid);
921 my $conn = pbs_api_connect
($scfg, $password);
922 my $datastore = $scfg->{datastore
};
924 eval { $conn->put("/api2/json/admin/datastore/$datastore/$attribute", $param); };
926 die "Server is not recent enough to support feature '$attribute'\n"
927 if $err->{code
} == 404;
933 die "attribute '$attribute' is not supported for storage type '$scfg->{type}'\n";
936 sub volume_size_info
{
937 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
939 my ($vtype, $name, undef, undef, undef, undef, $format) = $class->parse_volname($volname);
941 my $data = run_client_cmd
($scfg, $storeid, "files", [ $name ]);
944 foreach my $info (@$data) {
945 if ($info->{size
} && $info->{size
} =~ /^(\d+)$/) { # untaints
952 return wantarray ?
($size, $format, $used, undef) : $size;
956 my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
957 die "volume resize is not possible on pbs device";
960 sub volume_snapshot
{
961 my ($class, $scfg, $storeid, $volname, $snap) = @_;
962 die "volume snapshot is not possible on pbs device";
965 sub volume_snapshot_rollback
{
966 my ($class, $scfg, $storeid, $volname, $snap) = @_;
967 die "volume snapshot rollback is not possible on pbs device";
970 sub volume_snapshot_delete
{
971 my ($class, $scfg, $storeid, $volname, $snap) = @_;
972 die "volume snapshot delete is not possible on pbs device";
975 sub volume_has_feature
{
976 my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running) = @_;