From 5ac6bd0e292136748fccdfd468eaf7b978c6c922 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 21 Feb 2017 09:29:45 +0100 Subject: [PATCH] add read-only API for cluster config --- Makefile | 1 + PMG/API2/ClusterConfig.pm | 47 +++++++++++++++++++++++++++++++++++++++ PMG/API2/Config.pm | 6 +++++ 3 files changed, 54 insertions(+) create mode 100644 PMG/API2/ClusterConfig.pm diff --git a/Makefile b/Makefile index 295463c..7c1d2c7 100644 --- a/Makefile +++ b/Makefile @@ -95,6 +95,7 @@ LIBSOURCES = \ PMG/API2/LDAP.pm \ PMG/API2/Domains.pm \ PMG/API2/Config.pm \ + PMG/API2/ClusterConfig.pm \ PMG/API2/Nodes.pm \ PMG/API2/AccessControl.pm \ PMG/API2/RuleDB.pm \ diff --git a/PMG/API2/ClusterConfig.pm b/PMG/API2/ClusterConfig.pm new file mode 100644 index 0000000..7f31500 --- /dev/null +++ b/PMG/API2/ClusterConfig.pm @@ -0,0 +1,47 @@ +package PMG::API2::ClusterConfig; + +use strict; +use warnings; +use Data::Dumper; + +use PVE::SafeSyslog; +use PVE::Tools qw(extract_param); +use HTTP::Status qw(:constants); +use Storable qw(dclone); +use PVE::JSONSchema qw(get_standard_option); +use PVE::RESTHandler; +use PVE::INotify; + +use PMG::ClusterConfig; + +use base qw(PVE::RESTHandler); + +__PACKAGE__->register_method({ + name => 'index', + path => '', + method => 'GET', + description => "Cluster node index.", + # alway read local file + parameters => { + additionalProperties => 0, + properties => {}, + }, + returns => { + type => 'array', + items => { + type => "object", + properties => { + cid => { type => 'integer' }, + }, + }, + links => [ { rel => 'child', href => "{cid}" } ], + }, + code => sub { + my ($param) = @_; + + my $cfg = PVE::INotify::read_file('cluster.conf'); + + return PVE::RESTHandler::hash_to_array($cfg->{ids}, 'cid'); + }}); + +1; diff --git a/PMG/API2/Config.pm b/PMG/API2/Config.pm index 97ad1c6..376e077 100644 --- a/PMG/API2/Config.pm +++ b/PMG/API2/Config.pm @@ -15,6 +15,7 @@ use PMG::Config; use PMG::API2::RuleDB; use PMG::API2::LDAP; use PMG::API2::Domains; +use PMG::API2::ClusterConfig; use base qw(PVE::RESTHandler); @@ -35,6 +36,10 @@ __PACKAGE__->register_method ({ path => 'domains', }); +__PACKAGE__->register_method ({ + subclass => "PMG::API2::ClusterConfig", + path => 'cluster', +}); __PACKAGE__->register_method ({ name => 'index', @@ -63,6 +68,7 @@ __PACKAGE__->register_method ({ push @$res, { section => 'ldap' }; push @$res, { section => 'domains' }; + push @$res, { section => 'cluster' }; push @$res, { section => 'ruledb' }; return $res; -- 2.39.2