]> git.proxmox.com Git - pve-ha-manager.git/blob - src/PVE/API2/HA/Groups.pm
start API for groups
[pve-ha-manager.git] / src / PVE / API2 / HA / Groups.pm
1 package PVE::API2::HA::Groups;
2
3 use strict;
4 use warnings;
5
6 use PVE::SafeSyslog;
7 use PVE::Tools qw(extract_param);
8 use PVE::Cluster qw(cfs_read_file cfs_write_file);
9 use PVE::HA::Config;
10 use HTTP::Status qw(:constants);
11 use Storable qw(dclone);
12 use PVE::JSONSchema qw(get_standard_option);
13 use PVE::RPCEnvironment;
14
15 use PVE::RESTHandler;
16
17 use base qw(PVE::RESTHandler);
18
19 # fixme: use cfs_read_file
20
21 my $ha_groups_config = "/etc/pve/ha/groups.cfg";
22
23 # fixme: fix permissions
24
25 my $api_copy_config = sub {
26 my ($cfg, $sid) = @_;
27
28 my $scfg = dclone($cfg->{ids}->{$sid});
29 $scfg->{group} = $sid;
30 $scfg->{digest} = $cfg->{digest};
31
32 return $scfg;
33 };
34
35 __PACKAGE__->register_method ({
36 name => 'index',
37 path => '',
38 method => 'GET',
39 description => "Get HA groups.",
40 parameters => {
41 additionalProperties => 0,
42 properties => {},
43 },
44 returns => {
45 type => 'array',
46 items => {
47 type => "object",
48 properties => { group => { type => 'string'} },
49 },
50 links => [ { rel => 'child', href => "{group}" } ],
51 },
52 code => sub {
53 my ($param) = @_;
54
55 my $raw = '';
56
57 $raw = PVE::Tools::file_get_contents($ha_groups_config)
58 if -f $ha_groups_config;
59
60 my $cfg = PVE::HA::Config::parse_groups_config($ha_groups_config, $raw);
61
62 my $res = [];
63 foreach my $sid (keys %{$cfg->{ids}}) {
64 my $scfg = &$api_copy_config($cfg, $sid);
65 next if $scfg->{type} ne 'group'; # should not happen
66 push @$res, $scfg;
67 }
68
69 return $res;
70 }});
71
72
73 1;