1 package PVE
::API2
::LXC
::Config
;
7 use PVE
::Tools
qw(extract_param run_command);
8 use PVE
::Exception
qw(raise raise_param_exc);
10 use PVE
::Cluster
qw(cfs_read_file);
11 use PVE
::AccessControl
;
15 use PVE
::RPCEnvironment
;
18 use PVE
::JSONSchema
qw(get_standard_option);
19 use base
qw(PVE::RESTHandler);
21 use Data
::Dumper
; # fixme: remove
23 __PACKAGE__-
>register_method({
28 description
=> "Get container configuration.",
30 check
=> ['perm', '/vms/{vmid}', [ 'VM.Audit' ]],
33 additionalProperties
=> 0,
35 node
=> get_standard_option
('pve-node'),
36 vmid
=> get_standard_option
('pve-vmid', { completion
=> \
&PVE
::LXC
::complete_ctid
}),
44 description
=> 'SHA1 digest of configuration file. This can be used to prevent concurrent modifications.',
51 my $conf = PVE
::LXC
::Config-
>load_config($param->{vmid
});
53 delete $conf->{snapshots
};
59 my $vm_config_perm_list = [
67 __PACKAGE__-
>register_method({
73 description
=> "Set container options.",
75 check
=> ['perm', '/vms/{vmid}', $vm_config_perm_list, any
=> 1],
78 additionalProperties
=> 0,
79 properties
=> PVE
::LXC
::json_config_properties
(
81 node
=> get_standard_option
('pve-node'),
82 vmid
=> get_standard_option
('pve-vmid', { completion
=> \
&PVE
::LXC
::complete_ctid
}),
84 type
=> 'string', format
=> 'pve-configid-list',
85 description
=> "A list of settings you want to delete.",
90 description
=> 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.',
96 returns
=> { type
=> 'null'},
100 my $rpcenv = PVE
::RPCEnvironment
::get
();
102 my $authuser = $rpcenv->get_user();
104 my $node = extract_param
($param, 'node');
106 my $vmid = extract_param
($param, 'vmid');
108 my $digest = extract_param
($param, 'digest');
110 die "no options specified\n" if !scalar(keys %$param);
112 my $delete_str = extract_param
($param, 'delete');
113 my @delete = PVE
::Tools
::split_list
($delete_str);
115 PVE
::LXC
::check_ct_modify_config_perm
($rpcenv, $authuser, $vmid, undef, {}, [@delete]);
117 foreach my $opt (@delete) {
118 raise_param_exc
({ delete => "you can't use '-$opt' and " .
119 "-delete $opt' at the same time" })
120 if defined($param->{$opt});
122 if (!PVE
::LXC
::option_exists
($opt)) {
123 raise_param_exc
({ delete => "unknown option '$opt'" });
127 PVE
::LXC
::check_ct_modify_config_perm
($rpcenv, $authuser, $vmid, undef, $param, []);
129 my $storage_cfg = cfs_read_file
("storage.cfg");
133 my $conf = PVE
::LXC
::Config-
>load_config($vmid);
134 PVE
::LXC
::Config-
>check_lock($conf);
136 PVE
::Tools
::assert_if_modified
($digest, $conf->{digest
});
138 my $running = PVE
::LXC
::check_running
($vmid);
140 PVE
::LXC
::update_pct_config
($vmid, $conf, $running, $param, \
@delete);
142 PVE
::LXC
::Config-
>write_config($vmid, $conf);
143 PVE
::LXC
::update_lxc_config
($storage_cfg, $vmid, $conf);
146 PVE
::LXC
::Config-
>lock_config($vmid, $code);