]> git.proxmox.com Git - pve-container.git/blame - src/pct
Enhance pct man page with DESCRIPTION, EXAMPLES, FILES, SEE ALSO sections
[pve-container.git] / src / pct
CommitLineData
f76a2828
DM
1#!/usr/bin/perl -T
2
3use strict;
4use warnings;
5use lib qw(. ..);
6
7use PVE::SafeSyslog;
148d1cb4 8use PVE::Tools qw(extract_param);
f76a2828
DM
9use PVE::Cluster;
10use PVE::INotify;
11use PVE::RPCEnvironment;
12use PVE::JSONSchema qw(get_standard_option);
13use PVE::CLIHandler;
14use PVE::API2::LXC;
52389a07
DM
15use PVE::API2::LXC::Config;
16use PVE::API2::LXC::Status;
17use PVE::API2::LXC::Snapshot;
f76a2828
DM
18
19use Data::Dumper;
20
21use base qw(PVE::CLIHandler);
22
23$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
24
25initlog ('pct');
26
27die "please run as root\n" if $> != 0;
28
29PVE::INotify::inotify_init();
30
31my $rpcenv = PVE::RPCEnvironment->init('cli');
32$rpcenv->init_request();
33$rpcenv->set_language($ENV{LANG});
34$rpcenv->set_user('root@pam');
35
36my $nodename = PVE::INotify::nodename();
37
38my $upid_exit = sub {
39 my $upid = shift;
40 my $status = PVE::Tools::upid_read_status($upid);
41 exit($status eq 'OK' ? 0 : -1);
42};
43
44__PACKAGE__->register_method ({
cf52aa57
DM
45 name => 'console',
46 path => 'console',
f76a2828 47 method => 'GET',
cf52aa57 48 description => "Launch a console for the specified container.",
f76a2828
DM
49 parameters => {
50 additionalProperties => 0,
51 properties => {
68e8f3c5 52 vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid_running }),
f76a2828
DM
53 },
54 },
55 returns => { type => 'null' },
56
57 code => sub {
58 my ($param) = @_;
59
cf52aa57 60 # test if container exists on this node
aca816ad 61 my $conf = PVE::LXC::load_config($param->{vmid});
cf52aa57 62
aca816ad
DM
63 my $cmd = PVE::LXC::get_console_command($param->{vmid}, $conf);
64 exec(@$cmd);
cf52aa57
DM
65 }});
66
67__PACKAGE__->register_method ({
68 name => 'enter',
69 path => 'enter',
70 method => 'GET',
71 description => "Launch a shell for the specified container.",
72 parameters => {
73 additionalProperties => 0,
74 properties => {
68e8f3c5 75 vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid_running }),
cf52aa57
DM
76 },
77 },
78 returns => { type => 'null' },
79
80 code => sub {
81 my ($param) = @_;
82
83 # test if container exists on this node
84 PVE::LXC::load_config($param->{vmid});
85
86 exec('lxc-attach', '-n', $param->{vmid});
f76a2828
DM
87 }});
88
f76a2828 89my $cmddef = {
9c2d4ce9 90 #test => [ __PACKAGE__, 'test', [], {}, sub {} ],
f76a2828
DM
91 list=> [ 'PVE::API2::LXC', 'vmlist', [], { node => $nodename }, sub {
92 my $res = shift;
2d0261f6
DM
93 return if !scalar(@$res);
94 my $format = "%-10s %-10s %-20s\n";
95 printf($format, 'VMID', 'Status', 'Name');
96 foreach my $d (sort {$a->{vmid} <=> $b->{vmid} } @$res) {
97 printf($format, $d->{vmid}, $d->{status}, $d->{name});
98 }
99 }],
52389a07 100 config => [ "PVE::API2::LXC::Config", 'vm_config', ['vmid'],
f76a2828
DM
101 { node => $nodename }, sub {
102 my $config = shift;
103 foreach my $k (sort (keys %$config)) {
104 next if $k eq 'digest';
105 my $v = $config->{$k};
106 if ($k eq 'description') {
107 $v = PVE::Tools::encode_text($v);
108 }
109 print "$k: $v\n";
110 }
111 }],
52389a07 112 set => [ 'PVE::API2::LXC::Config', 'update_vm', ['vmid'], { node => $nodename }],
ec52ac21 113
9c2d4ce9 114 create => [ 'PVE::API2::LXC', 'create_vm', ['vmid', 'ostemplate'], { node => $nodename }, $upid_exit ],
148d1cb4 115 restore => [ 'PVE::API2::LXC', 'create_vm', ['vmid', 'ostemplate'], { node => $nodename, restore => 1 }, $upid_exit ],
f76a2828 116
52389a07
DM
117 start => [ 'PVE::API2::LXC::Status', 'vm_start', ['vmid'], { node => $nodename }, $upid_exit],
118 suspend => [ 'PVE::API2::LXC::Status', 'vm_suspend', ['vmid'], { node => $nodename }, $upid_exit],
119 resume => [ 'PVE::API2::LXC::Status', 'vm_resume', ['vmid'], { node => $nodename }, $upid_exit],
120 shutdown => [ 'PVE::API2::LXC::Status', 'vm_shutdown', ['vmid'], { node => $nodename }, $upid_exit],
121 stop => [ 'PVE::API2::LXC::Status', 'vm_stop', ['vmid'], { node => $nodename }, $upid_exit],
122
cf52aa57
DM
123 migrate => [ "PVE::API2::LXC", 'migrate_vm', ['vmid', 'target'], { node => $nodename }, $upid_exit],
124
125 console => [ __PACKAGE__, 'console', ['vmid']],
126 enter => [ __PACKAGE__, 'enter', ['vmid']],
127
f76a2828
DM
128 destroy => [ 'PVE::API2::LXC', 'destroy_vm', ['vmid'],
129 { node => $nodename }, $upid_exit ],
130
52389a07 131 snapshot => [ "PVE::API2::LXC::Snapshot", 'snapshot', ['vmid', 'snapname'],
489e960d 132 { node => $nodename } , $upid_exit ],
57ccb3f8 133
52389a07 134 delsnapshot => [ "PVE::API2::LXC::Snapshot", 'delsnapshot', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],
723157f6 135
56ec6fef
DM
136 listsnapshot => [ "PVE::API2::LXC::Snapshot", 'list', ['vmid'], { node => $nodename },
137 sub {
138 my $res = shift;
139 foreach my $e (@$res) {
140 my $headline = $e->{description} || 'no-description';
141 $headline =~ s/\n.*//sg;
142 my $parent = $e->{parent} // 'no-parent';
143 printf("%-20s %-20s %s\n", $e->{name}, $parent, $headline);
144 }
145 }],
146
52389a07 147 rollback => [ "PVE::API2::LXC::Snapshot", 'rollback', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],
bb1ac2de
DM
148
149 template => [ "PVE::API2::LXC", 'template', ['vmid'], { node => $nodename }],
f76a2828
DM
150};
151
152my $cmd = shift;
153
154PVE::CLIHandler::handle_cmd($cmddef, "pct", $cmd, \@ARGV, undef, $0);
155
156exit 0;
157
158__END__
159
160=head1 NAME
161
081850e1 162pct - Tool to manage Linux Containers (LXC) on Proxmox VE
f76a2828
DM
163
164=head1 SYNOPSIS
165
166=include synopsis
167
168=head1 DESCRIPTION
169
081850e1
EK
170pct is a tool to manages Linux Containers (LXC). You can create
171and destroy containers, and control execution
172(start/stop/suspend/resume). Besides that, you can use pct to set
173parameters in the associated config file, like network configuration or
174memory.
175
176=head1 EXAMPLES
177
178Create a container based on a Debian template
179(provided you downloaded the template via the webgui before)
180
181pct create 100 /var/lib/vz/template/cache/debian-8.0-standard_8.0-1_amd64.tar.gz
182
183Start a container
184
185pct start 100
186
187Start a login session via getty
188
189pct console 100
190
191Enter the lxc namespace and run a shell as root user
192
193pct enter 100
194
195Display the configuration
196
197pct config 100
198
199Add a network interface called eth0, bridged to the host bridge vmbr0,
200set the address and gateway, while it's running
201
202pct set 100 -net0 name=eth0,bridge=vmbr0,ip=192.168.15.147/24,gw=192.168.15.1
203
204Reduce the memory of the container to 512MB
205
206pct set -memory 512 100
207
208=head1 FILES
209
210/etc/pve/lxc/<vmid>.conf
211
212Configuration file for the container <vmid>
213
214=head1 SEE ALSO
215
216L<B<qm(1)>>, L<B<pvesh(1)>>
f76a2828
DM
217
218=include pve_copyright