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