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
};
58 my $vm_config_perm_list = [
66 __PACKAGE__-
>register_method({
72 description
=> "Set container options.",
74 check
=> ['perm', '/vms/{vmid}', $vm_config_perm_list, any
=> 1],
77 additionalProperties
=> 0,
78 properties
=> PVE
::LXC
::Config-
>json_config_properties(
80 node
=> get_standard_option
('pve-node'),
81 vmid
=> get_standard_option
('pve-vmid', { completion
=> \
&PVE
::LXC
::complete_ctid
}),
83 type
=> 'string', format
=> 'pve-configid-list',
84 description
=> "A list of settings you want to delete.",
89 description
=> 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.',
95 returns
=> { type
=> 'null'},
99 my $rpcenv = PVE
::RPCEnvironment
::get
();
101 my $authuser = $rpcenv->get_user();
103 my $node = extract_param
($param, 'node');
105 my $vmid = extract_param
($param, 'vmid');
107 my $digest = extract_param
($param, 'digest');
109 die "no options specified\n" if !scalar(keys %$param);
111 my $delete_str = extract_param
($param, 'delete');
112 my @delete = PVE
::Tools
::split_list
($delete_str);
114 PVE
::LXC
::check_ct_modify_config_perm
($rpcenv, $authuser, $vmid, undef, {}, [@delete]);
116 foreach my $opt (@delete) {
117 raise_param_exc
({ delete => "you can't use '-$opt' and " .
118 "-delete $opt' at the same time" })
119 if defined($param->{$opt});
121 if (!PVE
::LXC
::Config-
>option_exists($opt)) {
122 raise_param_exc
({ delete => "unknown option '$opt'" });
126 PVE
::LXC
::check_ct_modify_config_perm
($rpcenv, $authuser, $vmid, undef, $param, []);
128 my $storage_cfg = cfs_read_file
("storage.cfg");
132 my $conf = PVE
::LXC
::Config-
>load_config($vmid);
133 PVE
::LXC
::Config-
>check_lock($conf);
135 PVE
::Tools
::assert_if_modified
($digest, $conf->{digest
});
137 my $running = PVE
::LXC
::check_running
($vmid);
139 PVE
::LXC
::Config-
>update_pct_config($vmid, $conf, $running, $param, \
@delete);
141 PVE
::LXC
::Config-
>write_config($vmid, $conf);
142 PVE
::LXC
::update_lxc_config
($vmid, $conf);
145 PVE
::LXC
::Config-
>lock_config($vmid, $code);