]> git.proxmox.com Git - pmg-api.git/blob - PMG/API2/ClusterConfig.pm
bin/pmgcm: start cluster management toolkit + API
[pmg-api.git] / PMG / API2 / ClusterConfig.pm
1 package PMG::API2::ClusterConfig;
2
3 use strict;
4 use warnings;
5 use Data::Dumper;
6
7 use PVE::SafeSyslog;
8 use PVE::Tools qw(extract_param);
9 use HTTP::Status qw(:constants);
10 use Storable qw(dclone);
11 use PVE::JSONSchema qw(get_standard_option);
12 use PVE::RESTHandler;
13 use PVE::INotify;
14
15 use PMG::ClusterConfig;
16
17 use base qw(PVE::RESTHandler);
18
19 __PACKAGE__->register_method({
20 name => 'index',
21 path => '',
22 method => 'GET',
23 description => "Cluster node index.",
24 # alway read local file
25 parameters => {
26 additionalProperties => 0,
27 properties => {},
28 },
29 permissions => { check => [ 'admin' ] },
30 returns => {
31 type => 'array',
32 items => {
33 type => "object",
34 properties => {
35 cid => { type => 'integer' },
36 },
37 },
38 links => [ { rel => 'child', href => "{cid}" } ],
39 },
40 code => sub {
41 my ($param) = @_;
42
43 my $cfg = PVE::INotify::read_file('cluster.conf');
44
45 return PVE::RESTHandler::hash_to_array($cfg->{ids}, 'cid');
46 }});
47
48 __PACKAGE__->register_method({
49 name => 'create_master',
50 path => '',
51 method => 'POST',
52 description => "Create initial cluster config with current node as master.",
53 # alway read local file
54 parameters => {
55 additionalProperties => 0,
56 properties => {},
57 },
58 returns => { type => 'null' },
59 code => sub {
60 my ($param) = @_;
61
62 my $code = sub {
63 my $cfg = PMG::ClusterConfig->new();
64
65 die "cluster alreayd defined\n" if scalar(keys %{$cfg->{ids}});
66
67 my $info = PMG::Cluster::read_local_cluster_info();
68
69 $info->{type} = 'master';
70 $info->{maxcid} = 1,
71
72 $cfg->{ids}->{$info->{maxcid}} = $info;
73
74 $cfg->write();
75 };
76
77 PMG::ClusterConfig::lock_config($code, "create cluster failed");
78
79 return undef;
80 }});
81
82
83 1;