]> git.proxmox.com Git - pve-ha-manager.git/blob - src/ha-manager
improve API for resources
[pve-ha-manager.git] / src / ha-manager
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use PVE::INotify;
7 use PVE::JSONSchema;
8 use PVE::CLIHandler;
9 use PVE::Cluster;
10
11 use PVE::API2::HA::Resources;
12 use PVE::API2::HA::Groups;
13
14 use base qw(PVE::CLIHandler);
15
16 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
17 $ENV{LC_ALL} = 'C';
18
19 die "please run as root\n" if $> != 0;
20
21 my $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
42 my $cmddef = {
43 test => [ __PACKAGE__, 'test', []],
44 config => [ 'PVE::API2::HA::Resources', 'index', [], {}, sub {
45 my $res = shift;
46 foreach my $rec (sort { $a->{sid} cmp $b->{sid} } @$res) {
47 my ($type, $name) = split(':', $rec->{sid}, 2);
48 print "$type: $name\n";
49 foreach my $k (sort keys %$rec) {
50 next if $k eq 'digest' || $k eq 'sid' ||
51 $k eq 'type';
52 print "\t$k $rec->{$k}\n";
53 }
54 print "\n";
55 }}],
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 }}],
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
71 };
72
73 my $cmd = shift;
74
75 if ($cmd && $cmd ne 'printmanpod' && $cmd ne 'verifyapi') {
76 PVE::Cluster::check_cfs_is_mounted();
77 PVE::Cluster::cfs_update();
78 }
79
80 PVE::CLIHandler::handle_cmd($cmddef, "ha-manager", $cmd, \@ARGV, undef, $0);
81
82 exit 0;
83
84 __END__
85
86 =head1 NAME
87
88 pvecm - Proxmox VE HA Command Line Interface
89
90 =head1 SYNOPSIS
91
92 =include synopsis
93
94 =head1 DESCRIPTION
95
96 ha-manager is a program to manage the HA configuration.
97
98 =include pve_copyright
99
100