]>
git.proxmox.com Git - pve-manager.git/blob - PVE/API2/Cluster/BackupInfo.pm
1 package PVE
::API2
::Cluster
::BackupInfo
;
8 use PVE
::Tools
qw(extract_param);
9 use PVE
::Cluster
qw(cfs_lock_file cfs_read_file cfs_write_file);
11 use PVE
::RPCEnvironment
;
14 use PVE
::Exception
qw(raise_param_exc);
16 use PVE
::VZDump
::Common
;
18 use base
qw(PVE::RESTHandler);
20 sub get_included_vmids
{
21 my $legacy_vzdump_job_cfg = cfs_read_file
('vzdump.cron');
22 my $legacy_jobs = $legacy_vzdump_job_cfg->{jobs
} || [];
24 my $jobs = cfs_read_file
('jobs.cfg');
27 for my $job ($legacy_jobs->@*, grep { $_->{type
} eq 'vzdump' } values $jobs->{ids
}->%*) {
28 my $job_included_guests = PVE
::VZDump
::get_included_guests
($job);
29 $all_vmids->{$_} = 1 for map { $_->@* } values %{$job_included_guests};
35 __PACKAGE__-
>register_method({
39 description
=> "Index for backup info related endpoints",
41 additionalProperties
=> 0,
46 description
=> 'Directory index.',
52 description
=> 'API sub-directory endpoint',
56 links
=> [ { rel
=> 'child', href
=> "{subdir}" } ],
60 { subdir
=> 'not-backed-up' },
64 __PACKAGE__-
>register_method({
65 name
=> 'get_guests_not_in_backup',
66 path
=> 'not-backed-up',
69 description
=> "Shows all guests which are not covered by any backup job.",
71 check
=> ['perm', '/', ['Sys.Audit']],
74 additionalProperties
=> 0,
79 description
=> 'Contains the guest objects.',
85 description
=> 'VMID of the guest.',
89 description
=> 'Name of the guest',
94 description
=> 'Type of the guest.',
95 enum
=> ['qemu', 'lxc'],
101 my $rpcenv = PVE
::RPCEnvironment
::get
();
102 my $user = $rpcenv->get_user();
104 my $included_vmids = get_included_vmids
();
105 my $vmlist = PVE
::Cluster
::get_vmlist
();
106 my @vmids = ( keys %{$vmlist->{ids
}} );
108 # remove VMIDs to which the user has no permission to not leak infos
109 # like the guest name
110 my @allowed_vmids = grep {
111 $rpcenv->check($user, "/vms/$_", [ 'VM.Audit' ], 1);
116 for my $vmid (@allowed_vmids) {
118 next if $included_vmids->{$vmid};
120 my $type = $vmlist->{ids
}->{$vmid}->{type
};
121 my $node = $vmlist->{ids
}->{$vmid}->{node
};
126 if ($type eq 'qemu') {
127 $conf = PVE
::QemuConfig-
>load_config($vmid, $node);
128 $name = $conf->{name
};
129 } elsif ($type eq 'lxc') {
130 $conf = PVE
::LXC
::Config-
>load_config($vmid, $node);
131 $name = $conf->{hostname
};
133 die "VMID $vmid is neither Qemu nor LXC guest\n";