From: Dietmar Maurer Date: Thu, 16 Apr 2015 09:44:38 +0000 (+0200) Subject: implement update_vm API (change hostname for now) X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=ec52ac213648e7b858b7806823c45293d7afb523;p=pve-container.git implement update_vm API (change hostname for now) --- diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm index 644cc20..2aaad49 100644 --- a/src/PVE/API2/LXC.pm +++ b/src/PVE/API2/LXC.pm @@ -273,6 +273,11 @@ __PACKAGE__->register_method({ { node => get_standard_option('pve-node'), vmid => get_standard_option('pve-vmid'), + delete => { + type => 'string', format => 'pve-configid-list', + description => "A list of settings you want to delete.", + optional => 1, + }, digest => { type => 'string', description => 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.', @@ -297,6 +302,21 @@ __PACKAGE__->register_method({ die "no options specified\n" if !scalar(keys %$param); + my $delete_str = extract_param($param, 'delete'); + my @delete = PVE::Tools::split_list($delete_str); + + &$check_ct_modify_config_perm($rpcenv, $authuser, $vmid, undef, [@delete]); + + foreach my $opt (@delete) { + raise_param_exc({ delete => "you can't use '-$opt' and " . + "-delete $opt' at the same time" }) + if defined($param->{$opt}); + + if (!PVE::LXC::option_exists($opt)) { + raise_param_exc({ delete => "unknown option '$opt'" }); + } + } + &$check_ct_modify_config_perm($rpcenv, $authuser, $vmid, undef, [keys %$param]); my $code = sub { @@ -305,7 +325,26 @@ __PACKAGE__->register_method({ PVE::Tools::assert_if_modified($digest, $conf->{digest}); - die "implement me" + # die if running + + foreach my $opt (@delete) { + if ($opt eq 'hostname') { + die "unable to delete required option '$opt'\n"; + } else { + die "implement me" + } + } + + foreach my $opt (keys %$param) { + my $value = $param->{$opt}; + if ($opt eq 'hostname') { + $conf->{'lxc.utsname'} = $value; + } else { + die "implement me" + } + } + + PVE::LXC::write_config($vmid, $conf); }; PVE::LXC::lock_container($vmid, undef, $code); diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index eb95540..149ec42 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -325,12 +325,22 @@ my $confdesc = { type => 'string', description => "Sets DNS server IP address for a container. Create will automatically use the setting from the host if you neither set searchdomain or nameserver.", }, - net0 => { +}; + +my $MAX_LXC_NETWORKS = 10; +for (my $i = 0; $i < $MAX_LXC_NETWORKS; $i++) { + $confdesc->{"net$i"} = { optional => 1, type => 'string', format => 'pve-lxc-network', description => "Specifies network interfaces for the container.", - }, -}; + }; +} + +sub option_exists { + my ($name) = @_; + + return defined($confdesc->{$name}); +} # add JSON properties for create and set function sub json_config_properties { diff --git a/src/pct b/src/pct index d996b0e..4c68007 100755 --- a/src/pct +++ b/src/pct @@ -76,6 +76,8 @@ my $cmddef = { print "$k: $v\n"; } }], + set => [ 'PVE::API2::LXC', 'update_vm', ['vmid'], { node => $nodename }], + create => [ 'PVE::API2::LXC', 'create_vm', ['vmid', 'ostemplate'], { node => $nodename }, $upid_exit ], destroy => [ 'PVE::API2::LXC', 'destroy_vm', ['vmid'],