]> git.proxmox.com Git - pve-manager.git/blob - PVE/API2/Replication.pm
use correct field for child link
[pve-manager.git] / PVE / API2 / Replication.pm
1 package PVE::API2::Replication;
2
3 use warnings;
4 use strict;
5
6 use PVE::JSONSchema qw(get_standard_option);
7 use PVE::RPCEnvironment;
8 use PVE::ProcFSTools;
9 use PVE::ReplicationConfig;
10 use PVE::Replication;
11
12 use PVE::RESTHandler;
13
14 use base qw(PVE::RESTHandler);
15
16 __PACKAGE__->register_method ({
17 name => 'index',
18 path => '',
19 method => 'GET',
20 permissions => { user => 'all' },
21 description => "Directory index.",
22 parameters => {
23 additionalProperties => 0,
24 properties => {
25 node => get_standard_option('pve-node'),
26 },
27 },
28 returns => {
29 type => 'array',
30 items => {
31 type => "object",
32 properties => {},
33 },
34 links => [ { rel => 'child', href => "{name}" } ],
35 },
36 code => sub {
37 my ($param) = @_;
38
39 return [
40 { name => 'status' },
41 ];
42 }});
43
44
45 __PACKAGE__->register_method ({
46 name => 'status',
47 path => 'status',
48 method => 'GET',
49 description => "List replication job status.",
50 permissions => {
51 description => "Requires the VM.Audit permission on /vms/<vmid>.",
52 user => 'all',
53 },
54 protected => 1,
55 proxyto => 'node',
56 parameters => {
57 additionalProperties => 0,
58 properties => {
59 node => get_standard_option('pve-node'),
60 guest => get_standard_option('pve-vmid', {
61 optional => 1,
62 description => "Only list replication jobs for this guest.",
63 }),
64 },
65 },
66 returns => {
67 type => 'array',
68 items => {
69 type => "object",
70 properties => {},
71 },
72 links => [ { rel => 'child', href => "{id}" } ],
73 },
74 code => sub {
75 my ($param) = @_;
76
77 my $rpcenv = PVE::RPCEnvironment::get();
78 my $authuser = $rpcenv->get_user();
79
80 my $jobs = PVE::Replication::job_status();
81
82 my $res = [];
83 foreach my $id (sort keys %$jobs) {
84 my $d = $jobs->{$id};
85 my $state = delete $d->{state};
86 my $guest = $d->{guest};
87 next if defined($param->{guest}) && $guest != $param->{guest};
88 next if !$rpcenv->check($authuser, "/vms/$guest", [ 'VM.Audit' ]);
89 $d->{id} = $id;
90 foreach my $k (qw(last_sync last_try fail_count error duration)) {
91 $d->{$k} = $state->{$k} if defined($state->{$k});
92 }
93 if ($state->{pid} && $state->{ptime}) {
94 if (PVE::ProcFSTools::check_process_running($state->{pid}, $state->{ptime})) {
95 $d->{pid} = $state->{pid};
96 }
97 }
98 push @$res, $d;
99 }
100
101 return $res;
102 }});
103
104 1;