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],
75 description
=> 'non-volume mount points in rootfs and mp[n] are restricted to root@pam',
78 additionalProperties
=> 0,
79 properties
=> PVE
::LXC
::Config-
>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
::Config-
>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");
131 my $repl_conf = PVE
::ReplicationConfig-
>new();
132 my $is_replicated = $repl_conf->check_for_existing_jobs($vmid, 1);
133 if ($is_replicated) {
134 PVE
::LXC
::Config-
>foreach_mountpoint_full($param, 0, sub {
135 my ($opt, $mountpoint) = @_;
136 my $volid = $mountpoint->{volume
};
137 return if !$volid || !($mountpoint->{replicate
}//1);
138 if ($mountpoint->{type
} eq 'volume') {
139 my ($storeid, $format);
140 if ($volid =~ $PVE::LXC
::NEW_DISK_RE
) {
142 $format = $mountpoint->{format
} || PVE
::Storage
::storage_default_format
($storage_cfg, $storeid);
144 ($storeid, undef) = PVE
::Storage
::parse_volume_id
($volid, 1);
145 $format = (PVE
::Storage
::parse_volname
($storage_cfg, $volid))[6];
147 return if PVE
::Storage
::storage_can_replicate
($storage_cfg, $storeid, $format);
149 die "cannot add non-replicatable volume to a replicated VM\n";
155 my $conf = PVE
::LXC
::Config-
>load_config($vmid);
156 PVE
::LXC
::Config-
>check_lock($conf);
158 PVE
::Tools
::assert_if_modified
($digest, $conf->{digest
});
160 my $running = PVE
::LXC
::check_running
($vmid);
162 PVE
::LXC
::Config-
>update_pct_config($vmid, $conf, $running, $param, \
@delete);
164 PVE
::LXC
::Config-
>write_config($vmid, $conf);
165 PVE
::LXC
::update_lxc_config
($vmid, $conf);
168 PVE
::LXC
::Config-
>lock_config($vmid, $code);