]>
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
::API2
::HA
::Status
;
18 use PVE
::HA
::Env
::PVE2
;
20 use base
qw(PVE::CLIHandler);
22 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
25 die "please run as root\n" if $> != 0;
27 my $nodename = PVE
::INotify
::nodename
();
29 __PACKAGE__-
>register_method ({
33 description
=> "Enable a HA resource.",
35 additionalProperties
=> 0,
37 sid
=> get_standard_option
('pve-ha-resource-or-vm-id'),
40 returns
=> { type
=> 'null' },
44 my $sid = PVE
::HA
::Tools
::parse_sid
($param->{sid
});
46 # delete state (default is 'enabled')
47 PVE
::API2
::HA
::Resources-
>update({ sid
=> $sid, delete => 'state' });
52 __PACKAGE__-
>register_method ({
56 description
=> "Disable a HA resource.",
58 additionalProperties
=> 0,
60 sid
=> get_standard_option
('pve-ha-resource-or-vm-id'),
63 returns
=> { type
=> 'null' },
67 my $sid = PVE
::HA
::Tools
::parse_sid
($param->{sid
});
69 PVE
::API2
::HA
::Resources-
>update({ sid
=> $sid, state => 'disabled' });
74 my $timestamp_to_status = sub {
75 my ($ctime, $timestamp) = @_;
77 my $tdiff = $ctime - $timestamp;
79 return "old timestamp - dead?";
80 } elsif ($tdiff < -2) {
81 return "detected time drift!";
87 __PACKAGE__-
>register_method ({
91 description
=> "Display HA manger status.",
93 additionalProperties
=> 0,
96 description
=> "Verbose output. Include complete CRM and LRM status (JSON).",
103 returns
=> { type
=> 'null' },
107 my $res = PVE
::API2
::HA
::Status-
>status({});
108 foreach my $e (@$res) {
109 print "$e->{type} $e->{status}\n";
112 if ($param->{verbose
}) {
113 print "full cluster state:\n";
114 my $data = PVE
::API2
::HA
::Status-
>manager_status({});
115 print to_json
($data, { pretty
=> 1, canonical
=> 1} );
122 enable
=> [ __PACKAGE__
, 'enable', ['sid']],
123 disable
=> [ __PACKAGE__
, 'disable', ['sid']],
124 status
=> [ __PACKAGE__
, 'status'],
125 config
=> [ 'PVE::API2::HA::Resources', 'index', [], {}, sub {
127 foreach my $rec (sort { $a->{sid
} cmp $b->{sid
} } @$res) {
128 my ($type, $name) = split(':', $rec->{sid
}, 2);
129 print "$type:$name\n";
130 foreach my $k (sort keys %$rec) {
131 next if $k eq 'digest' || $k eq 'sid' ||
132 $k eq 'type' || $k eq 'errors';
133 print "\t$k $rec->{$k}\n";
135 if (my $errors = $rec->{errors
}) {
136 foreach my $p (keys %$errors) {
137 warn "error: property '$p' - $errors->{$p}\n";
142 groups
=> [ 'PVE::API2::HA::Groups', 'index', [], {}, sub {
144 foreach my $rec (sort { $a->{group
} cmp $b->{group
} } @$res) {
145 print "group: $rec->{group}\n";
146 foreach my $k (sort keys %$rec) {
147 next if $k eq 'digest' || $k eq 'group' ||
149 print "\t$k $rec->{$k}\n";
153 add
=> [ "PVE::API2::HA::Resources", 'create', ['sid'] ],
154 remove
=> [ "PVE::API2::HA::Resources", 'delete', ['sid'] ],
155 set
=> [ "PVE::API2::HA::Resources", 'update', ['sid'] ],
157 migrate
=> [ "PVE::API2::HA::Resources", 'migrate', ['sid', 'node'] ],
158 relocate
=> [ "PVE::API2::HA::Resources", 'relocate', ['sid', 'node'] ],
164 if ($cmd && $cmd ne 'printmanpod' && $cmd ne 'verifyapi') {
165 PVE
::Cluster
::check_cfs_is_mounted
();
166 PVE
::Cluster
::cfs_update
();
169 PVE
::CLIHandler
::handle_cmd
($cmddef, "ha-manager", $cmd, \
@ARGV, undef, $0);
177 pvecm - Proxmox VE HA Command Line Interface
185 ha-manager is a program to manage the HA configuration.
187 =include pve_copyright