]> git.proxmox.com Git - pve-container.git/blob - src/pct
Enhance pct man page with DESCRIPTION, EXAMPLES, FILES, SEE ALSO sections
[pve-container.git] / src / pct
1 #!/usr/bin/perl -T
2
3 use strict;
4 use warnings;
5 use lib qw(. ..);
6
7 use PVE::SafeSyslog;
8 use PVE::Tools qw(extract_param);
9 use PVE::Cluster;
10 use PVE::INotify;
11 use PVE::RPCEnvironment;
12 use PVE::JSONSchema qw(get_standard_option);
13 use PVE::CLIHandler;
14 use PVE::API2::LXC;
15 use PVE::API2::LXC::Config;
16 use PVE::API2::LXC::Status;
17 use PVE::API2::LXC::Snapshot;
18
19 use Data::Dumper;
20
21 use base qw(PVE::CLIHandler);
22
23 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
24
25 initlog ('pct');
26
27 die "please run as root\n" if $> != 0;
28
29 PVE::INotify::inotify_init();
30
31 my $rpcenv = PVE::RPCEnvironment->init('cli');
32 $rpcenv->init_request();
33 $rpcenv->set_language($ENV{LANG});
34 $rpcenv->set_user('root@pam');
35
36 my $nodename = PVE::INotify::nodename();
37
38 my $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 ({
45 name => 'console',
46 path => 'console',
47 method => 'GET',
48 description => "Launch a console for the specified container.",
49 parameters => {
50 additionalProperties => 0,
51 properties => {
52 vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid_running }),
53 },
54 },
55 returns => { type => 'null' },
56
57 code => sub {
58 my ($param) = @_;
59
60 # test if container exists on this node
61 my $conf = PVE::LXC::load_config($param->{vmid});
62
63 my $cmd = PVE::LXC::get_console_command($param->{vmid}, $conf);
64 exec(@$cmd);
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 => {
75 vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid_running }),
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});
87 }});
88
89 my $cmddef = {
90 #test => [ __PACKAGE__, 'test', [], {}, sub {} ],
91 list=> [ 'PVE::API2::LXC', 'vmlist', [], { node => $nodename }, sub {
92 my $res = shift;
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 }],
100 config => [ "PVE::API2::LXC::Config", 'vm_config', ['vmid'],
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 }],
112 set => [ 'PVE::API2::LXC::Config', 'update_vm', ['vmid'], { node => $nodename }],
113
114 create => [ 'PVE::API2::LXC', 'create_vm', ['vmid', 'ostemplate'], { node => $nodename }, $upid_exit ],
115 restore => [ 'PVE::API2::LXC', 'create_vm', ['vmid', 'ostemplate'], { node => $nodename, restore => 1 }, $upid_exit ],
116
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
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
128 destroy => [ 'PVE::API2::LXC', 'destroy_vm', ['vmid'],
129 { node => $nodename }, $upid_exit ],
130
131 snapshot => [ "PVE::API2::LXC::Snapshot", 'snapshot', ['vmid', 'snapname'],
132 { node => $nodename } , $upid_exit ],
133
134 delsnapshot => [ "PVE::API2::LXC::Snapshot", 'delsnapshot', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],
135
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
147 rollback => [ "PVE::API2::LXC::Snapshot", 'rollback', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],
148
149 template => [ "PVE::API2::LXC", 'template', ['vmid'], { node => $nodename }],
150 };
151
152 my $cmd = shift;
153
154 PVE::CLIHandler::handle_cmd($cmddef, "pct", $cmd, \@ARGV, undef, $0);
155
156 exit 0;
157
158 __END__
159
160 =head1 NAME
161
162 pct - Tool to manage Linux Containers (LXC) on Proxmox VE
163
164 =head1 SYNOPSIS
165
166 =include synopsis
167
168 =head1 DESCRIPTION
169
170 pct is a tool to manages Linux Containers (LXC). You can create
171 and destroy containers, and control execution
172 (start/stop/suspend/resume). Besides that, you can use pct to set
173 parameters in the associated config file, like network configuration or
174 memory.
175
176 =head1 EXAMPLES
177
178 Create a container based on a Debian template
179 (provided you downloaded the template via the webgui before)
180
181 pct create 100 /var/lib/vz/template/cache/debian-8.0-standard_8.0-1_amd64.tar.gz
182
183 Start a container
184
185 pct start 100
186
187 Start a login session via getty
188
189 pct console 100
190
191 Enter the lxc namespace and run a shell as root user
192
193 pct enter 100
194
195 Display the configuration
196
197 pct config 100
198
199 Add a network interface called eth0, bridged to the host bridge vmbr0,
200 set the address and gateway, while it's running
201
202 pct set 100 -net0 name=eth0,bridge=vmbr0,ip=192.168.15.147/24,gw=192.168.15.1
203
204 Reduce the memory of the container to 512MB
205
206 pct set -memory 512 100
207
208 =head1 FILES
209
210 /etc/pve/lxc/<vmid>.conf
211
212 Configuration file for the container <vmid>
213
214 =head1 SEE ALSO
215
216 L<B<qm(1)>>, L<B<pvesh(1)>>
217
218 =include pve_copyright