[pve-devel] [RFC pve-client] Add configureable defaults to "lxc create"

René Jochum r.jochum at proxmox.com
Wed Jun 20 14:35:17 CEST 2018


The given patch adds configureable defaults to lxc create,
I don't like how it handles defaults that are given by pveclient
and I don't know ConfigParser well enough to come up with another
solution.
---
 PVE/APIClient/Commands/lxc.pm | 16 ++++++++++++++--
 PVE/APIClient/Config.pm       | 22 +++++++++++++++++++++-
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/PVE/APIClient/Commands/lxc.pm b/PVE/APIClient/Commands/lxc.pm
index 3add2dd..f16d60e 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 $defaults_config = PVE::APIClient::Config->get_defaults($config);
+
+	if (!$node) {
+	    $node = $defaults_config->{node} // 'localhost';
+	}
+	$param->{storage} = $param->{storage} // $defaults_config->{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..f5abb61 100644
--- a/PVE/APIClient/Config.pm
+++ b/PVE/APIClient/Config.pm
@@ -293,11 +293,31 @@ sub type {
     return 'defaults';
 }
 
+sub properties {
+    return {
+	node => {
+	    description => "The default Node to create guests on.",
+	    type => 'string',
+	    optional => 1,
+	    maxLength => 4096,
+	    default => 'localhost',
+	},
+	storage => {
+	    description => "The default storage to create guests on.",
+	    type => 'string',
+	    optional => 1,
+	    maxLength => 4096,
+	    default => 'local',
+	},
+    }
+}
+
 sub options {
     return {
-	name => { optional => 1 },
 	username => { optional => 1 },
 	port => { optional => 1 },
+	node => { optional => 1 },
+	storage => { optional => 1 },
    };
 }
 
-- 
2.11.0




More information about the pve-devel mailing list