]> git.proxmox.com Git - pve-container.git/blob - src/PVE/CLI/pct.pm
6296d6fc9aaa3b62d4d0b10ba5e6a1a45723d9f5
[pve-container.git] / src / PVE / CLI / pct.pm
1 package PVE::CLI::pct;
2
3 use strict;
4 use warnings;
5
6 use POSIX;
7 use Fcntl;
8 use File::Copy 'copy';
9
10 use PVE::SafeSyslog;
11 use PVE::Tools qw(extract_param);
12 use PVE::CpuSet;
13 use PVE::Cluster;
14 use PVE::INotify;
15 use PVE::RPCEnvironment;
16 use PVE::JSONSchema qw(get_standard_option);
17 use PVE::CLIHandler;
18 use PVE::API2::LXC;
19 use PVE::API2::LXC::Config;
20 use PVE::API2::LXC::Status;
21 use PVE::API2::LXC::Snapshot;
22
23 use Data::Dumper;
24
25 use base qw(PVE::CLIHandler);
26
27 my $nodename = PVE::INotify::nodename();
28
29 my $upid_exit = sub {
30 my $upid = shift;
31 my $status = PVE::Tools::upid_read_status($upid);
32 exit($status eq 'OK' ? 0 : -1);
33 };
34
35 sub setup_environment {
36 PVE::RPCEnvironment->setup_default_cli_env();
37 }
38
39 __PACKAGE__->register_method ({
40 name => 'status',
41 path => 'status',
42 method => 'GET',
43 description => "Show CT status.",
44 parameters => {
45 additionalProperties => 0,
46 properties => {
47 vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid }),
48 verbose => {
49 description => "Verbose output format",
50 type => 'boolean',
51 optional => 1,
52 }
53 },
54 },
55 returns => { type => 'null'},
56 code => sub {
57 my ($param) = @_;
58
59 # test if CT exists
60 my $conf = PVE::LXC::Config->load_config ($param->{vmid});
61
62 my $vmstatus = PVE::LXC::vmstatus($param->{vmid});
63 my $stat = $vmstatus->{$param->{vmid}};
64 if ($param->{verbose}) {
65 foreach my $k (sort (keys %$stat)) {
66 my $v = $stat->{$k};
67 next if !defined($v);
68 print "$k: $v\n";
69 }
70 } else {
71 my $status = $stat->{status} || 'unknown';
72 print "status: $status\n";
73 }
74
75 return undef;
76 }});
77
78 sub param_mapping {
79 my ($name) = @_;
80
81 my $mapping = {
82 'create_vm' => [
83 PVE::CLIHandler::get_standard_mapping('pve-password'),
84 'ssh-public-keys',
85 ],
86 };
87
88 return $mapping->{$name};
89 }
90
91 __PACKAGE__->register_method ({
92 name => 'unlock',
93 path => 'unlock',
94 method => 'PUT',
95 description => "Unlock the VM.",
96 parameters => {
97 additionalProperties => 0,
98 properties => {
99 vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid }),
100 },
101 },
102 returns => { type => 'null'},
103 code => sub {
104 my ($param) = @_;
105
106 my $vmid = $param->{vmid};
107
108 PVE::LXC::Config->remove_lock($vmid);
109
110 return undef;
111 }});
112
113 __PACKAGE__->register_method ({
114 name => 'console',
115 path => 'console',
116 method => 'GET',
117 description => "Launch a console for the specified container.",
118 parameters => {
119 additionalProperties => 0,
120 properties => {
121 vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid_running }),
122 },
123 },
124 returns => { type => 'null' },
125
126 code => sub {
127 my ($param) = @_;
128
129 # test if container exists on this node
130 my $conf = PVE::LXC::Config->load_config($param->{vmid});
131
132 my $cmd = PVE::LXC::get_console_command($param->{vmid}, $conf);
133 exec(@$cmd);
134 }});
135
136 __PACKAGE__->register_method ({
137 name => 'enter',
138 path => 'enter',
139 method => 'GET',
140 description => "Launch a shell for the specified container.",
141 parameters => {
142 additionalProperties => 0,
143 properties => {
144 vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid_running }),
145 },
146 },
147 returns => { type => 'null' },
148
149 code => sub {
150 my ($param) = @_;
151
152 my $vmid = $param->{vmid};
153
154 # test if container exists on this node
155 PVE::LXC::Config->load_config($vmid);
156
157 die "Error: container '$vmid' not running!\n" if !PVE::LXC::check_running($vmid);
158
159 exec('lxc-attach', '-n', $vmid);
160 }});
161
162 __PACKAGE__->register_method ({
163 name => 'exec',
164 path => 'exec',
165 method => 'GET',
166 description => "Launch a command inside the specified container.",
167 parameters => {
168 additionalProperties => 0,
169 properties => {
170 vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid_running }),
171 'extra-args' => get_standard_option('extra-args'),
172 },
173 },
174 returns => { type => 'null' },
175
176 code => sub {
177 my ($param) = @_;
178
179 # test if container exists on this node
180 PVE::LXC::Config->load_config($param->{vmid});
181
182 if (!@{$param->{'extra-args'}}) {
183 die "missing command";
184 }
185 exec('lxc-attach', '-n', $param->{vmid}, '--', @{$param->{'extra-args'}});
186 }});
187
188 __PACKAGE__->register_method ({
189 name => 'fsck',
190 path => 'fsck',
191 method => 'PUT',
192 description => "Run a filesystem check (fsck) on a container volume.",
193 parameters => {
194 additionalProperties => 0,
195 properties => {
196 vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid_stopped }),
197 force => {
198 optional => 1,
199 type => 'boolean',
200 description => "Force checking, even if the filesystem seems clean",
201 default => 0,
202 },
203 device => {
204 optional => 1,
205 type => 'string',
206 description => "A volume on which to run the filesystem check",
207 enum => [PVE::LXC::Config->mountpoint_names()],
208 },
209 },
210 },
211 returns => { type => 'null' },
212 code => sub {
213
214 my ($param) = @_;
215 my $vmid = $param->{'vmid'};
216 my $device = defined($param->{'device'}) ? $param->{'device'} : 'rootfs';
217
218 my $command = ['fsck', '-a', '-l'];
219 push(@$command, '-f') if $param->{force};
220
221 # critical path: all of this will be done while the container is locked
222 my $do_fsck = sub {
223
224 my $conf = PVE::LXC::Config->load_config($vmid);
225 my $storage_cfg = PVE::Storage::config();
226
227 defined($conf->{$device}) || die "cannot run command on non-existing mount point $device\n";
228
229 my $mount_point = $device eq 'rootfs' ? PVE::LXC::Config->parse_ct_rootfs($conf->{$device}) :
230 PVE::LXC::Config->parse_ct_mountpoint($conf->{$device});
231
232 my $volid = $mount_point->{volume};
233
234 my $path;
235 my $storage_id = PVE::Storage::parse_volume_id($volid, 1);
236
237 if ($storage_id) {
238 my (undef, undef, undef, undef, undef, undef, $format) =
239 PVE::Storage::parse_volname($storage_cfg, $volid);
240
241 die "unable to run fsck for '$volid' (format == $format)\n"
242 if $format ne 'raw';
243
244 $path = PVE::Storage::path($storage_cfg, $volid);
245
246 } else {
247 if (($volid =~ m|^/.+|) && (-b $volid)) {
248 # pass block devices directly
249 $path = $volid;
250 } else {
251 die "path '$volid' does not point to a block device\n";
252 }
253 }
254
255 push(@$command, $path);
256
257 PVE::LXC::check_running($vmid) &&
258 die "cannot run fsck on active container\n";
259
260 PVE::Tools::run_command($command);
261 };
262
263 PVE::LXC::Config->lock_config($vmid, $do_fsck);
264 return undef;
265 }});
266
267 __PACKAGE__->register_method({
268 name => 'mount',
269 path => 'mount',
270 method => 'POST',
271 description => "Mount the container's filesystem on the host. " .
272 "This will hold a lock on the container and is meant for emergency maintenance only " .
273 "as it will prevent further operations on the container other than start and stop.",
274 parameters => {
275 additionalProperties => 0,
276 properties => {
277 vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid }),
278 },
279 },
280 returns => { type => 'null' },
281 code => sub {
282 my ($param) = @_;
283
284 my $rpcenv = PVE::RPCEnvironment::get();
285
286 my $vmid = extract_param($param, 'vmid');
287 my $storecfg = PVE::Storage::config();
288 PVE::LXC::Config->lock_config($vmid, sub {
289 my $conf = PVE::LXC::Config->set_lock($vmid, 'mounted');
290 PVE::LXC::mount_all($vmid, $storecfg, $conf);
291 });
292
293 print "mounted CT $vmid in '/var/lib/lxc/$vmid/rootfs'\n";
294 return undef;
295 }});
296
297 __PACKAGE__->register_method({
298 name => 'unmount',
299 path => 'unmount',
300 method => 'POST',
301 description => "Unmount the container's filesystem.",
302 parameters => {
303 additionalProperties => 0,
304 properties => {
305 vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid }),
306 },
307 },
308 returns => { type => 'null' },
309 code => sub {
310 my ($param) = @_;
311
312 my $rpcenv = PVE::RPCEnvironment::get();
313
314 my $vmid = extract_param($param, 'vmid');
315 my $storecfg = PVE::Storage::config();
316 PVE::LXC::Config->lock_config($vmid, sub {
317 my $conf = PVE::LXC::Config->load_config($vmid);
318 PVE::LXC::umount_all($vmid, $storecfg, $conf, 0);
319 PVE::LXC::Config->remove_lock($vmid, 'mounted');
320 });
321 return undef;
322 }});
323
324 __PACKAGE__->register_method({
325 name => 'df',
326 path => 'df',
327 method => 'GET',
328 description => "Get the container's current disk usage.",
329 parameters => {
330 additionalProperties => 0,
331 properties => {
332 vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid }),
333 },
334 },
335 returns => { type => 'null' },
336 code => sub {
337 my ($param) = @_;
338
339 my $rpcenv = PVE::RPCEnvironment::get();
340
341 # JSONSchema's format_size is exact, this uses floating point numbers
342 my $format = sub {
343 my ($size) = @_;
344 return $size if $size < 1024.;
345 $size /= 1024.;
346 return sprintf('%.1fK', ${size}) if $size < 1024.;
347 $size /= 1024.;
348 return sprintf('%.1fM', ${size}) if $size < 1024.;
349 $size /= 1024.;
350 return sprintf('%.1fG', ${size}) if $size < 1024.;
351 $size /= 1024.;
352 return sprintf('%.1fT', ${size}) if $size < 1024.;
353 };
354
355 my $vmid = extract_param($param, 'vmid');
356 PVE::LXC::Config->lock_config($vmid, sub {
357 my $pid = eval { PVE::LXC::find_lxc_pid($vmid) };
358 my ($conf, $rootdir, $storecfg, $mounted);
359 if ($@ || !$pid) {
360 $conf = PVE::LXC::Config->set_lock($vmid, 'mounted');
361 $rootdir = "/var/lib/lxc/$vmid/rootfs";
362 $storecfg = PVE::Storage::config();
363 PVE::LXC::mount_all($vmid, $storecfg, $conf);
364 $mounted = 1;
365 } else {
366 $conf = PVE::LXC::Config->load_config($vmid);
367 $rootdir = "/proc/$pid/root";
368 }
369
370 my @list = [qw(MP Volume Size Used Avail Use% Path)];
371 my @len = map { length($_) } @{$list[0]};
372
373 eval {
374 PVE::LXC::Config->foreach_mountpoint($conf, sub {
375 my ($name, $mp) = @_;
376 my $path = $mp->{mp};
377
378 my $df = PVE::Tools::df("$rootdir/$path", 3);
379 my $total = $format->($df->{total});
380 my $used = $format->($df->{used});
381 my $avail = $format->($df->{avail});
382
383 my $pc = sprintf('%.1f', $df->{used}/$df->{total});
384
385 my $entry = [ $name, $mp->{volume}, $total, $used, $avail, $pc, $path ];
386 push @list, $entry;
387
388 foreach my $i (0..5) {
389 $len[$i] = length($entry->[$i])
390 if $len[$i] < length($entry->[$i]);
391 }
392 });
393
394 my $format = "%-$len[0]s %-$len[1]s %$len[2]s %$len[3]s %$len[4]s %$len[5]s %s\n";
395 printf($format, @$_) foreach @list;
396 };
397 warn $@ if $@;
398
399 if ($mounted) {
400 PVE::LXC::umount_all($vmid, $storecfg, $conf, 0);
401 PVE::LXC::Config->remove_lock($vmid, 'mounted');
402 }
403 });
404 return undef;
405 }});
406
407 # File creation with specified ownership and permissions.
408 # User and group can be names or decimal numbers.
409 # Permissions are explicit (not affected by umask) and can be numeric with the
410 # usual 0/0x prefixes for octal/hex.
411 sub create_file {
412 my ($path, $perms, $user, $group) = @_;
413 my ($uid, $gid);
414 if (defined($user)) {
415 if ($user =~ /^\d+$/) {
416 $uid = int($user);
417 } else {
418 $uid = getpwnam($user) or die "failed to get uid for: $user\n"
419 }
420 }
421 if (defined($group)) {
422 if ($group =~ /^\d+$/) {
423 $gid = int($group);
424 } else {
425 $gid = getgrnam($group) or die "failed to get gid for: $group\n"
426 }
427 }
428
429 if (defined($perms)) {
430 $! = 0;
431 my ($mode, $unparsed) = POSIX::strtoul($perms, 0);
432 die "invalid mode: '$perms'\n" if $perms eq '' || $unparsed > 0 || $!;
433 $perms = $mode;
434 }
435
436 my $fd;
437 if (sysopen($fd, $path, O_WRONLY | O_CREAT | O_EXCL, 0)) {
438 $perms = 0666 & ~umask if !defined($perms);
439 } else {
440 # If the path previously existed then we do not care about left-over
441 # file descriptors even if the permissions/ownership is changed.
442 sysopen($fd, $path, O_WRONLY | O_CREAT | O_TRUNC)
443 or die "failed to create file: $path: $!\n";
444 }
445
446 my $trunc = 0;
447
448 if (defined($perms)) {
449 $trunc = 1;
450 chmod($perms, $fd);
451 }
452
453 if (defined($uid) || defined($gid)) {
454 $trunc = 1;
455 my ($fuid, $fgid) = (stat($fd))[4,5] if !defined($uid) || !defined($gid);
456 $uid = $fuid if !defined($uid);
457 $gid = $fgid if !defined($gid);
458 chown($uid, $gid, $fd)
459 or die "failed to change file owner: $!\n";
460 }
461 return $fd;
462 }
463
464 __PACKAGE__->register_method({
465 name => 'pull',
466 path => 'pull',
467 method => 'PUT',
468 description => "Copy a file from the container to the local system.",
469 parameters => {
470 additionalProperties => 0,
471 properties => {
472 vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid }),
473 path => {
474 type => 'string',
475 description => "Path to a file inside the container to pull.",
476 },
477 destination => {
478 type => 'string',
479 description => "Destination",
480 },
481 user => {
482 type => 'string',
483 description => 'Owner user name or id.',
484 optional => 1,
485 },
486 group => {
487 type => 'string',
488 description => 'Owner group name or id.',
489 optional => 1,
490 },
491 perms => {
492 type => 'string',
493 description => "File permissions to use (octal by default, prefix with '0x' for hexadecimal).",
494 optional => 1,
495 },
496 },
497 },
498 returns => {
499 type => 'string',
500 description => "the task ID.",
501 },
502 code => sub {
503 my ($param) = @_;
504
505 my $rpcenv = PVE::RPCEnvironment::get();
506
507 my $vmid = extract_param($param, 'vmid');
508 my $path = extract_param($param, 'path');
509 my $dest = extract_param($param, 'destination');
510
511 my $perms = extract_param($param, 'perms');
512 # assume octal as default
513 $perms = "0$perms" if defined($perms) && $perms !~m/^0/;
514 my $user = extract_param($param, 'user');
515 my $group = extract_param($param, 'group');
516
517 my $code = sub {
518 my $running = PVE::LXC::check_running($vmid);
519 die "can only pull files from a running VM" if !$running;
520
521 my $realcmd = sub {
522 my $pid = PVE::LXC::find_lxc_pid($vmid);
523 # Avoid symlink issues by opening the files from inside the
524 # corresponding namespaces.
525 my $destfd = create_file($dest, $perms, $user, $group);
526
527 sysopen my $mntnsfd, "/proc/$pid/ns/mnt", O_RDONLY
528 or die "failed to open the container's mount namespace\n";
529 PVE::Tools::setns(fileno($mntnsfd), PVE::Tools::CLONE_NEWNS)
530 or die "failed to enter the container's mount namespace\n";
531 close($mntnsfd);
532 chdir('/') or die "failed to change to container root directory\n";
533
534 open my $srcfd, '<', $path
535 or die "failed to open $path: $!\n";
536
537 copy($srcfd, $destfd);
538 };
539
540 # This avoids having to setns() back to our namespace.
541 return $rpcenv->fork_worker('pull_file', $vmid, undef, $realcmd);
542 };
543
544 return PVE::LXC::Config->lock_config($vmid, $code);
545 }});
546
547 __PACKAGE__->register_method({
548 name => 'push',
549 path => 'push',
550 method => 'PUT',
551 description => "Copy a local file to the container.",
552 parameters => {
553 additionalProperties => 0,
554 properties => {
555 vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid }),
556 file => {
557 type => 'string',
558 description => "Path to a local file.",
559 },
560 destination => {
561 type => 'string',
562 description => "Destination inside the container to write to.",
563 },
564 user => {
565 type => 'string',
566 description => 'Owner user name or id. When using a name it must exist inside the container.',
567 optional => 1,
568 },
569 group => {
570 type => 'string',
571 description => 'Owner group name or id. When using a name it must exist inside the container.',
572 optional => 1,
573 },
574 perms => {
575 type => 'string',
576 description => "File permissions to use (octal by default, prefix with '0x' for hexadecimal).",
577 optional => 1,
578 },
579 },
580 },
581 returns => {
582 type => 'string',
583 description => "the task ID.",
584 },
585 code => sub {
586 my ($param) = @_;
587
588 my $rpcenv = PVE::RPCEnvironment::get();
589
590 my $vmid = extract_param($param, 'vmid');
591 my $file = extract_param($param, 'file');
592 my $dest = extract_param($param, 'destination');
593
594 my $perms = extract_param($param, 'perms');
595 # assume octal as default
596 $perms = "0$perms" if defined($perms) && $perms !~m/^0/;
597 my $user = extract_param($param, 'user');
598 my $group = extract_param($param, 'group');
599
600 my $code = sub {
601 my $running = PVE::LXC::check_running($vmid);
602 die "can only push files to a running CT\n" if !$running;
603
604 my $conf = PVE::LXC::Config->load_config($vmid);
605 my $unprivileged = $conf->{unprivileged};
606
607 my $realcmd = sub {
608 my $pid = PVE::LXC::find_lxc_pid($vmid);
609 # We open the file then enter the container's mount - and for
610 # unprivileged containers - user namespace and then create the
611 # file. This avoids symlink attacks as a symlink cannot point
612 # outside the namespace and our own access is equivalent to the
613 # container-local's root user. Also the user-passed -user and
614 # -group parameters will use the container-local's user and
615 # group names.
616 sysopen my $srcfd, $file, O_RDONLY
617 or die "failed to open $file for reading\n";
618
619 sysopen my $mntnsfd, "/proc/$pid/ns/mnt", O_RDONLY
620 or die "failed to open the container's mount namespace\n";
621 my $usernsfd;
622 if ($unprivileged) {
623 sysopen $usernsfd, "/proc/$pid/ns/user", O_RDONLY
624 or die "failed to open the container's user namespace\n";
625 }
626
627 PVE::Tools::setns(fileno($mntnsfd), PVE::Tools::CLONE_NEWNS)
628 or die "failed to enter the container's mount namespace\n";
629 close($mntnsfd);
630 chdir('/') or die "failed to change to container root directory\n";
631
632 if ($unprivileged) {
633 PVE::Tools::setns(fileno($usernsfd), PVE::Tools::CLONE_NEWUSER)
634 or die "failed to enter the container's user namespace\n";
635 close($usernsfd);
636 POSIX::setgid(0) or die "setgid failed: $!\n";
637 POSIX::setuid(0) or die "setuid failed: $!\n";
638 }
639
640 my $destfd = create_file($dest, $perms, $user, $group);
641 copy($srcfd, $destfd);
642 };
643
644 # This avoids having to setns() back to our namespace.
645 return $rpcenv->fork_worker('push_file', $vmid, undef, $realcmd);
646 };
647
648 return PVE::LXC::Config->lock_config($vmid, $code);
649 }});
650
651 __PACKAGE__->register_method ({
652 name => 'cpusets',
653 path => 'cpusets',
654 method => 'GET',
655 description => "Print the list of assigned CPU sets.",
656 parameters => {
657 additionalProperties => 0,
658 properties => {},
659 },
660 returns => { type => 'null'},
661 code => sub {
662 my ($param) = @_;
663
664 my $cgv1 = PVE::LXC::get_cgroup_subsystems();
665 if (!$cgv1->{cpuset}) {
666 print "cpuset cgroup not available\n";
667 return undef;
668 }
669
670 my $ctlist = PVE::LXC::config_list();
671
672 my $len = 0;
673 my $id_len = 0;
674 my $res = {};
675
676 foreach my $vmid (sort keys %$ctlist) {
677 next if ! -d "/sys/fs/cgroup/cpuset/lxc/$vmid";
678
679 my $cpuset = eval { PVE::CpuSet->new_from_cgroup("lxc/$vmid"); };
680 if (my $err = $@) {
681 warn $err;
682 next;
683 }
684 my @cpuset_members = $cpuset->members();
685
686 my $line = ': ';
687
688 my $last = $cpuset_members[-1];
689
690 for (my $id = 0; $id <= $last; $id++) {
691 my $empty = ' ' x length("$id");
692 $line .= ' ' . ($cpuset->has($id) ? $id : $empty);
693 }
694 $len = length($line) if length($line) > $len;
695 $id_len = length($vmid) if length($vmid) > $id_len;
696
697 $res->{$vmid} = $line;
698 }
699
700 my @vmlist = sort keys %$res;
701
702 if (scalar(@vmlist)) {
703 my $header = '-' x ($len + $id_len) . "\n";
704
705 print $header;
706 foreach my $vmid (@vmlist) {
707 print sprintf("%${id_len}i%s\n", $vmid, $res->{$vmid});
708 }
709 print $header;
710
711 } else {
712 print "no running containers\n";
713 }
714
715 return undef;
716 }});
717
718 our $cmddef = {
719 list=> [ 'PVE::API2::LXC', 'vmlist', [], { node => $nodename }, sub {
720 my $res = shift;
721 return if !scalar(@$res);
722 my $format = "%-10s %-10s %-12s %-20s\n";
723 printf($format, 'VMID', 'Status', 'Lock', 'Name');
724 foreach my $d (sort {$a->{vmid} <=> $b->{vmid} } @$res) {
725 printf($format, $d->{vmid}, $d->{status}, $d->{lock}, $d->{name});
726 }
727 }],
728 config => [ "PVE::API2::LXC::Config", 'vm_config', ['vmid'],
729 { node => $nodename }, sub {
730 my $config = shift;
731 foreach my $k (sort (keys %$config)) {
732 next if $k eq 'digest';
733 next if $k eq 'lxc';
734 my $v = $config->{$k};
735 if ($k eq 'description') {
736 $v = PVE::Tools::encode_text($v);
737 }
738 print "$k: $v\n";
739 }
740 if (defined($config->{'lxc'})) {
741 my $lxc_list = $config->{'lxc'};
742 foreach my $lxc_opt (@$lxc_list) {
743 print "$lxc_opt->[0]: $lxc_opt->[1]\n"
744 }
745 }
746 }],
747 set => [ 'PVE::API2::LXC::Config', 'update_vm', ['vmid'], { node => $nodename }],
748
749 resize => [ "PVE::API2::LXC", 'resize_vm', ['vmid', 'disk', 'size'], { node => $nodename } ],
750
751 create => [ 'PVE::API2::LXC', 'create_vm', ['vmid', 'ostemplate'], { node => $nodename }, $upid_exit ],
752 restore => [ 'PVE::API2::LXC', 'create_vm', ['vmid', 'ostemplate'], { node => $nodename, restore => 1 }, $upid_exit ],
753
754 start => [ 'PVE::API2::LXC::Status', 'vm_start', ['vmid'], { node => $nodename }, $upid_exit],
755 suspend => [ 'PVE::API2::LXC::Status', 'vm_suspend', ['vmid'], { node => $nodename }, $upid_exit],
756 resume => [ 'PVE::API2::LXC::Status', 'vm_resume', ['vmid'], { node => $nodename }, $upid_exit],
757 shutdown => [ 'PVE::API2::LXC::Status', 'vm_shutdown', ['vmid'], { node => $nodename }, $upid_exit],
758 stop => [ 'PVE::API2::LXC::Status', 'vm_stop', ['vmid'], { node => $nodename }, $upid_exit],
759
760 clone => [ "PVE::API2::LXC", 'clone_vm', ['vmid', 'newid'], { node => $nodename }, $upid_exit ],
761 migrate => [ "PVE::API2::LXC", 'migrate_vm', ['vmid', 'target'], { node => $nodename }, $upid_exit],
762 move_volume => [ "PVE::API2::LXC", 'move_volume', ['vmid', 'volume', 'storage'], { node => $nodename }, $upid_exit ],
763
764 status => [ __PACKAGE__, 'status', ['vmid']],
765 console => [ __PACKAGE__, 'console', ['vmid']],
766 enter => [ __PACKAGE__, 'enter', ['vmid']],
767 unlock => [ __PACKAGE__, 'unlock', ['vmid']],
768 exec => [ __PACKAGE__, 'exec', ['vmid', 'extra-args']],
769 fsck => [ __PACKAGE__, 'fsck', ['vmid']],
770
771 mount => [ __PACKAGE__, 'mount', ['vmid']],
772 unmount => [ __PACKAGE__, 'unmount', ['vmid']],
773 push => [ __PACKAGE__, 'push', ['vmid', 'file', 'destination']],
774 pull => [ __PACKAGE__, 'pull', ['vmid', 'path', 'destination']],
775
776 df => [ __PACKAGE__, 'df', ['vmid']],
777
778 destroy => [ 'PVE::API2::LXC', 'destroy_vm', ['vmid'],
779 { node => $nodename }, $upid_exit ],
780
781 snapshot => [ "PVE::API2::LXC::Snapshot", 'snapshot', ['vmid', 'snapname'],
782 { node => $nodename } , $upid_exit ],
783
784 delsnapshot => [ "PVE::API2::LXC::Snapshot", 'delsnapshot', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],
785
786 listsnapshot => [ "PVE::API2::LXC::Snapshot", 'list', ['vmid'], { node => $nodename },
787 sub {
788 my $res = shift;
789 foreach my $e (@$res) {
790 my $headline = $e->{description} || 'no-description';
791 $headline =~ s/\n.*//sg;
792 my $parent = $e->{parent} // 'no-parent';
793 printf("%-20s %-20s %s\n", $e->{name}, $parent, $headline);
794 }
795 }],
796
797 rollback => [ "PVE::API2::LXC::Snapshot", 'rollback', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],
798
799 template => [ "PVE::API2::LXC", 'template', ['vmid'], { node => $nodename }],
800
801 cpusets => [ __PACKAGE__, 'cpusets', []],
802
803 };
804
805
806 1;