]>
git.proxmox.com Git - pve-ha-manager.git/blob - src/ha-manager
10 use PVE
::JSONSchema
qw(get_standard_option);
15 use PVE
::API2
::HA
::Resources
;
16 use PVE
::API2
::HA
::Groups
;
17 use PVE
::HA
::Env
::PVE2
;
19 use base
qw(PVE::CLIHandler);
21 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
24 die "please run as root\n" if $> != 0;
26 my $nodename = PVE
::INotify
::nodename
();
28 __PACKAGE__-
>register_method ({
32 description
=> "Enable a HA resource.",
34 additionalProperties
=> 0,
36 sid
=> get_standard_option
('pve-ha-resource-id'),
39 returns
=> { type
=> 'null' },
43 # delete state (default is 'enabled')
44 PVE
::API2
::HA
::Resources-
>update({ sid
=> $param->{sid
}, delete => 'state' });
49 __PACKAGE__-
>register_method ({
53 description
=> "Disable a HA resource.",
55 additionalProperties
=> 0,
57 sid
=> get_standard_option
('pve-ha-resource-id'),
60 returns
=> { type
=> 'null' },
64 PVE
::API2
::HA
::Resources-
>update({ sid
=> $param->{sid
}, state => 'disabled' });
69 my $timestamp_to_status = sub {
70 my ($ctime, $timestamp) = @_;
72 my $tdiff = $ctime - $timestamp;
74 return "old timestamp - dead?";
75 } elsif ($tdiff < -2) {
76 return "detected time drift!";
82 __PACKAGE__-
>register_method ({
86 description
=> "Display HA manger status.",
88 additionalProperties
=> 0,
91 returns
=> { type
=> 'null' },
95 PVE
::Cluster
::check_cfs_quorum
();
97 my $haenv = PVE
::HA
::Env
::PVE2-
>new($nodename);
99 my $status = $haenv->read_manager_status();
101 my $ctime = $haenv->get_time();
103 my $master = $status->{master_node
};
104 my $status_str = &$timestamp_to_status($ctime, $status->{timestamp
});
106 print "master_node: $master ($status_str)\n";
107 my $time_str = localtime($status->{timestamp
});
108 print "last_update: $time_str\n";
110 foreach my $node (sort keys %{$status->{node_status
}}) {
111 my $d = $status->{node_status
}->{node
};
112 my $lrm_status = $haenv->read_lrm_status($node);
113 if (!$lrm_status->{timestamp
}) {
114 print "lrm_status: $node (unable to read lrm status)\n";
116 $status_str = &$timestamp_to_status($ctime, $lrm_status->{timestamp
});
117 my $time_str = localtime($lrm_status->{timestamp
});
118 print "lrm_status: $node ($status_str, $time_str)\n";
122 print "manager_status:\n";
123 print to_json
($status, { pretty
=> 1, canonical
=> 1} );
129 enable
=> [ __PACKAGE__
, 'enable', ['sid']],
130 disable
=> [ __PACKAGE__
, 'disable', ['sid']],
131 status
=> [ __PACKAGE__
, 'status'],
132 config
=> [ 'PVE::API2::HA::Resources', 'index', [], {}, sub {
134 foreach my $rec (sort { $a->{sid
} cmp $b->{sid
} } @$res) {
135 my ($type, $name) = split(':', $rec->{sid
}, 2);
136 print "$type:$name\n";
137 foreach my $k (sort keys %$rec) {
138 next if $k eq 'digest' || $k eq 'sid' ||
140 print "\t$k $rec->{$k}\n";
144 groups
=> [ 'PVE::API2::HA::Groups', 'index', [], {}, sub {
146 foreach my $rec (sort { $a->{group
} cmp $b->{group
} } @$res) {
147 print "group: $rec->{group}\n";
148 foreach my $k (sort keys %$rec) {
149 next if $k eq 'digest' || $k eq 'group' ||
151 print "\t$k $rec->{$k}\n";
155 add
=> [ "PVE::API2::HA::Resources", 'create', ['sid'] ],
156 remove
=> [ "PVE::API2::HA::Resources", 'delete', ['sid'] ],
157 set
=> [ "PVE::API2::HA::Resources", 'update', ['sid'] ],
159 migrate
=> [ "PVE::API2::HA::Resources", 'migrate', ['sid', 'node'] ],
160 relocate
=> [ "PVE::API2::HA::Resources", 'relocate', ['sid', 'node'] ],
166 if ($cmd && $cmd ne 'printmanpod' && $cmd ne 'verifyapi') {
167 PVE
::Cluster
::check_cfs_is_mounted
();
168 PVE
::Cluster
::cfs_update
();
171 PVE
::CLIHandler
::handle_cmd
($cmddef, "ha-manager", $cmd, \
@ARGV, undef, $0);
179 pvecm - Proxmox VE HA Command Line Interface
187 ha-manager is a program to manage the HA configuration.
189 =include pve_copyright