Commit 3e86d7f6 authored by Dietmar Maurer's avatar Dietmar Maurer

implement update_vm for openvz

parent 590d0595
......@@ -163,11 +163,73 @@ __PACKAGE__->register_method({
# hack: vzctl '--userpasswd' starts the CT, but we want
# to avoid that for create
PVE::OpenVZ::set_rootpasswd($vmid, $password) if defined($password);
};
PVE::OpenVZ::lock_container($vmid, $code);
return undef;
}});
__PACKAGE__->register_method({
name => 'update_vm',
path => '{vmid}/config',
method => 'PUT',
protected => 1,
proxyto => 'node',
description => "Set virtual machine options.",
parameters => {
additionalProperties => 0,
properties => PVE::OpenVZ::json_config_properties(
{
node => get_standard_option('pve-node'),
vmid => get_standard_option('pve-vmid'),
digest => {
type => 'string',
description => 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.',
maxLength => 40,
optional => 1,
}
}),
},
returns => { type => 'null'},
code => sub {
my ($param) = @_;
my $rpcenv = PVE::RPCEnvironment::get();
my $user = $rpcenv->get_user();
my $node = extract_param($param, 'node');
my $vmid = extract_param($param, 'vmid');
return undef;
my $digest = extract_param($param, 'digest');
die "no options specified\n" if !scalar(keys %$param);
my $code = sub {
my $basecfg_fn = &$get_config_path($vmid);
my $basecfg = PVE::Tools::file_get_contents($basecfg_fn);
die "container $vmid does not exists\n" if !$basecfg;
my $conf = PVE::OpenVZ::parse_ovz_config($basecfg_fn, $basecfg);
die "checksum missmatch (file change by other user?)\n"
if $digest && $digest ne $conf->{digest};
my $changes = PVE::OpenVZ::update_ovz_config($conf, $param);
return if scalar (@$changes) <= 0;
my $cmd = ['vzctl', '--skiplock', 'set', $vmid, @$changes, '--save'];
PVE::Tools::run_command($cmd);
};
PVE::OpenVZ::lock_container($vmid, $code);
return undef;
}});
__PACKAGE__->register_method({
......
......@@ -891,8 +891,7 @@ sub update_ovz_config {
$veconf->{'nameserver'}->{value} = join(' ', keys %$nshash);
}
foreach my $nv (@$changes) { print "CHANGE: $nv\n"; }
# foreach my $nv (@$changes) { print "CHANGE: $nv\n"; }
return $changes;
}
......
......@@ -51,6 +51,9 @@ my $cmddef = {
create => [ 'PVE::API2::OpenVZ', 'create_vm', ['vmid', 'ostemplate'], { node => $nodename } ],
destroy => [ 'PVE::API2::OpenVZ', 'destroy_vm', ['vmid'], { node => $nodename } ],
set => [ "PVE::API2::OpenVZ", 'update_vm', ['vmid'], { node => $nodename } ],
};
my $cmd = shift;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment