]> git.proxmox.com Git - pve-container.git/blob - src/PVE/API2/LXC.pm
15ebb87f9e336b0274ad559ff97f3b790cf87b29
[pve-container.git] / src / PVE / API2 / LXC.pm
1 package PVE::API2::LXC;
2
3 use strict;
4 use warnings;
5
6 use PVE::SafeSyslog;
7 use PVE::Tools qw(extract_param run_command);
8 use PVE::Exception qw(raise raise_param_exc);
9 use PVE::INotify;
10 use PVE::Cluster qw(cfs_read_file);
11 use PVE::AccessControl;
12 use PVE::Firewall;
13 use PVE::Storage;
14 use PVE::RESTHandler;
15 use PVE::RPCEnvironment;
16 use PVE::LXC;
17 use PVE::LXC::Create;
18 use PVE::LXC::Migrate;
19 use PVE::API2::LXC::Config;
20 use PVE::API2::LXC::Status;
21 use PVE::API2::LXC::Snapshot;
22 use PVE::HA::Env::PVE2;
23 use PVE::HA::Config;
24 use PVE::JSONSchema qw(get_standard_option);
25 use base qw(PVE::RESTHandler);
26
27 use Data::Dumper; # fixme: remove
28
29 __PACKAGE__->register_method ({
30 subclass => "PVE::API2::LXC::Config",
31 path => '{vmid}/config',
32 });
33
34 __PACKAGE__->register_method ({
35 subclass => "PVE::API2::LXC::Status",
36 path => '{vmid}/status',
37 });
38
39 __PACKAGE__->register_method ({
40 subclass => "PVE::API2::LXC::Snapshot",
41 path => '{vmid}/snapshot',
42 });
43
44 __PACKAGE__->register_method ({
45 subclass => "PVE::API2::Firewall::CT",
46 path => '{vmid}/firewall',
47 });
48
49 __PACKAGE__->register_method({
50 name => 'vmlist',
51 path => '',
52 method => 'GET',
53 description => "LXC container index (per node).",
54 permissions => {
55 description => "Only list CTs where you have VM.Audit permissons on /vms/<vmid>.",
56 user => 'all',
57 },
58 proxyto => 'node',
59 protected => 1, # /proc files are only readable by root
60 parameters => {
61 additionalProperties => 0,
62 properties => {
63 node => get_standard_option('pve-node'),
64 },
65 },
66 returns => {
67 type => 'array',
68 items => {
69 type => "object",
70 properties => {},
71 },
72 links => [ { rel => 'child', href => "{vmid}" } ],
73 },
74 code => sub {
75 my ($param) = @_;
76
77 my $rpcenv = PVE::RPCEnvironment::get();
78 my $authuser = $rpcenv->get_user();
79
80 my $vmstatus = PVE::LXC::vmstatus();
81
82 my $res = [];
83 foreach my $vmid (keys %$vmstatus) {
84 next if !$rpcenv->check($authuser, "/vms/$vmid", [ 'VM.Audit' ], 1);
85
86 my $data = $vmstatus->{$vmid};
87 $data->{vmid} = $vmid;
88 push @$res, $data;
89 }
90
91 return $res;
92
93 }});
94
95 __PACKAGE__->register_method({
96 name => 'create_vm',
97 path => '',
98 method => 'POST',
99 description => "Create or restore a container.",
100 permissions => {
101 user => 'all', # check inside
102 description => "You need 'VM.Allocate' permissions on /vms/{vmid} or on the VM pool /pool/{pool}. " .
103 "For restore, it is enough if the user has 'VM.Backup' permission and the VM already exists. " .
104 "You also need 'Datastore.AllocateSpace' permissions on the storage.",
105 },
106 protected => 1,
107 proxyto => 'node',
108 parameters => {
109 additionalProperties => 0,
110 properties => PVE::LXC::Config->json_config_properties({
111 node => get_standard_option('pve-node'),
112 vmid => get_standard_option('pve-vmid', { completion => \&PVE::Cluster::complete_next_vmid }),
113 ostemplate => {
114 description => "The OS template or backup file.",
115 type => 'string',
116 maxLength => 255,
117 completion => \&PVE::LXC::complete_os_templates,
118 },
119 password => {
120 optional => 1,
121 type => 'string',
122 description => "Sets root password inside container.",
123 minLength => 5,
124 },
125 storage => get_standard_option('pve-storage-id', {
126 description => "Default Storage.",
127 default => 'local',
128 optional => 1,
129 completion => \&PVE::Storage::complete_storage_enabled,
130 }),
131 force => {
132 optional => 1,
133 type => 'boolean',
134 description => "Allow to overwrite existing container.",
135 },
136 restore => {
137 optional => 1,
138 type => 'boolean',
139 description => "Mark this as restore task.",
140 },
141 pool => {
142 optional => 1,
143 type => 'string', format => 'pve-poolid',
144 description => "Add the VM to the specified pool.",
145 },
146 'ignore-unpack-errors' => {
147 optional => 1,
148 type => 'boolean',
149 description => "Ignore errors when extracting the template.",
150 },
151 'ssh-public-keys' => {
152 optional => 1,
153 type => 'string',
154 description => "Setup public SSH keys (one key per line, " .
155 "OpenSSH format).",
156 },
157 }),
158 },
159 returns => {
160 type => 'string',
161 },
162 code => sub {
163 my ($param) = @_;
164
165 my $rpcenv = PVE::RPCEnvironment::get();
166
167 my $authuser = $rpcenv->get_user();
168
169 my $node = extract_param($param, 'node');
170
171 my $vmid = extract_param($param, 'vmid');
172
173 my $ignore_unpack_errors = extract_param($param, 'ignore-unpack-errors');
174
175 my $basecfg_fn = PVE::LXC::Config->config_file($vmid);
176
177 my $same_container_exists = -f $basecfg_fn;
178
179 # 'unprivileged' is read-only, so we can't pass it to update_pct_config
180 my $unprivileged = extract_param($param, 'unprivileged');
181
182 my $restore = extract_param($param, 'restore');
183
184 if ($restore) {
185 # fixme: limit allowed parameters
186
187 }
188
189 my $force = extract_param($param, 'force');
190
191 if (!($same_container_exists && $restore && $force)) {
192 PVE::Cluster::check_vmid_unused($vmid);
193 } else {
194 my $conf = PVE::LXC::Config->load_config($vmid);
195 PVE::LXC::Config->check_protection($conf, "unable to restore CT $vmid");
196 }
197
198 my $password = extract_param($param, 'password');
199
200 my $ssh_keys = extract_param($param, 'ssh-public-keys');
201 PVE::Tools::validate_ssh_public_keys($ssh_keys) if defined($ssh_keys);
202
203 my $pool = extract_param($param, 'pool');
204
205 if (defined($pool)) {
206 $rpcenv->check_pool_exist($pool);
207 $rpcenv->check_perm_modify($authuser, "/pool/$pool");
208 }
209
210 if ($rpcenv->check($authuser, "/vms/$vmid", ['VM.Allocate'], 1)) {
211 # OK
212 } elsif ($pool && $rpcenv->check($authuser, "/pool/$pool", ['VM.Allocate'], 1)) {
213 # OK
214 } elsif ($restore && $force && $same_container_exists &&
215 $rpcenv->check($authuser, "/vms/$vmid", ['VM.Backup'], 1)) {
216 # OK: user has VM.Backup permissions, and want to restore an existing VM
217 } else {
218 raise_perm_exc();
219 }
220
221 PVE::LXC::check_ct_modify_config_perm($rpcenv, $authuser, $vmid, $pool, $param, []);
222
223 my $storage = extract_param($param, 'storage') // 'local';
224
225 my $storage_cfg = cfs_read_file("storage.cfg");
226
227 my $ostemplate = extract_param($param, 'ostemplate');
228
229 my $archive;
230
231 if ($ostemplate eq '-') {
232 die "pipe requires cli environment\n"
233 if $rpcenv->{type} ne 'cli';
234 die "pipe can only be used with restore tasks\n"
235 if !$restore;
236 $archive = '-';
237 die "restore from pipe requires rootfs parameter\n" if !defined($param->{rootfs});
238 } else {
239 $rpcenv->check_volume_access($authuser, $storage_cfg, $vmid, $ostemplate);
240 $archive = PVE::Storage::abs_filesystem_path($storage_cfg, $ostemplate);
241 }
242
243 my $check_and_activate_storage = sub {
244 my ($sid) = @_;
245
246 my $scfg = PVE::Storage::storage_check_node($storage_cfg, $sid, $node);
247
248 raise_param_exc({ storage => "storage '$sid' does not support container directories"})
249 if !$scfg->{content}->{rootdir};
250
251 $rpcenv->check($authuser, "/storage/$sid", ['Datastore.AllocateSpace']);
252
253 PVE::Storage::activate_storage($storage_cfg, $sid);
254 };
255
256 my $conf = {};
257
258 my $no_disk_param = {};
259 my $mp_param = {};
260 my $storage_only_mode = 1;
261 foreach my $opt (keys %$param) {
262 my $value = $param->{$opt};
263 if ($opt eq 'rootfs' || $opt =~ m/^mp\d+$/) {
264 # allow to use simple numbers (add default storage in that case)
265 if ($value =~ m/^\d+(\.\d+)?$/) {
266 $mp_param->{$opt} = "$storage:$value";
267 } else {
268 $mp_param->{$opt} = $value;
269 }
270 $storage_only_mode = 0;
271 } elsif ($opt =~ m/^unused\d+$/) {
272 warn "ignoring '$opt', cannot create/restore with unused volume\n";
273 delete $param->{$opt};
274 } else {
275 $no_disk_param->{$opt} = $value;
276 }
277 }
278
279 die "mountpoints configured, but 'rootfs' not set - aborting\n"
280 if !$storage_only_mode && !defined($mp_param->{rootfs});
281
282 # check storage access, activate storage
283 my $delayed_mp_param = {};
284 PVE::LXC::Config->foreach_mountpoint($mp_param, sub {
285 my ($ms, $mountpoint) = @_;
286
287 my $volid = $mountpoint->{volume};
288 my $mp = $mountpoint->{mp};
289
290 if ($mountpoint->{type} ne 'volume') { # bind or device
291 die "Only root can pass arbitrary filesystem paths.\n"
292 if $authuser ne 'root@pam';
293 } else {
294 my ($sid, $volname) = PVE::Storage::parse_volume_id($volid);
295 &$check_and_activate_storage($sid);
296 }
297 });
298
299 # check/activate default storage
300 &$check_and_activate_storage($storage) if !defined($mp_param->{rootfs});
301
302 PVE::LXC::Config->update_pct_config($vmid, $conf, 0, $no_disk_param);
303
304 $conf->{unprivileged} = 1 if $unprivileged;
305
306 my $check_vmid_usage = sub {
307 if ($force) {
308 die "can't overwrite running container\n"
309 if PVE::LXC::check_running($vmid);
310 } else {
311 PVE::Cluster::check_vmid_unused($vmid);
312 }
313 };
314
315 my $code = sub {
316 &$check_vmid_usage(); # final check after locking
317 my $old_conf;
318
319 my $config_fn = PVE::LXC::Config->config_file($vmid);
320 if (-f $config_fn) {
321 die "container exists" if !$restore; # just to be sure
322 $old_conf = PVE::LXC::Config->load_config($vmid);
323 } else {
324 eval {
325 # try to create empty config on local node, we have an flock
326 PVE::LXC::Config->write_config($vmid, {});
327 };
328
329 # another node was faster, abort
330 die "Could not reserve ID $vmid, already taken\n" if $@;
331 }
332
333 PVE::Cluster::check_cfs_quorum();
334 my $vollist = [];
335
336 eval {
337 if ($storage_only_mode) {
338 if ($restore) {
339 (undef, $mp_param) = PVE::LXC::Create::recover_config($archive);
340 die "rootfs configuration could not be recovered, please check and specify manually!\n"
341 if !defined($mp_param->{rootfs});
342 PVE::LXC::Config->foreach_mountpoint($mp_param, sub {
343 my ($ms, $mountpoint) = @_;
344 my $type = $mountpoint->{type};
345 if ($type eq 'volume') {
346 die "unable to detect disk size - please specify $ms (size)\n"
347 if !defined($mountpoint->{size});
348 my $disksize = $mountpoint->{size} / (1024 * 1024 * 1024); # create_disks expects GB as unit size
349 delete $mountpoint->{size};
350 $mountpoint->{volume} = "$storage:$disksize";
351 $mp_param->{$ms} = PVE::LXC::Config->print_ct_mountpoint($mountpoint, $ms eq 'rootfs');
352 } else {
353 my $type = $mountpoint->{type};
354 die "restoring rootfs to $type mount is only possible by specifying -rootfs manually!\n"
355 if ($ms eq 'rootfs');
356 die "restoring '$ms' to $type mount is only possible for root\n"
357 if $authuser ne 'root@pam';
358
359 if ($mountpoint->{backup}) {
360 warn "WARNING - unsupported configuration!\n";
361 warn "backup was enabled for $type mountpoint $ms ('$mountpoint->{mp}')\n";
362 warn "mountpoint configuration will be restored after archive extraction!\n";
363 warn "contained files will be restored to wrong directory!\n";
364 }
365 delete $mp_param->{$ms}; # actually delay bind/dev mps
366 $delayed_mp_param->{$ms} = PVE::LXC::Config->print_ct_mountpoint($mountpoint, $ms eq 'rootfs');
367 }
368 });
369 } else {
370 $mp_param->{rootfs} = "$storage:4"; # defaults to 4GB
371 }
372 }
373
374 $vollist = PVE::LXC::create_disks($storage_cfg, $vmid, $mp_param, $conf);
375
376 if (defined($old_conf)) {
377 # destroy old container volumes
378 PVE::LXC::destroy_lxc_container($storage_cfg, $vmid, $old_conf, {});
379 }
380
381 eval {
382 my $rootdir = PVE::LXC::mount_all($vmid, $storage_cfg, $conf, 1);
383 PVE::LXC::Create::restore_archive($archive, $rootdir, $conf, $ignore_unpack_errors);
384
385 if ($restore) {
386 PVE::LXC::Create::restore_configuration($vmid, $rootdir, $conf, $authuser ne 'root@pam');
387 } else {
388 my $lxc_setup = PVE::LXC::Setup->new($conf, $rootdir); # detect OS
389 PVE::LXC::Config->write_config($vmid, $conf); # safe config (after OS detection)
390 $lxc_setup->post_create_hook($password, $ssh_keys);
391 }
392 };
393 my $err = $@;
394 PVE::LXC::umount_all($vmid, $storage_cfg, $conf, $err ? 1 : 0);
395 PVE::Storage::deactivate_volumes($storage_cfg, PVE::LXC::Config->get_vm_volumes($conf));
396 die $err if $err;
397 # set some defaults
398 $conf->{hostname} ||= "CT$vmid";
399 $conf->{memory} ||= 512;
400 $conf->{swap} //= 512;
401 foreach my $mp (keys %$delayed_mp_param) {
402 $conf->{$mp} = $delayed_mp_param->{$mp};
403 }
404 PVE::LXC::Config->write_config($vmid, $conf);
405 };
406 if (my $err = $@) {
407 PVE::LXC::destroy_disks($storage_cfg, $vollist);
408 PVE::LXC::destroy_config($vmid);
409 die $err;
410 }
411 PVE::AccessControl::add_vm_to_pool($vmid, $pool) if $pool;
412 };
413
414 my $realcmd = sub { PVE::LXC::Config->lock_config($vmid, $code); };
415
416 &$check_vmid_usage(); # first check before locking
417
418 return $rpcenv->fork_worker($restore ? 'vzrestore' : 'vzcreate',
419 $vmid, $authuser, $realcmd);
420
421 }});
422
423 __PACKAGE__->register_method({
424 name => 'vmdiridx',
425 path => '{vmid}',
426 method => 'GET',
427 proxyto => 'node',
428 description => "Directory index",
429 permissions => {
430 user => 'all',
431 },
432 parameters => {
433 additionalProperties => 0,
434 properties => {
435 node => get_standard_option('pve-node'),
436 vmid => get_standard_option('pve-vmid'),
437 },
438 },
439 returns => {
440 type => 'array',
441 items => {
442 type => "object",
443 properties => {
444 subdir => { type => 'string' },
445 },
446 },
447 links => [ { rel => 'child', href => "{subdir}" } ],
448 },
449 code => sub {
450 my ($param) = @_;
451
452 # test if VM exists
453 my $conf = PVE::LXC::Config->load_config($param->{vmid});
454
455 my $res = [
456 { subdir => 'config' },
457 { subdir => 'status' },
458 { subdir => 'vncproxy' },
459 { subdir => 'vncwebsocket' },
460 { subdir => 'spiceproxy' },
461 { subdir => 'migrate' },
462 { subdir => 'clone' },
463 # { subdir => 'initlog' },
464 { subdir => 'rrd' },
465 { subdir => 'rrddata' },
466 { subdir => 'firewall' },
467 { subdir => 'snapshot' },
468 { subdir => 'resize' },
469 ];
470
471 return $res;
472 }});
473
474
475 __PACKAGE__->register_method({
476 name => 'rrd',
477 path => '{vmid}/rrd',
478 method => 'GET',
479 protected => 1, # fixme: can we avoid that?
480 permissions => {
481 check => ['perm', '/vms/{vmid}', [ 'VM.Audit' ]],
482 },
483 description => "Read VM RRD statistics (returns PNG)",
484 parameters => {
485 additionalProperties => 0,
486 properties => {
487 node => get_standard_option('pve-node'),
488 vmid => get_standard_option('pve-vmid'),
489 timeframe => {
490 description => "Specify the time frame you are interested in.",
491 type => 'string',
492 enum => [ 'hour', 'day', 'week', 'month', 'year' ],
493 },
494 ds => {
495 description => "The list of datasources you want to display.",
496 type => 'string', format => 'pve-configid-list',
497 },
498 cf => {
499 description => "The RRD consolidation function",
500 type => 'string',
501 enum => [ 'AVERAGE', 'MAX' ],
502 optional => 1,
503 },
504 },
505 },
506 returns => {
507 type => "object",
508 properties => {
509 filename => { type => 'string' },
510 },
511 },
512 code => sub {
513 my ($param) = @_;
514
515 return PVE::Cluster::create_rrd_graph(
516 "pve2-vm/$param->{vmid}", $param->{timeframe},
517 $param->{ds}, $param->{cf});
518
519 }});
520
521 __PACKAGE__->register_method({
522 name => 'rrddata',
523 path => '{vmid}/rrddata',
524 method => 'GET',
525 protected => 1, # fixme: can we avoid that?
526 permissions => {
527 check => ['perm', '/vms/{vmid}', [ 'VM.Audit' ]],
528 },
529 description => "Read VM RRD statistics",
530 parameters => {
531 additionalProperties => 0,
532 properties => {
533 node => get_standard_option('pve-node'),
534 vmid => get_standard_option('pve-vmid'),
535 timeframe => {
536 description => "Specify the time frame you are interested in.",
537 type => 'string',
538 enum => [ 'hour', 'day', 'week', 'month', 'year' ],
539 },
540 cf => {
541 description => "The RRD consolidation function",
542 type => 'string',
543 enum => [ 'AVERAGE', 'MAX' ],
544 optional => 1,
545 },
546 },
547 },
548 returns => {
549 type => "array",
550 items => {
551 type => "object",
552 properties => {},
553 },
554 },
555 code => sub {
556 my ($param) = @_;
557
558 return PVE::Cluster::create_rrd_data(
559 "pve2-vm/$param->{vmid}", $param->{timeframe}, $param->{cf});
560 }});
561
562 __PACKAGE__->register_method({
563 name => 'destroy_vm',
564 path => '{vmid}',
565 method => 'DELETE',
566 protected => 1,
567 proxyto => 'node',
568 description => "Destroy the container (also delete all uses files).",
569 permissions => {
570 check => [ 'perm', '/vms/{vmid}', ['VM.Allocate']],
571 },
572 parameters => {
573 additionalProperties => 0,
574 properties => {
575 node => get_standard_option('pve-node'),
576 vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid_stopped }),
577 },
578 },
579 returns => {
580 type => 'string',
581 },
582 code => sub {
583 my ($param) = @_;
584
585 my $rpcenv = PVE::RPCEnvironment::get();
586
587 my $authuser = $rpcenv->get_user();
588
589 my $vmid = $param->{vmid};
590
591 # test if container exists
592 my $conf = PVE::LXC::Config->load_config($vmid);
593
594 my $storage_cfg = cfs_read_file("storage.cfg");
595
596 PVE::LXC::Config->check_protection($conf, "can't remove CT $vmid");
597
598 die "unable to remove CT $vmid - used in HA resources\n"
599 if PVE::HA::Config::vm_is_ha_managed($vmid);
600
601 my $running_error_msg = "unable to destroy CT $vmid - container is running\n";
602
603 die $running_error_msg if PVE::LXC::check_running($vmid); # check early
604
605 my $code = sub {
606 # reload config after lock
607 $conf = PVE::LXC::Config->load_config($vmid);
608 PVE::LXC::Config->check_lock($conf);
609
610 die $running_error_msg if PVE::LXC::check_running($vmid);
611
612 PVE::LXC::destroy_lxc_container($storage_cfg, $vmid, $conf);
613 PVE::AccessControl::remove_vm_access($vmid);
614 PVE::Firewall::remove_vmfw_conf($vmid);
615 };
616
617 my $realcmd = sub { PVE::LXC::Config->lock_config($vmid, $code); };
618
619 return $rpcenv->fork_worker('vzdestroy', $vmid, $authuser, $realcmd);
620 }});
621
622 my $sslcert;
623
624 __PACKAGE__->register_method ({
625 name => 'vncproxy',
626 path => '{vmid}/vncproxy',
627 method => 'POST',
628 protected => 1,
629 permissions => {
630 check => ['perm', '/vms/{vmid}', [ 'VM.Console' ]],
631 },
632 description => "Creates a TCP VNC proxy connections.",
633 parameters => {
634 additionalProperties => 0,
635 properties => {
636 node => get_standard_option('pve-node'),
637 vmid => get_standard_option('pve-vmid'),
638 websocket => {
639 optional => 1,
640 type => 'boolean',
641 description => "use websocket instead of standard VNC.",
642 },
643 },
644 },
645 returns => {
646 additionalProperties => 0,
647 properties => {
648 user => { type => 'string' },
649 ticket => { type => 'string' },
650 cert => { type => 'string' },
651 port => { type => 'integer' },
652 upid => { type => 'string' },
653 },
654 },
655 code => sub {
656 my ($param) = @_;
657
658 my $rpcenv = PVE::RPCEnvironment::get();
659
660 my $authuser = $rpcenv->get_user();
661
662 my $vmid = $param->{vmid};
663 my $node = $param->{node};
664
665 my $authpath = "/vms/$vmid";
666
667 my $ticket = PVE::AccessControl::assemble_vnc_ticket($authuser, $authpath);
668
669 $sslcert = PVE::Tools::file_get_contents("/etc/pve/pve-root-ca.pem", 8192)
670 if !$sslcert;
671
672 my ($remip, $family);
673
674 if ($node ne PVE::INotify::nodename()) {
675 ($remip, $family) = PVE::Cluster::remote_node_ip($node);
676 } else {
677 $family = PVE::Tools::get_host_address_family($node);
678 }
679
680 my $port = PVE::Tools::next_vnc_port($family);
681
682 # NOTE: vncterm VNC traffic is already TLS encrypted,
683 # so we select the fastest chipher here (or 'none'?)
684 my $remcmd = $remip ?
685 ['/usr/bin/ssh', '-t', $remip] : [];
686
687 my $conf = PVE::LXC::Config->load_config($vmid, $node);
688 my $concmd = PVE::LXC::get_console_command($vmid, $conf);
689
690 my $shcmd = [ '/usr/bin/dtach', '-A',
691 "/var/run/dtach/vzctlconsole$vmid",
692 '-r', 'winch', '-z', @$concmd];
693
694 my $realcmd = sub {
695 my $upid = shift;
696
697 syslog ('info', "starting lxc vnc proxy $upid\n");
698
699 my $timeout = 10;
700
701 my $cmd = ['/usr/bin/vncterm', '-rfbport', $port,
702 '-timeout', $timeout, '-authpath', $authpath,
703 '-perm', 'VM.Console'];
704
705 if ($param->{websocket}) {
706 $ENV{PVE_VNC_TICKET} = $ticket; # pass ticket to vncterm
707 push @$cmd, '-notls', '-listen', 'localhost';
708 }
709
710 push @$cmd, '-c', @$remcmd, @$shcmd;
711
712 run_command($cmd);
713
714 return;
715 };
716
717 my $upid = $rpcenv->fork_worker('vncproxy', $vmid, $authuser, $realcmd);
718
719 PVE::Tools::wait_for_vnc_port($port);
720
721 return {
722 user => $authuser,
723 ticket => $ticket,
724 port => $port,
725 upid => $upid,
726 cert => $sslcert,
727 };
728 }});
729
730 __PACKAGE__->register_method({
731 name => 'vncwebsocket',
732 path => '{vmid}/vncwebsocket',
733 method => 'GET',
734 permissions => {
735 description => "You also need to pass a valid ticket (vncticket).",
736 check => ['perm', '/vms/{vmid}', [ 'VM.Console' ]],
737 },
738 description => "Opens a weksocket for VNC traffic.",
739 parameters => {
740 additionalProperties => 0,
741 properties => {
742 node => get_standard_option('pve-node'),
743 vmid => get_standard_option('pve-vmid'),
744 vncticket => {
745 description => "Ticket from previous call to vncproxy.",
746 type => 'string',
747 maxLength => 512,
748 },
749 port => {
750 description => "Port number returned by previous vncproxy call.",
751 type => 'integer',
752 minimum => 5900,
753 maximum => 5999,
754 },
755 },
756 },
757 returns => {
758 type => "object",
759 properties => {
760 port => { type => 'string' },
761 },
762 },
763 code => sub {
764 my ($param) = @_;
765
766 my $rpcenv = PVE::RPCEnvironment::get();
767
768 my $authuser = $rpcenv->get_user();
769
770 my $authpath = "/vms/$param->{vmid}";
771
772 PVE::AccessControl::verify_vnc_ticket($param->{vncticket}, $authuser, $authpath);
773
774 my $port = $param->{port};
775
776 return { port => $port };
777 }});
778
779 __PACKAGE__->register_method ({
780 name => 'spiceproxy',
781 path => '{vmid}/spiceproxy',
782 method => 'POST',
783 protected => 1,
784 proxyto => 'node',
785 permissions => {
786 check => ['perm', '/vms/{vmid}', [ 'VM.Console' ]],
787 },
788 description => "Returns a SPICE configuration to connect to the CT.",
789 parameters => {
790 additionalProperties => 0,
791 properties => {
792 node => get_standard_option('pve-node'),
793 vmid => get_standard_option('pve-vmid'),
794 proxy => get_standard_option('spice-proxy', { optional => 1 }),
795 },
796 },
797 returns => get_standard_option('remote-viewer-config'),
798 code => sub {
799 my ($param) = @_;
800
801 my $vmid = $param->{vmid};
802 my $node = $param->{node};
803 my $proxy = $param->{proxy};
804
805 my $authpath = "/vms/$vmid";
806 my $permissions = 'VM.Console';
807
808 my $conf = PVE::LXC::Config->load_config($vmid);
809
810 die "CT $vmid not running\n" if !PVE::LXC::check_running($vmid);
811
812 my $concmd = PVE::LXC::get_console_command($vmid, $conf);
813
814 my $shcmd = ['/usr/bin/dtach', '-A',
815 "/var/run/dtach/vzctlconsole$vmid",
816 '-r', 'winch', '-z', @$concmd];
817
818 my $title = "CT $vmid";
819
820 return PVE::API2Tools::run_spiceterm($authpath, $permissions, $vmid, $node, $proxy, $title, $shcmd);
821 }});
822
823
824 __PACKAGE__->register_method({
825 name => 'migrate_vm',
826 path => '{vmid}/migrate',
827 method => 'POST',
828 protected => 1,
829 proxyto => 'node',
830 description => "Migrate the container to another node. Creates a new migration task.",
831 permissions => {
832 check => ['perm', '/vms/{vmid}', [ 'VM.Migrate' ]],
833 },
834 parameters => {
835 additionalProperties => 0,
836 properties => {
837 node => get_standard_option('pve-node'),
838 vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid }),
839 target => get_standard_option('pve-node', {
840 description => "Target node.",
841 completion => \&PVE::Cluster::complete_migration_target,
842 }),
843 online => {
844 type => 'boolean',
845 description => "Use online/live migration.",
846 optional => 1,
847 },
848 force => {
849 type => 'boolean',
850 description => "Force migration despite local bind / device" .
851 " mounts. WARNING: identical bind / device mounts need to ".
852 " be available on the target node.",
853 optional => 1,
854 },
855 },
856 },
857 returns => {
858 type => 'string',
859 description => "the task ID.",
860 },
861 code => sub {
862 my ($param) = @_;
863
864 my $rpcenv = PVE::RPCEnvironment::get();
865
866 my $authuser = $rpcenv->get_user();
867
868 my $target = extract_param($param, 'target');
869
870 my $localnode = PVE::INotify::nodename();
871 raise_param_exc({ target => "target is local node."}) if $target eq $localnode;
872
873 PVE::Cluster::check_cfs_quorum();
874
875 PVE::Cluster::check_node_exists($target);
876
877 my $targetip = PVE::Cluster::remote_node_ip($target);
878
879 my $vmid = extract_param($param, 'vmid');
880
881 # test if VM exists
882 PVE::LXC::Config->load_config($vmid);
883
884 # try to detect errors early
885 if (PVE::LXC::check_running($vmid)) {
886 die "can't migrate running container without --online\n"
887 if !$param->{online};
888 }
889
890 if (PVE::HA::Config::vm_is_ha_managed($vmid) && $rpcenv->{type} ne 'ha') {
891
892 my $hacmd = sub {
893 my $upid = shift;
894
895 my $service = "ct:$vmid";
896
897 my $cmd = ['ha-manager', 'migrate', $service, $target];
898
899 print "Executing HA migrate for CT $vmid to node $target\n";
900
901 PVE::Tools::run_command($cmd);
902
903 return;
904 };
905
906 return $rpcenv->fork_worker('hamigrate', $vmid, $authuser, $hacmd);
907
908 } else {
909
910 my $realcmd = sub {
911 my $upid = shift;
912
913 PVE::LXC::Migrate->migrate($target, $targetip, $vmid, $param);
914
915 return;
916 };
917
918 return $rpcenv->fork_worker('vzmigrate', $vmid, $authuser, $realcmd);
919 }
920 }});
921
922 __PACKAGE__->register_method({
923 name => 'vm_feature',
924 path => '{vmid}/feature',
925 method => 'GET',
926 proxyto => 'node',
927 protected => 1,
928 description => "Check if feature for virtual machine is available.",
929 permissions => {
930 check => ['perm', '/vms/{vmid}', [ 'VM.Audit' ]],
931 },
932 parameters => {
933 additionalProperties => 0,
934 properties => {
935 node => get_standard_option('pve-node'),
936 vmid => get_standard_option('pve-vmid'),
937 feature => {
938 description => "Feature to check.",
939 type => 'string',
940 enum => [ 'snapshot' ],
941 },
942 snapname => get_standard_option('pve-lxc-snapshot-name', {
943 optional => 1,
944 }),
945 },
946 },
947 returns => {
948 type => "object",
949 properties => {
950 hasFeature => { type => 'boolean' },
951 #nodes => {
952 #type => 'array',
953 #items => { type => 'string' },
954 #}
955 },
956 },
957 code => sub {
958 my ($param) = @_;
959
960 my $node = extract_param($param, 'node');
961
962 my $vmid = extract_param($param, 'vmid');
963
964 my $snapname = extract_param($param, 'snapname');
965
966 my $feature = extract_param($param, 'feature');
967
968 my $conf = PVE::LXC::Config->load_config($vmid);
969
970 if($snapname){
971 my $snap = $conf->{snapshots}->{$snapname};
972 die "snapshot '$snapname' does not exist\n" if !defined($snap);
973 $conf = $snap;
974 }
975 my $storage_cfg = PVE::Storage::config();
976 #Maybe include later
977 #my $nodelist = PVE::LXC::shared_nodes($conf, $storage_cfg);
978 my $hasFeature = PVE::LXC::Config->has_feature($feature, $conf, $storage_cfg, $snapname);
979
980 return {
981 hasFeature => $hasFeature,
982 #nodes => [ keys %$nodelist ],
983 };
984 }});
985
986 __PACKAGE__->register_method({
987 name => 'template',
988 path => '{vmid}/template',
989 method => 'POST',
990 protected => 1,
991 proxyto => 'node',
992 description => "Create a Template.",
993 permissions => {
994 description => "You need 'VM.Allocate' permissions on /vms/{vmid}",
995 check => [ 'perm', '/vms/{vmid}', ['VM.Allocate']],
996 },
997 parameters => {
998 additionalProperties => 0,
999 properties => {
1000 node => get_standard_option('pve-node'),
1001 vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid_stopped }),
1002 experimental => {
1003 type => 'boolean',
1004 description => "The template feature is experimental, set this " .
1005 "flag if you know what you are doing.",
1006 default => 0,
1007 },
1008 },
1009 },
1010 returns => { type => 'null'},
1011 code => sub {
1012 my ($param) = @_;
1013
1014 my $rpcenv = PVE::RPCEnvironment::get();
1015
1016 my $authuser = $rpcenv->get_user();
1017
1018 my $node = extract_param($param, 'node');
1019
1020 my $vmid = extract_param($param, 'vmid');
1021
1022 my $updatefn = sub {
1023
1024 my $conf = PVE::LXC::Config->load_config($vmid);
1025 PVE::LXC::Config->check_lock($conf);
1026
1027 die "unable to create template, because CT contains snapshots\n"
1028 if $conf->{snapshots} && scalar(keys %{$conf->{snapshots}});
1029
1030 die "you can't convert a template to a template\n"
1031 if PVE::LXC::Config->is_template($conf);
1032
1033 die "you can't convert a CT to template if the CT is running\n"
1034 if PVE::LXC::check_running($vmid);
1035
1036 my $realcmd = sub {
1037 PVE::LXC::template_create($vmid, $conf);
1038 };
1039
1040 $conf->{template} = 1;
1041
1042 PVE::LXC::Config->write_config($vmid, $conf);
1043 # and remove lxc config
1044 PVE::LXC::update_lxc_config($vmid, $conf);
1045
1046 return $rpcenv->fork_worker('vztemplate', $vmid, $authuser, $realcmd);
1047 };
1048
1049 PVE::LXC::Config->lock_config($vmid, $updatefn);
1050
1051 return undef;
1052 }});
1053
1054 __PACKAGE__->register_method({
1055 name => 'clone_vm',
1056 path => '{vmid}/clone',
1057 method => 'POST',
1058 protected => 1,
1059 proxyto => 'node',
1060 description => "Create a container clone/copy",
1061 permissions => {
1062 description => "You need 'VM.Clone' permissions on /vms/{vmid}, " .
1063 "and 'VM.Allocate' permissions " .
1064 "on /vms/{newid} (or on the VM pool /pool/{pool}). You also need " .
1065 "'Datastore.AllocateSpace' on any used storage.",
1066 check =>
1067 [ 'and',
1068 ['perm', '/vms/{vmid}', [ 'VM.Clone' ]],
1069 [ 'or',
1070 [ 'perm', '/vms/{newid}', ['VM.Allocate']],
1071 [ 'perm', '/pool/{pool}', ['VM.Allocate'], require_param => 'pool'],
1072 ],
1073 ]
1074 },
1075 parameters => {
1076 additionalProperties => 0,
1077 properties => {
1078 node => get_standard_option('pve-node'),
1079 vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid }),
1080 newid => get_standard_option('pve-vmid', {
1081 completion => \&PVE::Cluster::complete_next_vmid,
1082 description => 'VMID for the clone.' }),
1083 hostname => {
1084 optional => 1,
1085 type => 'string', format => 'dns-name',
1086 description => "Set a hostname for the new CT.",
1087 },
1088 description => {
1089 optional => 1,
1090 type => 'string',
1091 description => "Description for the new CT.",
1092 },
1093 pool => {
1094 optional => 1,
1095 type => 'string', format => 'pve-poolid',
1096 description => "Add the new CT to the specified pool.",
1097 },
1098 snapname => get_standard_option('pve-lxc-snapshot-name', {
1099 optional => 1,
1100 }),
1101 storage => get_standard_option('pve-storage-id', {
1102 description => "Target storage for full clone.",
1103 requires => 'full',
1104 optional => 1,
1105 }),
1106 full => {
1107 optional => 1,
1108 type => 'boolean',
1109 description => "Create a full copy of all disk. This is always done when " .
1110 "you clone a normal CT. For CT templates, we try to create a linked clone by default.",
1111 default => 0,
1112 },
1113 experimental => {
1114 type => 'boolean',
1115 description => "The clone feature is experimental, set this " .
1116 "flag if you know what you are doing.",
1117 default => 0,
1118 },
1119 # target => get_standard_option('pve-node', {
1120 # description => "Target node. Only allowed if the original VM is on shared storage.",
1121 # optional => 1,
1122 # }),
1123 },
1124 },
1125 returns => {
1126 type => 'string',
1127 },
1128 code => sub {
1129 my ($param) = @_;
1130
1131 my $rpcenv = PVE::RPCEnvironment::get();
1132
1133 my $authuser = $rpcenv->get_user();
1134
1135 my $node = extract_param($param, 'node');
1136
1137 my $vmid = extract_param($param, 'vmid');
1138
1139 my $newid = extract_param($param, 'newid');
1140
1141 my $pool = extract_param($param, 'pool');
1142
1143 if (defined($pool)) {
1144 $rpcenv->check_pool_exist($pool);
1145 }
1146
1147 my $snapname = extract_param($param, 'snapname');
1148
1149 my $storage = extract_param($param, 'storage');
1150
1151 my $localnode = PVE::INotify::nodename();
1152
1153 my $storecfg = PVE::Storage::config();
1154
1155 if ($storage) {
1156 # check if storage is enabled on local node
1157 PVE::Storage::storage_check_enabled($storecfg, $storage);
1158 }
1159
1160 PVE::Cluster::check_cfs_quorum();
1161
1162 my $running = PVE::LXC::check_running($vmid) || 0;
1163
1164 my $clonefn = sub {
1165
1166 # do all tests after lock
1167 # we also try to do all tests before we fork the worker
1168 my $conf = PVE::LXC::Config->load_config($vmid);
1169
1170 PVE::LXC::Config->check_lock($conf);
1171
1172 my $verify_running = PVE::LXC::check_running($vmid) || 0;
1173
1174 die "unexpected state change\n" if $verify_running != $running;
1175
1176 die "snapshot '$snapname' does not exist\n"
1177 if $snapname && !defined( $conf->{snapshots}->{$snapname});
1178
1179 my $oldconf = $snapname ? $conf->{snapshots}->{$snapname} : $conf;
1180
1181 my $conffile = PVE::LXC::Config->config_file($newid);
1182 die "unable to create CT $newid: config file already exists\n"
1183 if -f $conffile;
1184
1185 my $newconf = { lock => 'clone' };
1186 my $mountpoints = {};
1187 my $fullclone = {};
1188 my $vollist = [];
1189
1190 foreach my $opt (keys %$oldconf) {
1191 my $value = $oldconf->{$opt};
1192
1193 # no need to copy unused images, because VMID(owner) changes anyways
1194 next if $opt =~ m/^unused\d+$/;
1195
1196 if (($opt eq 'rootfs') || ($opt =~ m/^mp\d+$/)) {
1197 my $mp = $opt eq 'rootfs' ?
1198 PVE::LXC::Config->parse_ct_rootfs($value) :
1199 PVE::LXC::Config->parse_ct_mountpoint($value);
1200
1201 if ($mp->{type} eq 'volume') {
1202 my $volid = $mp->{volume};
1203 if ($param->{full}) {
1204 die "fixme: full clone not implemented";
1205
1206 die "Full clone feature for '$volid' is not available\n"
1207 if !PVE::Storage::volume_has_feature($storecfg, 'copy', $volid, $snapname, $running);
1208 $fullclone->{$opt} = 1;
1209 } else {
1210 # not full means clone instead of copy
1211 die "Linked clone feature for '$volid' is not available\n"
1212 if !PVE::Storage::volume_has_feature($storecfg, 'clone', $volid, $snapname, $running);
1213 }
1214
1215 $mountpoints->{$opt} = $mp;
1216 push @$vollist, $volid;
1217
1218 } else {
1219 # TODO: allow bind mounts?
1220 die "unable to clone mountpint '$opt' (type $mp->{type})\n";
1221 }
1222
1223 } else {
1224 # copy everything else
1225 $newconf->{$opt} = $value;
1226 }
1227 }
1228
1229 delete $newconf->{template};
1230 if ($param->{hostname}) {
1231 $newconf->{hostname} = $param->{hostname};
1232 }
1233
1234 if ($param->{description}) {
1235 $newconf->{description} = $param->{description};
1236 }
1237
1238 # create empty/temp config - this fails if CT already exists on other node
1239 PVE::Tools::file_set_contents($conffile, "# ctclone temporary file\nlock: clone\n");
1240
1241 my $realcmd = sub {
1242 my $upid = shift;
1243
1244 my $newvollist = [];
1245
1246 eval {
1247 local $SIG{INT} = $SIG{TERM} = $SIG{QUIT} = $SIG{HUP} = sub { die "interrupted by signal\n"; };
1248
1249 PVE::Storage::activate_volumes($storecfg, $vollist, $snapname);
1250
1251 foreach my $opt (keys %$mountpoints) {
1252 my $mp = $mountpoints->{$opt};
1253 my $volid = $mp->{volume};
1254
1255 if ($fullclone->{$opt}) {
1256 die "fixme: full clone not implemented\n";
1257 } else {
1258 print "create linked clone of mountpoint $opt ($volid)\n";
1259 my $newvolid = PVE::Storage::vdisk_clone($storecfg, $volid, $newid, $snapname);
1260 push @$newvollist, $newvolid;
1261 $mp->{volume} = $newvolid;
1262
1263 $newconf->{$opt} = PVE::LXC::Config->print_ct_mountpoint($mp, $opt eq 'rootfs');
1264 PVE::LXC::Config->write_config($newid, $newconf);
1265 }
1266 }
1267
1268 delete $newconf->{lock};
1269 PVE::LXC::Config->write_config($newid, $newconf);
1270
1271 PVE::AccessControl::add_vm_to_pool($newid, $pool) if $pool;
1272 };
1273 if (my $err = $@) {
1274 unlink $conffile;
1275
1276 sleep 1; # some storage like rbd need to wait before release volume - really?
1277
1278 foreach my $volid (@$newvollist) {
1279 eval { PVE::Storage::vdisk_free($storecfg, $volid); };
1280 warn $@ if $@;
1281 }
1282 die "clone failed: $err";
1283 }
1284
1285 return;
1286 };
1287
1288 PVE::Firewall::clone_vmfw_conf($vmid, $newid);
1289
1290 return $rpcenv->fork_worker('vzclone', $vmid, $authuser, $realcmd);
1291
1292 };
1293
1294 return PVE::LXC::Config->lock_config($vmid, $clonefn);
1295 }});
1296
1297
1298 __PACKAGE__->register_method({
1299 name => 'resize_vm',
1300 path => '{vmid}/resize',
1301 method => 'PUT',
1302 protected => 1,
1303 proxyto => 'node',
1304 description => "Resize a container mountpoint.",
1305 permissions => {
1306 check => ['perm', '/vms/{vmid}', ['VM.Config.Disk'], any => 1],
1307 },
1308 parameters => {
1309 additionalProperties => 0,
1310 properties => {
1311 node => get_standard_option('pve-node'),
1312 vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid }),
1313 disk => {
1314 type => 'string',
1315 description => "The disk you want to resize.",
1316 enum => [PVE::LXC::Config->mountpoint_names()],
1317 },
1318 size => {
1319 type => 'string',
1320 pattern => '\+?\d+(\.\d+)?[KMGT]?',
1321 description => "The new size. With the '+' sign the value is added to the actual size of the volume and without it, the value is taken as an absolute one. Shrinking disk size is not supported.",
1322 },
1323 digest => {
1324 type => 'string',
1325 description => 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.',
1326 maxLength => 40,
1327 optional => 1,
1328 }
1329 },
1330 },
1331 returns => {
1332 type => 'string',
1333 description => "the task ID.",
1334 },
1335 code => sub {
1336 my ($param) = @_;
1337
1338 my $rpcenv = PVE::RPCEnvironment::get();
1339
1340 my $authuser = $rpcenv->get_user();
1341
1342 my $node = extract_param($param, 'node');
1343
1344 my $vmid = extract_param($param, 'vmid');
1345
1346 my $digest = extract_param($param, 'digest');
1347
1348 my $sizestr = extract_param($param, 'size');
1349 my $ext = ($sizestr =~ s/^\+//);
1350 my $newsize = PVE::JSONSchema::parse_size($sizestr);
1351 die "invalid size string" if !defined($newsize);
1352
1353 die "no options specified\n" if !scalar(keys %$param);
1354
1355 PVE::LXC::check_ct_modify_config_perm($rpcenv, $authuser, $vmid, undef, $param, []);
1356
1357 my $storage_cfg = cfs_read_file("storage.cfg");
1358
1359 my $code = sub {
1360
1361 my $conf = PVE::LXC::Config->load_config($vmid);
1362 PVE::LXC::Config->check_lock($conf);
1363
1364 PVE::Tools::assert_if_modified($digest, $conf->{digest});
1365
1366 my $running = PVE::LXC::check_running($vmid);
1367
1368 my $disk = $param->{disk};
1369 my $mp = $disk eq 'rootfs' ? PVE::LXC::Config->parse_ct_rootfs($conf->{$disk}) :
1370 PVE::LXC::Config->parse_ct_mountpoint($conf->{$disk});
1371
1372 my $volid = $mp->{volume};
1373
1374 my (undef, undef, $owner, undef, undef, undef, $format) =
1375 PVE::Storage::parse_volname($storage_cfg, $volid);
1376
1377 die "can't resize mountpoint owned by another container ($owner)"
1378 if $vmid != $owner;
1379
1380 die "can't resize volume: $disk if snapshot exists\n"
1381 if %{$conf->{snapshots}} && $format eq 'qcow2';
1382
1383 my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid);
1384
1385 $rpcenv->check($authuser, "/storage/$storeid", ['Datastore.AllocateSpace']);
1386
1387 PVE::Storage::activate_volumes($storage_cfg, [$volid]);
1388
1389 my $size = PVE::Storage::volume_size_info($storage_cfg, $volid, 5);
1390 $newsize += $size if $ext;
1391 $newsize = int($newsize);
1392
1393 die "unable to shrink disk size\n" if $newsize < $size;
1394
1395 return if $size == $newsize;
1396
1397 PVE::Cluster::log_msg('info', $authuser, "update CT $vmid: resize --disk $disk --size $sizestr");
1398 my $realcmd = sub {
1399 # Note: PVE::Storage::volume_resize doesn't do anything if $running=1, so
1400 # we pass 0 here (parameter only makes sense for qemu)
1401 PVE::Storage::volume_resize($storage_cfg, $volid, $newsize, 0);
1402
1403 $mp->{size} = $newsize;
1404 $conf->{$disk} = PVE::LXC::Config->print_ct_mountpoint($mp, $disk eq 'rootfs');
1405
1406 PVE::LXC::Config->write_config($vmid, $conf);
1407
1408 if ($format eq 'raw') {
1409 my $path = PVE::Storage::path($storage_cfg, $volid, undef);
1410 if ($running) {
1411
1412 $mp->{mp} = '/';
1413 my $use_loopdev = (PVE::LXC::mountpoint_mount_path($mp, $storage_cfg))[1];
1414 $path = PVE::LXC::query_loopdev($path) if $use_loopdev;
1415 die "internal error: CT running but mountpoint not attached to a loop device"
1416 if !$path;
1417 PVE::Tools::run_command(['losetup', '--set-capacity', $path]) if $use_loopdev;
1418
1419 # In order for resize2fs to know that we need online-resizing a mountpoint needs
1420 # to be visible to it in its namespace.
1421 # To not interfere with the rest of the system we unshare the current mount namespace,
1422 # mount over /tmp and then run resize2fs.
1423
1424 # interestingly we don't need to e2fsck on mounted systems...
1425 my $quoted = PVE::Tools::shellquote($path);
1426 my $cmd = "mount --make-rprivate / && mount $quoted /tmp && resize2fs $quoted";
1427 eval {
1428 PVE::Tools::run_command(['unshare', '-m', '--', 'sh', '-c', $cmd]);
1429 };
1430 warn "Failed to update the container's filesystem: $@\n" if $@;
1431 } else {
1432 eval {
1433 PVE::Tools::run_command(['e2fsck', '-f', '-y', $path]);
1434 PVE::Tools::run_command(['resize2fs', $path]);
1435 };
1436 warn "Failed to update the container's filesystem: $@\n" if $@;
1437 }
1438 }
1439 };
1440
1441 return $rpcenv->fork_worker('resize', $vmid, $authuser, $realcmd);
1442 };
1443
1444 return PVE::LXC::Config->lock_config($vmid, $code);;
1445 }});
1446
1447 1;