]>
git.proxmox.com Git - pve-ha-manager.git/blob - src/PVE/API2/HA/Status.pm
1 package PVE
::API2
::HA
::Status
;
10 use PVE
::JSONSchema
qw(get_standard_option);
11 use PVE
::RPCEnvironment
;
12 use PVE
::HA
::Env
::PVE2
;
16 use base
qw(PVE::RESTHandler);
18 my $nodename = PVE
::INotify
::nodename
();
20 my $timestamp_to_status = sub {
21 my ($ctime, $timestamp) = @_;
23 my $tdiff = $ctime - $timestamp;
25 return "old timestamp - dead?";
26 } elsif ($tdiff < -2) {
27 return "detected time drift!";
33 __PACKAGE__-
>register_method ({
37 permissions
=> { user
=> 'all' },
38 description
=> "Directory index.",
40 additionalProperties
=> 0,
49 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
55 { name
=> 'current' },
56 { name
=> 'manager_status' },
62 __PACKAGE__-
>register_method ({
66 description
=> "Get HA manger status.",
68 check
=> ['perm', '/', [ 'Sys.Audit' ]],
71 additionalProperties
=> 0,
74 returns
=> { type
=> 'array' },
80 my $quorate = PVE
::Cluster
::check_cfs_quorum
(1);
82 push @$res, { id
=> 'quorum', type
=> 'quorum',
83 node
=> $nodename, status
=> "OK", quorate
=> 1 };
85 push @$res, { id
=> 'quorum', type
=> 'quorum', node
=> $nodename,
86 status
=> "No quorum on node '$nodename'!", quorate
=> 0 };
89 my $haenv = PVE
::HA
::Env
::PVE2-
>new($nodename);
91 my $status = $haenv->read_manager_status();
93 my $service_config = $haenv->read_service_config();
95 my $ctime = $haenv->get_time();
97 if (defined($status->{master_node
}) && defined($status->{timestamp
})) {
98 my $master = $status->{master_node
};
99 my $status_str = &$timestamp_to_status($ctime, $status->{timestamp
});
100 # mark crm idle if it has no service configured and is not active
101 if ($quorate && $status_str ne 'active' && !keys %{$service_config}) {
102 $status_str = 'idle';
104 my $time_str = localtime($status->{timestamp
});
105 my $status_text = "$master ($status_str, $time_str)";
106 push @$res, { id
=> 'master', type
=> 'master', node
=> $master,
107 status
=> $status_text, timestamp
=> $status->{timestamp
} };
110 # compute active services for all nodes
111 my $active_count = {};
112 foreach my $sid (sort keys %{$status->{service_status
}}) {
113 my $sd = $status->{service_status
}->{$sid};
114 next if !$sd->{node
};
115 $active_count->{$sd->{node
}} = 0 if !defined($active_count->{$sd->{node
}});
116 my $req_state = $sd->{state};
117 next if !defined($req_state);
118 next if $req_state eq 'stopped';
119 next if $req_state eq 'freeze';
120 $active_count->{$sd->{node
}}++;
123 foreach my $node (sort keys %{$status->{node_status
}}) {
124 my $lrm_status = $haenv->read_lrm_status($node);
125 my $id = "lrm:$node";
126 if (!$lrm_status->{timestamp
}) {
127 push @$res, { id
=> $id, type
=> 'lrm', node
=> $node,
128 status
=> "$node (unable to read lrm status)"};
130 my $status_str = &$timestamp_to_status($ctime, $lrm_status->{timestamp
});
131 if ($status_str eq 'active') {
132 my $lrm_mode = $lrm_status->{mode
} || 'active';
133 my $lrm_state = $lrm_status->{state} || 'unknown';
134 if ($lrm_mode ne 'active') {
135 $status_str = "$lrm_mode mode";
137 if ($lrm_state eq 'wait_for_agent_lock' && !$active_count->{$node}) {
138 $status_str = 'idle';
140 $status_str = $lrm_state;
145 my $time_str = localtime($lrm_status->{timestamp
});
146 my $status_text = "$node ($status_str, $time_str)";
147 push @$res, { id
=> $id, type
=> 'lrm', node
=> $node,
148 status
=> $status_text, timestamp
=> $lrm_status->{timestamp
} };
152 foreach my $sid (sort keys %{$status->{service_status
}}) {
153 my $d = $status->{service_status
}->{$sid};
154 push @$res, { id
=> "service:$sid", type
=> 'service', sid
=> $sid,
155 node
=> $d->{node
}, status
=> "$sid ($d->{node}, $d->{state})" };
158 # show also service which aren't yet processed by the CRM
159 foreach my $sid (sort keys %$service_config) {
160 next if $status->{service_status
}->{$sid};
161 my $d = $service_config->{$sid};
162 push @$res, { id
=> "service:$sid", type
=> 'service', sid
=> $sid,
163 status
=> "$sid ($d->{node}, queued)",
164 node
=> $d->{node
} };
170 __PACKAGE__-
>register_method ({
171 name
=> 'manager_status',
172 path
=> 'manager_status',
174 description
=> "Get full HA manger status, including LRM status.",
176 check
=> ['perm', '/', [ 'Sys.Audit' ]],
179 additionalProperties
=> 0,
182 returns
=> { type
=> 'object' },
186 my $haenv = PVE
::HA
::Env
::PVE2-
>new($nodename);
188 my $status = $haenv->read_manager_status();
190 my $data = { manager_status
=> $status };
194 quorate
=> PVE
::Cluster
::check_cfs_quorum
(1),
197 foreach my $node (sort keys %{$status->{node_status
}}) {
198 my $lrm_status = $haenv->read_lrm_status($node);
199 $data->{lrm_status
}->{$node} = $lrm_status;