]> git.proxmox.com Git - pve-client.git/commitdiff
add missing file PVE/APIClient/Commands/config.pm
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 12 Jun 2018 10:06:46 +0000 (12:06 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 12 Jun 2018 10:06:46 +0000 (12:06 +0200)
PVE/APIClient/Commands/config.pm [new file with mode: 0644]

diff --git a/PVE/APIClient/Commands/config.pm b/PVE/APIClient/Commands/config.pm
new file mode 100644 (file)
index 0000000..4015ad8
--- /dev/null
@@ -0,0 +1,85 @@
+package PVE::APIClient::Commands::config;
+
+use strict;
+use warnings;
+use Data::Dumper;
+
+use PVE::JSONSchema qw(get_standard_option);
+use PVE::Tools qw(extract_param);
+use PVE::APIClient::Config;
+
+use PVE::CLIHandler;
+
+use base qw(PVE::CLIHandler);
+
+__PACKAGE__->register_method ({
+    name => 'list',
+    path => 'list',
+    method => 'GET',
+    description => "Dump default configuration.",
+    parameters => {
+       additionalProperties => 0,
+    },
+    returns => { type => 'null' },
+    code => sub {
+
+       my $config = PVE::APIClient::Config->load();
+       
+       my $defaults = PVE::APIClient::Config->get_defaults($config);
+
+       
+       print Dumper($config);
+       
+       return undef;
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'set',
+    path => 'set',
+    method => 'PUT',
+    description => "Update a remote configuration.",
+    parameters => PVE::APIClient::DefaultsConfig->updateSchema(1),
+    returns => { type => 'null'},
+    code => sub {
+       my ($param) = @_;
+
+       # fixme: lock config file
+
+       my $digest = extract_param($param, 'digest');
+       my $delete = extract_param($param, 'delete');
+
+       my $config = PVE::APIClient::Config->load();
+       my $defaults = PVE::APIClient::Config->get_defaults($config);
+       
+       my $plugin = PVE::APIClient::Config->lookup('defaults');
+       my $opts = $plugin->check_config('defaults', $param, 0, 1);
+
+       foreach my $k (%$opts) {
+           $defaults->{$k} = $opts->{$k};
+       }
+
+       if ($delete) {
+           my $options = $plugin->private()->{options}->{'defaults'};
+           foreach my $k (PVE::Tools::split_list($delete)) {
+               my $d = $options->{$k} ||
+                   die "no such option '$k'\n";
+               die "unable to delete required option '$k'\n"
+                   if !$d->{optional};
+               die "unable to delete fixed option '$k'\n"
+                   if $d->{fixed};
+               delete $defaults->{$k};
+           }
+       }
+
+       PVE::APIClient::Config->save($config);
+
+       return undef;
+    }});
+
+
+our $cmddef = {
+    set => [ __PACKAGE__, 'set',],
+    list => [__PACKAGE__, 'list'],
+};
+
+1;