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
;
19 use PVE
::JSONSchema
qw(get_standard_option);
20 use base
qw(PVE::RESTHandler);
22 use Data
::Dumper
; # fixme: remove
24 __PACKAGE__-
>register_method({
29 description
=> "Get container configuration.",
31 check
=> ['perm', '/vms/{vmid}', [ 'VM.Audit' ]],
34 additionalProperties
=> 0,
36 node
=> get_standard_option
('pve-node'),
37 vmid
=> get_standard_option
('pve-vmid', { completion
=> \
&PVE
::LXC
::complete_ctid
}),
38 snapshot
=> get_standard_option
('pve-snapshot-name', {
39 description
=> "Fetch config values from given snapshot.",
42 my ($cmd, $pname, $cur, $args) = @_;
43 PVE
::LXC
::Config-
>snapshot_list($args->[0]);
50 properties
=> PVE
::LXC
::Config-
>json_config_properties({
52 description
=> "Array of lxc low-level configurations ([[key1, value1], [key2, value2] ...]).",
54 items
=> { type
=> 'array', items
=> { type
=> 'string' }},
59 description
=> 'SHA1 digest of configuration file. This can be used to prevent concurrent modifications.',
66 my $conf = PVE
::LXC
::Config-
>load_config($param->{vmid
});
68 my $snapname = $param->{snapshot
};
70 my $snapshot = $conf->{snapshots
}->{$snapname};
71 die "snapshot '$snapname' does not exist\n"
72 if !defined($snapshot);
74 # we need the digest of the file
75 $snapshot->{digest
} = $conf->{digest
};
79 delete $conf->{snapshots
};
84 my $vm_config_perm_list = [
92 __PACKAGE__-
>register_method({
98 description
=> "Set container options.",
100 check
=> ['perm', '/vms/{vmid}', $vm_config_perm_list, any
=> 1],
101 description
=> 'non-volume mount points in rootfs and mp[n] are restricted to root@pam',
104 additionalProperties
=> 0,
105 properties
=> PVE
::LXC
::Config-
>json_config_properties(
107 node
=> get_standard_option
('pve-node'),
108 vmid
=> get_standard_option
('pve-vmid', { completion
=> \
&PVE
::LXC
::complete_ctid
}),
110 type
=> 'string', format
=> 'pve-configid-list',
111 description
=> "A list of settings you want to delete.",
116 description
=> 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.',
122 returns
=> { type
=> 'null'},
126 my $rpcenv = PVE
::RPCEnvironment
::get
();
128 my $authuser = $rpcenv->get_user();
130 my $node = extract_param
($param, 'node');
132 my $vmid = extract_param
($param, 'vmid');
134 my $digest = extract_param
($param, 'digest');
136 die "no options specified\n" if !scalar(keys %$param);
138 my $delete_str = extract_param
($param, 'delete');
139 my @delete = PVE
::Tools
::split_list
($delete_str);
141 PVE
::LXC
::check_ct_modify_config_perm
($rpcenv, $authuser, $vmid, undef, {}, [@delete]);
143 foreach my $opt (@delete) {
144 raise_param_exc
({ delete => "you can't use '-$opt' and " .
145 "-delete $opt' at the same time" })
146 if defined($param->{$opt});
148 if (!PVE
::LXC
::Config-
>option_exists($opt)) {
149 raise_param_exc
({ delete => "unknown option '$opt'" });
153 PVE
::LXC
::check_ct_modify_config_perm
($rpcenv, $authuser, $vmid, undef, $param, []);
155 my $storage_cfg = cfs_read_file
("storage.cfg");
157 my $repl_conf = PVE
::ReplicationConfig-
>new();
158 my $is_replicated = $repl_conf->check_for_existing_jobs($vmid, 1);
159 if ($is_replicated) {
160 PVE
::LXC
::Config-
>foreach_mountpoint_full($param, 0, sub {
161 my ($opt, $mountpoint) = @_;
162 my $volid = $mountpoint->{volume
};
163 return if !$volid || !($mountpoint->{replicate
}//1);
164 if ($mountpoint->{type
} eq 'volume') {
165 my ($storeid, $format);
166 if ($volid =~ $PVE::LXC
::NEW_DISK_RE
) {
168 $format = $mountpoint->{format
} || PVE
::Storage
::storage_default_format
($storage_cfg, $storeid);
170 ($storeid, undef) = PVE
::Storage
::parse_volume_id
($volid, 1);
171 $format = (PVE
::Storage
::parse_volname
($storage_cfg, $volid))[6];
173 return if PVE
::Storage
::storage_can_replicate
($storage_cfg, $storeid, $format);
174 my $scfg = PVE
::Storage
::storage_config
($storage_cfg, $storeid);
175 return if $scfg->{shared
};
177 die "cannot add non-replicatable volume to a replicated VM\n";
183 my $conf = PVE
::LXC
::Config-
>load_config($vmid);
184 PVE
::LXC
::Config-
>check_lock($conf);
186 PVE
::Tools
::assert_if_modified
($digest, $conf->{digest
});
188 my $running = PVE
::LXC
::check_running
($vmid);
190 PVE
::LXC
::Config-
>update_pct_config($vmid, $conf, $running, $param, \
@delete);
192 PVE
::LXC
::Config-
>write_config($vmid, $conf);
193 PVE
::LXC
::update_lxc_config
($vmid, $conf);
196 PVE
::LXC
::Config-
>lock_config($vmid, $code);