[pve-devel] [PATCH pve-client v2] Add per remote configurable defaults
René Jochum
r.jochum at proxmox.com
Thu Jun 21 09:07:28 CEST 2018
Signed-off-by: René Jochum <r.jochum at proxmox.com>
---
v2 Makes defaults configureable per "remote".
PVE/APIClient/Commands/config.pm | 26 ++++++++++++++++++--------
PVE/APIClient/Commands/lxc.pm | 16 ++++++++++++++--
PVE/APIClient/Config.pm | 29 +++++++++++++++++++++++------
3 files changed, 55 insertions(+), 16 deletions(-)
diff --git a/PVE/APIClient/Commands/config.pm b/PVE/APIClient/Commands/config.pm
index 3b208a0..c620c6e 100644
--- a/PVE/APIClient/Commands/config.pm
+++ b/PVE/APIClient/Commands/config.pm
@@ -13,6 +13,15 @@ use PVE::APIClient::CLIHandler;
use base qw(PVE::APIClient::CLIHandler);
+my $add_remote = sub {
+ my ($params) = @_;
+
+ my $resprops = $params->{properties};
+ $resprops->{remote} = get_standard_option('pveclient-remote-name');
+
+ return {properties => $resprops};
+};
+
__PACKAGE__->register_method ({
name => 'list',
path => 'list',
@@ -39,27 +48,28 @@ __PACKAGE__->register_method ({
path => 'set',
method => 'PUT',
description => "Update a remote configuration.",
- parameters => PVE::APIClient::DefaultsConfig->updateSchema(1),
+ parameters => $add_remote->(PVE::APIClient::RemoteConfig->updateSchema(1)),
returns => { type => 'null'},
code => sub {
my ($param) = @_;
+ my $remote = extract_param($param, 'remote');
my $digest = extract_param($param, 'digest');
my $delete = extract_param($param, 'delete');
my $code = sub {
my $config = PVE::APIClient::Config->load();
- my $defaults = PVE::APIClient::Config->get_defaults($config);
+ my $remote_config = PVE::APIClient::Config->lookup_remote($config, $remote);
- my $plugin = PVE::APIClient::Config->lookup('defaults');
- my $opts = $plugin->check_config('defaults', $param, 0, 1);
+ my $plugin = PVE::APIClient::Config->lookup('remote');
+ my $opts = $plugin->check_config($param->{remote}, $param, 0, 1);
foreach my $k (%$opts) {
- $defaults->{$k} = $opts->{$k};
+ $remote_config->{$k} = $opts->{$k};
}
if ($delete) {
- my $options = $plugin->private()->{options}->{'defaults'};
+ my $options = $plugin->private()->{options}->{'remote'};
foreach my $k (PVE::APIClient::Tools::split_list($delete)) {
my $d = $options->{$k} ||
die "no such option '$k'\n";
@@ -67,7 +77,7 @@ __PACKAGE__->register_method ({
if !$d->{optional};
die "unable to delete fixed option '$k'\n"
if $d->{fixed};
- delete $defaults->{$k};
+ delete $remote_config->{$k};
}
}
@@ -81,7 +91,7 @@ __PACKAGE__->register_method ({
our $cmddef = {
- set => [ __PACKAGE__, 'set',],
+ set => [ __PACKAGE__, 'set', ['remote']],
list => [__PACKAGE__, 'list'],
};
diff --git a/PVE/APIClient/Commands/lxc.pm b/PVE/APIClient/Commands/lxc.pm
index 3add2dd..0601453 100644
--- a/PVE/APIClient/Commands/lxc.pm
+++ b/PVE/APIClient/Commands/lxc.pm
@@ -428,7 +428,12 @@ __PACKAGE__->register_method ({
'/nodes/{node}/lxc', 'POST', {
remote => get_standard_option('pveclient-remote-name'),
vmid => get_standard_option('pve-vmid'),
- node => get_standard_option('pve-node'),
+ node => {
+ description => "The cluster node name.",
+ type => 'string', format => 'pve-node',
+ optional => 1,
+ default => 'localhost | default node'
+ },
quiet => {
description => "Suppress log output.",
type => 'boolean',
@@ -453,6 +458,13 @@ __PACKAGE__->register_method ({
my $background = PVE::APIClient::Tools::extract_param($param, 'background');
my $config = PVE::APIClient::Config->load();
+ my $remote_config = PVE::APIClient::Config->lookup_remote($config, $remote);
+
+ if (!$node) {
+ $node = $remote_config->{default_node} // 'localhost';
+ }
+ $param->{storage} = $param->{storage} // $remote_config->{default_storage} // 'local';
+
my $conn = PVE::APIClient::Config->remote_conn($config, $remote);
my $upid = $conn->post("/nodes/$node/lxc", $param);
@@ -496,7 +508,7 @@ __PACKAGE__->register_method ({
}});
our $cmddef = {
- create => [ __PACKAGE__, 'create', ['remote', 'vmid', 'node']],
+ create => [ __PACKAGE__, 'create', ['remote', 'vmid']],
destroy => [ __PACKAGE__, 'destroy', ['remote', 'vmid']],
enter => [ __PACKAGE__, 'enter', ['remote', 'vmid']],
};
diff --git a/PVE/APIClient/Config.pm b/PVE/APIClient/Config.pm
index a783ab3..73e8f5d 100644
--- a/PVE/APIClient/Config.pm
+++ b/PVE/APIClient/Config.pm
@@ -261,18 +261,36 @@ sub properties {
optional => 1,
maxLength => 4096,
},
+
+ default_node => {
+ description => "The default Node to create guests on.",
+ type => 'string',
+ optional => 1,
+ maxLength => 4096,
+ default => 'localhost',
+ },
+ default_storage => {
+ description => "The default storage to create guests on.",
+ type => 'string',
+ optional => 1,
+ maxLength => 4096,
+ default => 'local',
+ },
};
}
sub options {
return {
- name => { optional => 0 },
- host => { optional => 0 },
+ name => { optional => 1 },
+ host => { optional => 0, fixed => 1 },
comment => { optional => 1 },
- username => { optional => 0 },
+ username => { optional => 0, fixed => 1 },
password => { optional => 1 },
- port => { optional => 1 },
- fingerprint => { optional => 1 },
+ port => { optional => 1, fixed => 1 },
+ fingerprint => { optional => 0, fixed => 1 },
+
+ default_node => { optional => 1 },
+ default_storage => { optional => 1 },
};
}
@@ -295,7 +313,6 @@ sub type {
sub options {
return {
- name => { optional => 1 },
username => { optional => 1 },
port => { optional => 1 },
};
--
2.11.0
More information about the pve-devel
mailing list