]> git.proxmox.com Git - pmg-api.git/commitdiff
add configuration API
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 17 Feb 2017 16:13:25 +0000 (17:13 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 17 Feb 2017 16:32:48 +0000 (17:32 +0100)
PMG/API2/Config.pm [new file with mode: 0644]
PMG/API2/Nodes.pm

diff --git a/PMG/API2/Config.pm b/PMG/API2/Config.pm
new file mode 100644 (file)
index 0000000..05a8a79
--- /dev/null
@@ -0,0 +1,76 @@
+package PMG::API2::Config;
+
+use strict;
+use warnings;
+
+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 PMG::Config;
+
+use base qw(PVE::RESTHandler);
+
+my $section_type_enum = PMG::Config::Base->lookup_types();
+
+__PACKAGE__->register_method ({
+    name => 'index', 
+    path => '',
+    method => 'GET',
+    description => "Directory index.",
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           node => get_standard_option('pve-node'),
+       },
+    },
+    returns => {
+       type => 'array',
+       items => {
+           type => "object",
+           properties => { section => { type => 'string'} },
+       },
+       links => [ { rel => 'child', href => "{section}" } ],
+    },
+    code => sub {
+       my ($param) = @_;
+
+       my $res = [];
+       foreach my $section (@$section_type_enum) {
+           push @$res, { section => $section };
+       }   
+       return $res;
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'read_section',
+    path => '{section}',
+    method => 'GET',
+    description => "Read configuration properties.",
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           node => get_standard_option('pve-node'),
+           section => {
+               description => "Section name.",
+               type => 'string',
+               enum => $section_type_enum,
+           },
+       },
+    },
+    returns => { type => 'object' },
+    code => sub {
+       my ($param) = @_;
+
+       my $cfg = PMG::Config->new();
+       my $section = $param->{section};
+
+       my $data = dclone($cfg->{ids}->{"section_$section"});
+       $data->{digest} = $cfg->{digest};
+       delete $data->{type};
+
+       return $data;
+    }});
index 479fc69c0e0ec09764cc062b24b867a1584b02f6..3a5cfcc3252c146e7be2afe63f633e99410e4da9 100644 (file)
@@ -16,9 +16,15 @@ use PMG::API2::Tasks;
 use PMG::API2::Services;
 use PMG::API2::Network;
 use PMG::API2::RuleDB;
+use PMG::API2::Config;
 
 use base qw(PVE::RESTHandler);
 
+__PACKAGE__->register_method ({
+    subclass => "PMG::API2::Config",
+    path => 'config',
+});
+
 __PACKAGE__->register_method ({
     subclass => "PMG::API2::RuleDB",
     path => 'ruledb',
@@ -63,6 +69,7 @@ __PACKAGE__->register_method ({
        my ($param) = @_;
 
        my $result = [
+           { name => 'config' },
            { name => 'ruledb' },
            { name => 'services' },
            { name => 'syslog' },