On 2018-06-20 14:35, René Jochum wrote: > 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'; ^ Here I have to set 'localhost' when node is not set in the defaults, while I set localhost as default in the Config.
We will use defaults->{node} at a lot places and having to write 'localhost' everywhere looks suboptimal for me. > + } > + $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 }, > }; > } > _______________________________________________ pve-devel mailing list pve-devel@pve.proxmox.com https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel