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.",
63 server
=> { fixed
=> 1 },
64 datastore
=> { fixed
=> 1 },
65 namespace
=> { optional
=> 1 },
66 port
=> { optional
=> 1 },
67 nodes
=> { optional
=> 1},
68 disable
=> { optional
=> 1},
69 content
=> { optional
=> 1},
70 username
=> { optional
=> 1 },
71 password
=> { optional
=> 1 },
72 'encryption-key' => { optional
=> 1 },
73 'master-pubkey' => { optional
=> 1 },
74 maxfiles
=> { optional
=> 1 },
75 'prune-backups' => { optional
=> 1 },
76 'max-protected-backups' => { optional
=> 1 },
77 fingerprint
=> { optional
=> 1 },
83 sub pbs_password_file_name
{
84 my ($scfg, $storeid) = @_;
86 return "/etc/pve/priv/storage/${storeid}.pw";
89 sub pbs_set_password
{
90 my ($scfg, $storeid, $password) = @_;
92 my $pwfile = pbs_password_file_name
($scfg, $storeid);
93 mkdir "/etc/pve/priv/storage";
95 PVE
::Tools
::file_set_contents
($pwfile, "$password\n");
98 sub pbs_delete_password
{
99 my ($scfg, $storeid) = @_;
101 my $pwfile = pbs_password_file_name
($scfg, $storeid);
106 sub pbs_get_password
{
107 my ($scfg, $storeid) = @_;
109 my $pwfile = pbs_password_file_name
($scfg, $storeid);
111 return PVE
::Tools
::file_read_firstline
($pwfile);
114 sub pbs_encryption_key_file_name
{
115 my ($scfg, $storeid) = @_;
117 return "/etc/pve/priv/storage/${storeid}.enc";
120 sub pbs_set_encryption_key
{
121 my ($scfg, $storeid, $key) = @_;
123 my $pwfile = pbs_encryption_key_file_name
($scfg, $storeid);
124 mkdir "/etc/pve/priv/storage";
126 PVE
::Tools
::file_set_contents
($pwfile, "$key\n");
129 sub pbs_delete_encryption_key
{
130 my ($scfg, $storeid) = @_;
132 my $pwfile = pbs_encryption_key_file_name
($scfg, $storeid);
134 if (!unlink $pwfile) {
135 return if $! == ENOENT
;
136 die "failed to delete encryption key! $!\n";
138 delete $scfg->{'encryption-key'};
141 sub pbs_get_encryption_key
{
142 my ($scfg, $storeid) = @_;
144 my $pwfile = pbs_encryption_key_file_name
($scfg, $storeid);
146 return PVE
::Tools
::file_get_contents
($pwfile);
149 # Returns a file handle if there is an encryption key, or `undef` if there is not. Dies on error.
150 sub pbs_open_encryption_key
{
151 my ($scfg, $storeid) = @_;
153 my $encryption_key_file = pbs_encryption_key_file_name
($scfg, $storeid);
156 if (!open($keyfd, '<', $encryption_key_file)) {
158 my $encryption_fp = $scfg->{'encryption-key'};
159 die "encryption configured ('$encryption_fp') but no encryption key file found!\n"
163 die "failed to open encryption key: $encryption_key_file: $!\n";
169 sub pbs_master_pubkey_file_name
{
170 my ($scfg, $storeid) = @_;
172 return "/etc/pve/priv/storage/${storeid}.master.pem";
175 sub pbs_set_master_pubkey
{
176 my ($scfg, $storeid, $key) = @_;
178 my $pwfile = pbs_master_pubkey_file_name
($scfg, $storeid);
179 mkdir "/etc/pve/priv/storage";
181 PVE
::Tools
::file_set_contents
($pwfile, "$key\n");
184 sub pbs_delete_master_pubkey
{
185 my ($scfg, $storeid) = @_;
187 my $pwfile = pbs_master_pubkey_file_name
($scfg, $storeid);
189 if (!unlink $pwfile) {
190 return if $! == ENOENT
;
191 die "failed to delete master public key! $!\n";
193 delete $scfg->{'master-pubkey'};
196 sub pbs_get_master_pubkey
{
197 my ($scfg, $storeid) = @_;
199 my $pwfile = pbs_master_pubkey_file_name
($scfg, $storeid);
201 return PVE
::Tools
::file_get_contents
($pwfile);
204 # Returns a file handle if there is a master key, or `undef` if there is not. Dies on error.
205 sub pbs_open_master_pubkey
{
206 my ($scfg, $storeid) = @_;
208 my $master_pubkey_file = pbs_master_pubkey_file_name
($scfg, $storeid);
211 if (!open($keyfd, '<', $master_pubkey_file)) {
213 die "master public key configured but no key file found!\n"
214 if $scfg->{'master-pubkey'};
217 die "failed to open master public key: $master_pubkey_file: $!\n";
224 my ($storeid, $btype, $bid, $btime) = @_;
226 my $time_str = strftime
("%FT%TZ", gmtime($btime));
227 my $volname = "backup/${btype}/${bid}/${time_str}";
229 return "${storeid}:${volname}";
232 my sub ns
: prototype($$) {
233 my ($scfg, $name) = @_;
234 my $ns = $scfg->{namespace
};
235 return defined($ns) ?
($name, $ns) : ();
238 # essentially the inverse of print_volid
239 my sub api_param_from_volname
: prototype($$$) {
240 my ($class, $scfg, $volname) = @_;
242 my $name = ($class->parse_volname($volname))[1];
244 my ($btype, $bid, $timestr) = split('/', $name);
246 my @tm = (POSIX
::strptime
($timestr, "%FT%TZ"));
247 # expect sec, min, hour, mday, mon, year
248 die "error parsing time from '$volname'" if grep { !defined($_) } @tm[0..5];
252 local $ENV{TZ
} = 'UTC'; # $timestr is UTC
254 # Fill in isdst to avoid undef warning. No daylight saving time for UTC.
257 my $since_epoch = mktime
(@tm) or die "error converting time from '$volname'\n";
258 $btime = int($since_epoch);
263 'backup-type' => $btype,
265 'backup-time' => $btime,
269 my $USE_CRYPT_PARAMS = {
275 my $USE_MASTER_KEY = {
279 my sub do_raw_client_cmd
{
280 my ($scfg, $storeid, $client_cmd, $param, %opts) = @_;
282 my $use_crypto = $USE_CRYPT_PARAMS->{$client_cmd};
283 my $use_master = $USE_MASTER_KEY->{$client_cmd};
285 my $client_exe = '/usr/bin/proxmox-backup-client';
286 die "executable not found '$client_exe'! Proxmox backup client not installed?\n"
289 my $repo = PVE
::PBSClient
::get_repository
($scfg);
291 my $userns_cmd = delete $opts{userns_cmd
};
295 push @$cmd, @$userns_cmd if defined($userns_cmd);
297 push @$cmd, $client_exe, $client_cmd;
299 # This must live in the top scope to not get closed before the `run_command`
300 my ($keyfd, $master_fd);
302 if (defined($keyfd = pbs_open_encryption_key
($scfg, $storeid))) {
303 my $flags = fcntl($keyfd, F_GETFD
, 0)
304 // die "failed to get file descriptor flags: $!\n";
305 fcntl($keyfd, F_SETFD
, $flags & ~FD_CLOEXEC
)
306 or die "failed to remove FD_CLOEXEC from encryption key file descriptor\n";
307 push @$cmd, '--crypt-mode=encrypt', '--keyfd='.fileno($keyfd);
308 if ($use_master && defined($master_fd = pbs_open_master_pubkey
($scfg, $storeid))) {
309 my $flags = fcntl($master_fd, F_GETFD
, 0)
310 // die "failed to get file descriptor flags: $!\n";
311 fcntl($master_fd, F_SETFD
, $flags & ~FD_CLOEXEC
)
312 or die "failed to remove FD_CLOEXEC from master public key file descriptor\n";
313 push @$cmd, '--master-pubkey-fd='.fileno($master_fd);
316 push @$cmd, '--crypt-mode=none';
320 push @$cmd, @$param if defined($param);
322 push @$cmd, "--repository", $repo;
323 if ($client_cmd ne 'status' && defined(my $ns = $scfg->{namespace
})) {
324 push @$cmd, '--ns', $ns;
327 local $ENV{PBS_PASSWORD
} = pbs_get_password
($scfg, $storeid);
329 local $ENV{PBS_FINGERPRINT
} = $scfg->{fingerprint
};
331 # no ascii-art on task logs
332 local $ENV{PROXMOX_OUTPUT_NO_BORDER
} = 1;
333 local $ENV{PROXMOX_OUTPUT_NO_HEADER
} = 1;
335 if (my $logfunc = $opts{logfunc
}) {
336 $logfunc->("run: " . join(' ', @$cmd));
339 run_command
($cmd, %opts);
342 # FIXME: External perl code should NOT have access to this.
344 # There should be separate functions to
349 sub run_raw_client_cmd
{
350 my ($scfg, $storeid, $client_cmd, $param, %opts) = @_;
351 return do_raw_client_cmd
($scfg, $storeid, $client_cmd, $param, %opts);
355 my ($scfg, $storeid, $client_cmd, $param, $no_output) = @_;
358 my $outfunc = sub { $json_str .= "$_[0]\n" };
360 $param = [] if !defined($param);
361 $param = [ $param ] if !ref($param);
363 $param = [@$param, '--output-format=json'] if !$no_output;
365 do_raw_client_cmd
($scfg, $storeid, $client_cmd, $param,
366 outfunc
=> $outfunc, errmsg
=> 'proxmox-backup-client failed');
368 return undef if $no_output;
370 my $res = decode_json
($json_str);
375 # Storage implementation
377 sub extract_vzdump_config
{
378 my ($class, $scfg, $volname, $storeid) = @_;
380 my ($vtype, $name, $vmid, undef, undef, undef, $format) = $class->parse_volname($volname);
383 my $outfunc = sub { $config .= "$_[0]\n" };
386 if ($format eq 'pbs-vm') {
387 $config_name = 'qemu-server.conf';
388 } elsif ($format eq 'pbs-ct') {
389 $config_name = 'pct.conf';
391 die "unable to extract configuration for backup format '$format'\n";
394 do_raw_client_cmd
($scfg, $storeid, 'restore', [ $name, $config_name, '-' ],
395 outfunc
=> $outfunc, errmsg
=> 'proxmox-backup-client failed');
401 my ($class, $scfg, $storeid, $keep, $vmid, $type, $dryrun, $logfunc) = @_;
403 $logfunc //= sub { print "$_[1]\n" };
405 $type = 'vm' if defined($type) && $type eq 'qemu';
406 $type = 'ct' if defined($type) && $type eq 'lxc';
408 my $backup_groups = {};
410 if (defined($vmid) && defined($type)) {
411 # no need to get the list of volumes, we only got a single backup group anyway
412 $backup_groups->{"$type/$vmid"} = 1;
414 my $backups = eval { $class->list_volumes($storeid, $scfg, $vmid, ['backup']) };
415 die "failed to get list of all backups to prune - $@" if $@;
417 foreach my $backup (@{$backups}) {
418 (my $backup_type = $backup->{format
}) =~ s/^pbs-//;
419 next if defined($type) && $backup_type ne $type;
421 my $backup_group = "$backup_type/$backup->{vmid}";
422 $backup_groups->{$backup_group} = 1;
428 my $keep_all = delete $keep->{'keep-all'};
431 foreach my $opt (keys %{$keep}) {
432 next if $keep->{$opt} == 0;
433 push @param, "--$opt";
434 push @param, "$keep->{$opt}";
436 } else { # no need to pass anything to PBS
437 $keep = { 'keep-all' => 1 };
440 push @param, '--dry-run' if $dryrun;
445 foreach my $backup_group (keys %{$backup_groups}) {
446 $logfunc->('info', "running 'proxmox-backup-client prune' for '$backup_group'")
449 my $res = run_client_cmd
($scfg, $storeid, 'prune', [ $backup_group, @param ]);
451 foreach my $backup (@{$res}) {
452 die "result from proxmox-backup-client is not as expected\n"
453 if !defined($backup->{'backup-time'})
454 || !defined($backup->{'backup-type'})
455 || !defined($backup->{'backup-id'})
456 || !defined($backup->{'keep'});
458 my $ctime = $backup->{'backup-time'};
459 my $type = $backup->{'backup-type'};
460 my $vmid = $backup->{'backup-id'};
461 my $volid = print_volid
($storeid, $type, $vmid, $ctime);
463 my $mark = $backup->{keep
} ?
'keep' : 'remove';
464 $mark = 'protected' if $backup->{protected
};
466 push @{$prune_list}, {
469 type
=> $type eq 'vm' ?
'qemu' : 'lxc',
476 $logfunc->('err', "prune '$backup_group': $err\n");
480 die "error pruning backups - check log\n" if $failed;
485 my $autogen_encryption_key = sub {
486 my ($scfg, $storeid) = @_;
487 my $encfile = pbs_encryption_key_file_name
($scfg, $storeid);
489 rename $encfile, "$encfile.old";
491 my $cmd = ['proxmox-backup-client', 'key', 'create', '--kdf', 'none', $encfile];
492 run_command
($cmd, errmsg
=> 'failed to create encryption key');
493 return PVE
::Tools
::file_get_contents
($encfile);
497 my ($class, $storeid, $scfg, %param) = @_;
501 if (defined(my $password = $param{password
})) {
502 pbs_set_password
($scfg, $storeid, $password);
504 pbs_delete_password
($scfg, $storeid);
507 if (defined(my $encryption_key = $param{'encryption-key'})) {
509 if ($encryption_key eq 'autogen') {
510 $res->{'encryption-key'} = $autogen_encryption_key->($scfg, $storeid);
511 $decoded_key = decode_json
($res->{'encryption-key'});
513 $decoded_key = eval { decode_json
($encryption_key) };
514 if ($@ || !exists($decoded_key->{data
})) {
515 die "Value does not seems like a valid, JSON formatted encryption key!\n";
517 pbs_set_encryption_key
($scfg, $storeid, $encryption_key);
518 $res->{'encryption-key'} = $encryption_key;
520 $scfg->{'encryption-key'} = $decoded_key->{fingerprint
} || 1;
522 pbs_delete_encryption_key
($scfg, $storeid);
525 if (defined(my $master_key = delete $param{'master-pubkey'})) {
526 die "'master-pubkey' can only be used together with 'encryption-key'\n"
527 if !defined($scfg->{'encryption-key'});
529 my $decoded = decode_base64
($master_key);
530 pbs_set_master_pubkey
($scfg, $storeid, $decoded);
531 $scfg->{'master-pubkey'} = 1;
533 pbs_delete_master_pubkey
($scfg, $storeid);
540 my ($class, $storeid, $scfg, %param) = @_;
544 if (exists($param{password
})) {
545 if (defined($param{password
})) {
546 pbs_set_password
($scfg, $storeid, $param{password
});
548 pbs_delete_password
($scfg, $storeid);
552 if (exists($param{'encryption-key'})) {
553 if (defined(my $encryption_key = delete($param{'encryption-key'}))) {
555 if ($encryption_key eq 'autogen') {
556 $res->{'encryption-key'} = $autogen_encryption_key->($scfg, $storeid);
557 $decoded_key = decode_json
($res->{'encryption-key'});
559 $decoded_key = eval { decode_json
($encryption_key) };
560 if ($@ || !exists($decoded_key->{data
})) {
561 die "Value does not seems like a valid, JSON formatted encryption key!\n";
563 pbs_set_encryption_key
($scfg, $storeid, $encryption_key);
564 $res->{'encryption-key'} = $encryption_key;
566 $scfg->{'encryption-key'} = $decoded_key->{fingerprint
} || 1;
568 pbs_delete_encryption_key
($scfg, $storeid);
569 delete $scfg->{'encryption-key'};
573 if (exists($param{'master-pubkey'})) {
574 if (defined(my $master_key = delete($param{'master-pubkey'}))) {
575 my $decoded = decode_base64
($master_key);
577 pbs_set_master_pubkey
($scfg, $storeid, $decoded);
578 $scfg->{'master-pubkey'} = 1;
580 pbs_delete_master_pubkey
($scfg, $storeid);
588 my ($class, $storeid, $scfg) = @_;
590 pbs_delete_password
($scfg, $storeid);
591 pbs_delete_encryption_key
($scfg, $storeid);
592 pbs_delete_master_pubkey
($scfg, $storeid);
598 my ($class, $volname) = @_;
600 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)$!) {
604 my $format = "pbs-$btype";
606 my $name = "$btype/$bid/$btime";
608 if ($bid =~ m/^\d+$/) {
609 return ('backup', $name, $bid, undef, undef, undef, $format);
611 return ('backup', $name, undef, undef, undef, undef, $format);
615 die "unable to parse PBS volume name '$volname'\n";
619 my ($class, $scfg, $volname, $storeid, $snapname) = @_;
621 die "volume snapshot is not possible on pbs storage"
622 if defined($snapname);
624 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
626 my $repo = PVE
::PBSClient
::get_repository
($scfg);
628 # artificial url - we currently do not use that anywhere
629 my $path = "pbs://$repo/$name";
630 if (defined(my $ns = $scfg->{namespace
})) {
631 $ns =~ s
|/|%2f|g
; # other characters to escape aren't allowed in the namespace schema
635 return ($path, $vmid, $vtype);
639 my ($class, $storeid, $scfg, $volname) = @_;
641 die "can't create base images in pbs storage\n";
645 my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
647 die "can't clone images in pbs storage\n";
651 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
653 die "can't allocate space in pbs storage\n";
657 my ($class, $storeid, $scfg, $volname, $isBase) = @_;
659 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
661 run_client_cmd
($scfg, $storeid, "forget", [ $name ], 1);
668 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
675 my sub snapshot_files_encrypted
{
681 for my $file (@$files) {
682 my $fn = $file->{filename
};
683 next if $fn eq 'client.log.blob' || $fn eq 'index.json.blob';
685 my $crypt = $file->{'crypt-mode'};
687 $all = 0 if !$crypt || $crypt ne 'encrypt';
688 $any ||= defined($crypt) && $crypt eq 'encrypt';
693 # TODO: use a client with native rust/proxmox-backup bindings to profit from
694 # API schema checks and types
695 my sub pbs_api_connect
{
696 my ($scfg, $password, $timeout) = @_;
700 my $user = $scfg->{username
} // 'root@pam';
702 if (my $tokenid = PVE
::AccessControl
::pve_verify_tokenid
($user, 1)) {
703 $params->{apitoken
} = "PBSAPIToken=${tokenid}:${password}";
705 $params->{password
} = $password;
706 $params->{username
} = $user;
709 if (my $fp = $scfg->{fingerprint
}) {
710 $params->{cached_fingerprints
}->{uc($fp)} = 1;
713 my $conn = PVE
::APIClient
::LWP-
>new(
715 host
=> $scfg->{server
},
716 port
=> $scfg->{port
} // 8007,
717 timeout
=> ($timeout // 7), # cope with a 401 (3s api delay) and high latency
718 cookie_name
=> 'PBSAuthCookie',
725 my ($class, $storeid, $scfg, $vmid, $content_types) = @_;
729 return $res if !grep { $_ eq 'backup' } @$content_types;
731 my $password = pbs_get_password
($scfg, $storeid);
732 my $conn = pbs_api_connect
($scfg, $password, 120);
733 my $datastore = $scfg->{datastore
};
736 $param->{'backup-id'} = "$vmid" if defined($vmid);
737 $param->{'ns'} = "$scfg->{namespace}" if defined($scfg->{namespace
});
738 my $data = eval { $conn->get("/api2/json/admin/datastore/$datastore/snapshots", $param); };
739 die "error listing snapshots - $@" if $@;
741 foreach my $item (@$data) {
742 my $btype = $item->{"backup-type"};
743 my $bid = $item->{"backup-id"};
744 my $epoch = $item->{"backup-time"};
745 my $size = $item->{size
} // 1;
747 next if !($btype eq 'vm' || $btype eq 'ct');
748 next if $bid !~ m/^\d+$/;
749 next if defined($vmid) && $bid ne $vmid;
751 my $volid = print_volid
($storeid, $btype, $bid, $epoch);
755 format
=> "pbs-$btype",
760 subtype
=> $btype eq 'vm' ?
'qemu' : 'lxc', # convert to PVE backup type
763 $info->{verification
} = $item->{verification
} if defined($item->{verification
});
764 $info->{notes
} = $item->{comment
} if defined($item->{comment
});
765 $info->{protected
} = 1 if $item->{protected
};
766 if (defined($item->{fingerprint
})) {
767 $info->{encrypted
} = $item->{fingerprint
};
768 } elsif (snapshot_files_encrypted
($item->{files
})) {
769 $info->{encrypted
} = '1';
779 my ($class, $storeid, $scfg, $cache) = @_;
787 my $res = run_client_cmd
($scfg, $storeid, "status");
790 $total = $res->{total
};
791 $used = $res->{used
};
792 $free = $res->{avail
};
798 return ($total, $free, $used, $active);
801 # can also be used for not (yet) added storages, pass $scfg with
805 # port (optional default to 8007)
806 # fingerprint (optional for trusted certs)
808 sub scan_datastores
{
809 my ($scfg, $password) = @_;
811 my $conn = pbs_api_connect
($scfg, $password);
813 my $response = eval { $conn->get('/api2/json/admin/datastore', {}) };
814 die "error fetching datastores - $@" if $@;
819 sub activate_storage
{
820 my ($class, $storeid, $scfg, $cache) = @_;
822 my $password = pbs_get_password
($scfg, $storeid);
824 my $datastores = eval { scan_datastores
($scfg, $password) };
825 die "$storeid: $@" if $@;
827 my $datastore = $scfg->{datastore
};
829 for my $ds (@$datastores) {
830 if ($ds->{store
} eq $datastore) {
835 die "$storeid: Cannot find datastore '$datastore', check permissions and existence!\n";
838 sub deactivate_storage
{
839 my ($class, $storeid, $scfg, $cache) = @_;
843 sub activate_volume
{
844 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
846 die "volume snapshot is not possible on pbs device" if $snapname;
851 sub deactivate_volume
{
852 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
854 die "volume snapshot is not possible on pbs device" if $snapname;
859 # FIXME remove on the next APIAGE reset.
860 # Deprecated, use get_volume_attribute instead.
861 sub get_volume_notes
{
862 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
864 my (undef, $name, undef, undef, undef, undef, $format) = $class->parse_volname($volname);
866 my $data = run_client_cmd
($scfg, $storeid, "snapshot", [ "notes", "show", $name ]);
868 return $data->{notes
};
871 # FIXME remove on the next APIAGE reset.
872 # Deprecated, use update_volume_attribute instead.
873 sub update_volume_notes
{
874 my ($class, $scfg, $storeid, $volname, $notes, $timeout) = @_;
876 my (undef, $name, undef, undef, undef, undef, $format) = $class->parse_volname($volname);
878 run_client_cmd
($scfg, $storeid, "snapshot", [ "notes", "update", $name, $notes ], 1);
883 sub get_volume_attribute
{
884 my ($class, $scfg, $storeid, $volname, $attribute) = @_;
886 if ($attribute eq 'notes') {
887 return $class->get_volume_notes($scfg, $storeid, $volname);
890 if ($attribute eq 'protected') {
891 my $param = api_param_from_volname
($class, $scfg, $volname);
893 my $password = pbs_get_password
($scfg, $storeid);
894 my $conn = pbs_api_connect
($scfg, $password);
895 my $datastore = $scfg->{datastore
};
897 my $res = eval { $conn->get("/api2/json/admin/datastore/$datastore/$attribute", $param); };
899 return if $err->{code
} == 404; # not supported
908 sub update_volume_attribute
{
909 my ($class, $scfg, $storeid, $volname, $attribute, $value) = @_;
911 if ($attribute eq 'notes') {
912 return $class->update_volume_notes($scfg, $storeid, $volname, $value);
915 if ($attribute eq 'protected') {
916 my $param = api_param_from_volname
($class, $scfg, $volname);
917 $param->{$attribute} = $value;
919 my $password = pbs_get_password
($scfg, $storeid);
920 my $conn = pbs_api_connect
($scfg, $password);
921 my $datastore = $scfg->{datastore
};
923 eval { $conn->put("/api2/json/admin/datastore/$datastore/$attribute", $param); };
925 die "Server is not recent enough to support feature '$attribute'\n"
926 if $err->{code
} == 404;
932 die "attribute '$attribute' is not supported for storage type '$scfg->{type}'\n";
935 sub volume_size_info
{
936 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
938 my ($vtype, $name, undef, undef, undef, undef, $format) = $class->parse_volname($volname);
940 my $data = run_client_cmd
($scfg, $storeid, "files", [ $name ]);
943 foreach my $info (@$data) {
944 if ($info->{size
} && $info->{size
} =~ /^(\d+)$/) { # untaints
951 return wantarray ?
($size, $format, $used, undef) : $size;
955 my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
956 die "volume resize is not possible on pbs device";
959 sub volume_snapshot
{
960 my ($class, $scfg, $storeid, $volname, $snap) = @_;
961 die "volume snapshot is not possible on pbs device";
964 sub volume_snapshot_rollback
{
965 my ($class, $scfg, $storeid, $volname, $snap) = @_;
966 die "volume snapshot rollback is not possible on pbs device";
969 sub volume_snapshot_delete
{
970 my ($class, $scfg, $storeid, $volname, $snap) = @_;
971 die "volume snapshot delete is not possible on pbs device";
974 sub volume_has_feature
{
975 my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running) = @_;