]> git.proxmox.com Git - pve-ha-manager.git/blob - src/PVE/CLI/ha_manager.pm
clean up 'Data::Dumper' usage tree wide
[pve-ha-manager.git] / src / PVE / CLI / ha_manager.pm
1 package PVE::CLI::ha_manager;
2
3 use strict;
4 use warnings;
5
6 use PVE::INotify;
7 use JSON;
8
9 use PVE::JSONSchema qw(get_standard_option);
10 use PVE::CLIHandler;
11 use PVE::Cluster;
12 use PVE::RPCEnvironment;
13
14 use PVE::HA::Env::PVE2;
15 use PVE::HA::Tools;
16 use PVE::HA::Config;
17 use PVE::API2::HA::Resources;
18 use PVE::API2::HA::Groups;
19 use PVE::API2::HA::Status;
20
21 use base qw(PVE::CLIHandler);
22
23 my $nodename = PVE::INotify::nodename();
24
25 my $timestamp_to_status = sub {
26 my ($ctime, $timestamp) = @_;
27
28 my $tdiff = $ctime - $timestamp;
29 if ($tdiff > 30) {
30 return "old timestamp - dead?";
31 } elsif ($tdiff < -2) {
32 return "detected time drift!";
33 } else {
34 return "active";
35 }
36 };
37
38 sub setup_environment {
39 PVE::RPCEnvironment->setup_default_cli_env();
40 }
41
42 __PACKAGE__->register_method ({
43 name => 'status',
44 path => 'status',
45 method => 'GET',
46 description => "Display HA manger status.",
47 parameters => {
48 additionalProperties => 0,
49 properties => {
50 verbose => {
51 description => "Verbose output. Include complete CRM and LRM status (JSON).",
52 type => 'boolean',
53 default => 0,
54 optional => 1,
55 }
56 },
57 },
58 returns => { type => 'null' },
59 code => sub {
60 my ($param) = @_;
61
62 my $res = PVE::API2::HA::Status->status({});
63 foreach my $e (@$res) {
64 print "$e->{type} $e->{status}\n";
65 }
66
67 if ($param->{verbose}) {
68 print "full cluster state:\n";
69 my $data = PVE::API2::HA::Status->manager_status({});
70 print to_json($data, { pretty => 1, canonical => 1} );
71 }
72
73 return undef;
74 }});
75
76 our $cmddef = {
77 status => [ __PACKAGE__, 'status'],
78 config => [ 'PVE::API2::HA::Resources', 'index', [], {}, sub {
79 my $res = shift;
80 foreach my $rec (sort { $a->{sid} cmp $b->{sid} } @$res) {
81 my ($type, $name) = split(':', $rec->{sid}, 2);
82 print "$type:$name\n";
83 foreach my $k (sort keys %$rec) {
84 next if $k eq 'digest' || $k eq 'sid' ||
85 $k eq 'type' || $k eq 'errors';
86 print "\t$k $rec->{$k}\n";
87 }
88 if (my $errors = $rec->{errors}) {
89 foreach my $p (keys %$errors) {
90 warn "error: property '$p' - $errors->{$p}\n";
91 }
92 }
93 print "\n";
94 }}],
95 groupconfig => [ 'PVE::API2::HA::Groups', 'index', [], {}, sub {
96 my $res = shift;
97 foreach my $rec (sort { $a->{group} cmp $b->{group} } @$res) {
98 print "group: $rec->{group}\n";
99 foreach my $k (sort keys %$rec) {
100 next if $k eq 'digest' || $k eq 'group' ||
101 $k eq 'type';
102 print "\t$k $rec->{$k}\n";
103 }
104 print "\n";
105 }}],
106 groupadd => [ "PVE::API2::HA::Groups", 'create', ['group'] ],
107 groupremove => [ "PVE::API2::HA::Groups", 'delete', ['group'] ],
108 groupset => [ "PVE::API2::HA::Groups", 'update', ['group'] ],
109
110 add => [ "PVE::API2::HA::Resources", 'create', ['sid'] ],
111 remove => [ "PVE::API2::HA::Resources", 'delete', ['sid'] ],
112 set => [ "PVE::API2::HA::Resources", 'update', ['sid'] ],
113
114 migrate => [ "PVE::API2::HA::Resources", 'migrate', ['sid', 'node'] ],
115 relocate => [ "PVE::API2::HA::Resources", 'relocate', ['sid', 'node'] ],
116
117 };
118
119 1;