]> git.proxmox.com Git - pve-ha-manager.git/blame - src/ha-manager
improve API for resources
[pve-ha-manager.git] / src / ha-manager
CommitLineData
aab4f80b
DM
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use PVE::INotify;
7use PVE::JSONSchema;
8use PVE::CLIHandler;
9use PVE::Cluster;
10
239a687f 11use PVE::API2::HA::Resources;
7252f28d 12use PVE::API2::HA::Groups;
239a687f 13
aab4f80b
DM
14use base qw(PVE::CLIHandler);
15
16$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
17$ENV{LC_ALL} = 'C';
18
19die "please run as root\n" if $> != 0;
20
21my $nodename = PVE::INotify::nodename();
22
23__PACKAGE__->register_method ({
24 name => 'test',
25 path => 'test',
26 method => 'GET',
27 description => "A stupid test.",
28 parameters => {
29 additionalProperties => 0,
30 properties => {
31 },
32 },
33 returns => { type => 'null' },
34 code => sub {
35 my ($param) = @_;
36
37 print "TEST\n";
38
39 return undef;
40 }});
41
42my $cmddef = {
43 test => [ __PACKAGE__, 'test', []],
239a687f
DM
44 config => [ 'PVE::API2::HA::Resources', 'index', [], {}, sub {
45 my $res = shift;
95ea5d67
DM
46 foreach my $rec (sort { $a->{sid} cmp $b->{sid} } @$res) {
47 my ($type, $name) = split(':', $rec->{sid}, 2);
48 print "$type: $name\n";
7252f28d 49 foreach my $k (sort keys %$rec) {
239a687f 50 next if $k eq 'digest' || $k eq 'sid' ||
95ea5d67 51 $k eq 'type';
239a687f
DM
52 print "\t$k $rec->{$k}\n";
53 }
54 print "\n";
55 }}],
7252f28d
DM
56 groups => [ 'PVE::API2::HA::Groups', 'index', [], {}, sub {
57 my $res = shift;
58 foreach my $rec (sort { $a->{group} cmp $b->{group} } @$res) {
59 print "group: $rec->{group}\n";
60 foreach my $k (sort keys %$rec) {
61 next if $k eq 'digest' || $k eq 'group' ||
62 $k eq 'type';
63 print "\t$k $rec->{$k}\n";
64 }
65 print "\n";
66 }}],
95ea5d67
DM
67 add => [ "PVE::API2::HA::Resources", 'create', ['sid'] ],
68 remove => [ "PVE::API2::HA::Resources", 'delete', ['sid'] ],
69 set => [ "PVE::API2::HA::Resources", 'update', ['sid'] ],
70
aab4f80b 71};
239a687f 72
aab4f80b
DM
73my $cmd = shift;
74
75if ($cmd && $cmd ne 'printmanpod' && $cmd ne 'verifyapi') {
76 PVE::Cluster::check_cfs_is_mounted();
77 PVE::Cluster::cfs_update();
78}
79
80PVE::CLIHandler::handle_cmd($cmddef, "ha-manager", $cmd, \@ARGV, undef, $0);
81
82exit 0;
83
84__END__
85
86=head1 NAME
87
88pvecm - Proxmox VE HA Command Line Interface
89
90=head1 SYNOPSIS
91
92=include synopsis
93
94=head1 DESCRIPTION
95
96ha-manager is a program to manage the HA configuration.
97
98=include pve_copyright
99
100