]>
git.proxmox.com Git - pve-ha-manager.git/blob - src/PVE/CLI/ha_manager.pm
1 package PVE
::CLI
::ha_manager
;
9 use PVE
::JSONSchema
qw(get_standard_option);
12 use PVE
::Tools
qw(extract_param);
13 use PVE
::RPCEnvironment
;
15 use PVE
::HA
::Config
; # needed for bash completion in PVE::HA::Tools!
16 use PVE
::HA
::Env
::PVE2
;
18 use PVE
::API2
::HA
::Resources
;
19 use PVE
::API2
::HA
::Groups
;
20 use PVE
::API2
::HA
::Status
;
22 use base
qw(PVE::CLIHandler);
24 my $nodename = PVE
::INotify
::nodename
();
26 my $timestamp_to_status = sub {
27 my ($ctime, $timestamp) = @_;
29 my $tdiff = $ctime - $timestamp;
31 return "old timestamp - dead?";
32 } elsif ($tdiff < -2) {
33 return "detected time drift!";
39 sub setup_environment
{
40 PVE
::RPCEnvironment-
>setup_default_cli_env();
43 __PACKAGE__-
>register_method ({
47 description
=> "Display HA manger status.",
49 additionalProperties
=> 0,
52 description
=> "Verbose output. Include complete CRM and LRM status (JSON).",
59 returns
=> { type
=> 'null' },
63 my $res = PVE
::API2
::HA
::Status-
>status({});
64 foreach my $e (@$res) {
65 print "$e->{type} $e->{status}\n";
68 if ($param->{verbose
}) {
69 print "full cluster state:\n";
70 my $data = PVE
::API2
::HA
::Status-
>manager_status({});
71 print to_json
($data, { pretty
=> 1, canonical
=> 1} );
77 __PACKAGE__-
>register_method ({
81 description
=> "Request the service to be stopped.",
83 check
=> ['perm', '/', [ 'Sys.Console' ]],
86 additionalProperties
=> 0,
88 sid
=> get_standard_option
('pve-ha-resource-or-vm-id', {
89 completion
=> \
&PVE
::HA
::Tools
::complete_sid
92 description
=> "Timeout in seconds. If set to 0 a hard stop will be performed.",
98 returns
=> { type
=> 'null' },
102 my $sid = PVE
::HA
::Config
::parse_sid
(extract_param
($param, 'sid'));
104 PVE
::HA
::Config
::service_is_ha_managed
($sid);
106 PVE
::API2
::HA
::Resources
::check_service_state
($sid);
108 PVE
::HA
::Config
::queue_crm_commands
("stop $sid $param->{timeout}");
113 __PACKAGE__-
>register_method ({
114 name
=> 'node-maintenance-set',
115 path
=> 'node-maintenance-set',
117 description
=> "Change the node-maintenance request state.",
119 check
=> ['perm', '/', [ 'Sys.Console' ]],
122 additionalProperties
=> 0,
124 node
=> get_standard_option
('pve-node'),
126 description
=> "Requests disabling or enabling maintenance-mode.",
131 returns
=> { type
=> 'null' },
135 my $cmd = $param->{disable
} ?
'disable-node-maintenance' : 'enable-node-maintenance';
136 PVE
::HA
::Config
::queue_crm_commands
("$cmd $param->{node}");
143 status
=> [ __PACKAGE__
, 'status'],
144 config
=> [ 'PVE::API2::HA::Resources', 'index', [], {}, sub {
146 foreach my $rec (sort { $a->{sid
} cmp $b->{sid
} } @$res) {
147 my ($type, $name) = split(':', $rec->{sid
}, 2);
148 print "$type:$name\n";
149 foreach my $k (sort keys %$rec) {
150 next if $k eq 'digest' || $k eq 'sid' ||
151 $k eq 'type' || $k eq 'errors';
152 print "\t$k $rec->{$k}\n";
154 if (my $errors = $rec->{errors
}) {
155 foreach my $p (keys %$errors) {
156 warn "error: property '$p' - $errors->{$p}\n";
161 groupconfig
=> [ 'PVE::API2::HA::Groups', 'index', [], {}, sub {
163 foreach my $rec (sort { $a->{group
} cmp $b->{group
} } @$res) {
164 print "group: $rec->{group}\n";
165 foreach my $k (sort keys %$rec) {
166 next if $k eq 'digest' || $k eq 'group' ||
168 print "\t$k $rec->{$k}\n";
172 groupadd
=> [ "PVE::API2::HA::Groups", 'create', ['group'] ],
173 groupremove
=> [ "PVE::API2::HA::Groups", 'delete', ['group'] ],
174 groupset
=> [ "PVE::API2::HA::Groups", 'update', ['group'] ],
176 add
=> [ "PVE::API2::HA::Resources", 'create', ['sid'] ],
177 remove
=> [ "PVE::API2::HA::Resources", 'delete', ['sid'] ],
178 set
=> [ "PVE::API2::HA::Resources", 'update', ['sid'] ],
180 migrate
=> { alias
=> 'crm-command migrate' },
181 relocate
=> { alias
=> 'crm-command relocate' },
184 migrate
=> [ "PVE::API2::HA::Resources", 'migrate', ['sid', 'node'] ],
185 relocate
=> [ "PVE::API2::HA::Resources", 'relocate', ['sid', 'node'] ],
186 stop
=> [ __PACKAGE__
, 'stop', ['sid', 'timeout'] ],
187 'node-maintenance' => {
188 enable
=> [ __PACKAGE__
, 'node-maintenance-set', ['node'], { disable
=> 0 } ],
189 disable
=> [ __PACKAGE__
, 'node-maintenance-set', ['node'], { disable
=> 1 } ],