]> git.proxmox.com Git - pve-container.git/commitdiff
implement update_vm API (change hostname for now)
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 16 Apr 2015 09:44:38 +0000 (11:44 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 16 Apr 2015 09:44:38 +0000 (11:44 +0200)
src/PVE/API2/LXC.pm
src/PVE/LXC.pm
src/pct

index 644cc2005a5c9fddbeecbfc933b8cf315cb6b12e..2aaad49e3fe9dad1c35122e73478bfbca83ad5d4 100644 (file)
@@ -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);
index eb9554064ceecac0795a406a03958a059d9b163c..149ec423fd9cc0bc2768011e96a5df3bac45a902 100644 (file)
@@ -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 d996b0e4a48da03b628440971ca1d0b2698518e4..4c6800752fe0bc4750b50ff7ea01a53cf63e12a3 100755 (executable)
--- 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'],