]>
git.proxmox.com Git - pve-container.git/blob - src/PVE/CLI/pct.pm
7 use PVE
::Tools
qw(extract_param);
10 use PVE
::RPCEnvironment
;
11 use PVE
::JSONSchema
qw(get_standard_option);
14 use PVE
::API2
::LXC
::Config
;
15 use PVE
::API2
::LXC
::Status
;
16 use PVE
::API2
::LXC
::Snapshot
;
20 use base
qw(PVE::CLIHandler);
22 my $nodename = PVE
::INotify
::nodename
();
26 my $status = PVE
::Tools
::upid_read_status
($upid);
27 exit($status eq 'OK' ?
0 : -1);
30 __PACKAGE__-
>register_method ({
34 description
=> "Launch a console for the specified container.",
36 additionalProperties
=> 0,
38 vmid
=> get_standard_option
('pve-vmid', { completion
=> \
&PVE
::LXC
::complete_ctid_running
}),
41 returns
=> { type
=> 'null' },
46 # test if container exists on this node
47 my $conf = PVE
::LXC
::load_config
($param->{vmid
});
49 my $cmd = PVE
::LXC
::get_console_command
($param->{vmid
}, $conf);
53 __PACKAGE__-
>register_method ({
57 description
=> "Launch a shell for the specified container.",
59 additionalProperties
=> 0,
61 vmid
=> get_standard_option
('pve-vmid', { completion
=> \
&PVE
::LXC
::complete_ctid_running
}),
64 returns
=> { type
=> 'null' },
69 # test if container exists on this node
70 PVE
::LXC
::load_config
($param->{vmid
});
72 exec('lxc-attach', '-n', $param->{vmid
});
75 __PACKAGE__-
>register_method ({
79 description
=> "Launch a command inside the specified container.",
81 additionalProperties
=> 0,
83 vmid
=> get_standard_option
('pve-vmid', { completion
=> \
&PVE
::LXC
::complete_ctid_running
}),
84 'extra-args' => get_standard_option
('extra-args'),
87 returns
=> { type
=> 'null' },
92 # test if container exists on this node
93 PVE
::LXC
::load_config
($param->{vmid
});
95 if (!@{$param->{'extra-args'}}) {
96 die "missing command";
98 exec('lxc-attach', '-n', $param->{vmid
}, '--', @{$param->{'extra-args'}});
102 list
=> [ 'PVE::API2::LXC', 'vmlist', [], { node
=> $nodename }, sub {
104 return if !scalar(@$res);
105 my $format = "%-10s %-10s %-20s\n";
106 printf($format, 'VMID', 'Status', 'Name');
107 foreach my $d (sort {$a->{vmid
} <=> $b->{vmid
} } @$res) {
108 printf($format, $d->{vmid
}, $d->{status
}, $d->{name
});
111 config
=> [ "PVE::API2::LXC::Config", 'vm_config', ['vmid'],
112 { node
=> $nodename }, sub {
114 foreach my $k (sort (keys %$config)) {
115 next if $k eq 'digest';
116 my $v = $config->{$k};
117 if ($k eq 'description') {
118 $v = PVE
::Tools
::encode_text
($v);
123 set
=> [ 'PVE::API2::LXC::Config', 'update_vm', ['vmid'], { node
=> $nodename }],
125 create
=> [ 'PVE::API2::LXC', 'create_vm', ['vmid', 'ostemplate'], { node
=> $nodename }, $upid_exit ],
126 restore
=> [ 'PVE::API2::LXC', 'create_vm', ['vmid', 'ostemplate'], { node
=> $nodename, restore
=> 1 }, $upid_exit ],
128 start
=> [ 'PVE::API2::LXC::Status', 'vm_start', ['vmid'], { node
=> $nodename }, $upid_exit],
129 suspend
=> [ 'PVE::API2::LXC::Status', 'vm_suspend', ['vmid'], { node
=> $nodename }, $upid_exit],
130 resume
=> [ 'PVE::API2::LXC::Status', 'vm_resume', ['vmid'], { node
=> $nodename }, $upid_exit],
131 shutdown => [ 'PVE::API2::LXC::Status', 'vm_shutdown', ['vmid'], { node
=> $nodename }, $upid_exit],
132 stop
=> [ 'PVE::API2::LXC::Status', 'vm_stop', ['vmid'], { node
=> $nodename }, $upid_exit],
134 migrate
=> [ "PVE::API2::LXC", 'migrate_vm', ['vmid', 'target'], { node
=> $nodename }, $upid_exit],
136 console
=> [ __PACKAGE__
, 'console', ['vmid']],
137 enter
=> [ __PACKAGE__
, 'enter', ['vmid']],
138 exec => [ __PACKAGE__
, 'exec', ['vmid', 'extra-args']],
140 destroy
=> [ 'PVE::API2::LXC', 'destroy_vm', ['vmid'],
141 { node
=> $nodename }, $upid_exit ],
143 snapshot
=> [ "PVE::API2::LXC::Snapshot", 'snapshot', ['vmid', 'snapname'],
144 { node
=> $nodename } , $upid_exit ],
146 delsnapshot
=> [ "PVE::API2::LXC::Snapshot", 'delsnapshot', ['vmid', 'snapname'], { node
=> $nodename } , $upid_exit ],
148 listsnapshot
=> [ "PVE::API2::LXC::Snapshot", 'list', ['vmid'], { node
=> $nodename },
151 foreach my $e (@$res) {
152 my $headline = $e->{description
} || 'no-description';
153 $headline =~ s/\n.*//sg;
154 my $parent = $e->{parent
} // 'no-parent';
155 printf("%-20s %-20s %s\n", $e->{name
}, $parent, $headline);
159 rollback
=> [ "PVE::API2::LXC::Snapshot", 'rollback', ['vmid', 'snapname'], { node
=> $nodename } , $upid_exit ],
161 template
=> [ "PVE::API2::LXC", 'template', ['vmid'], { node
=> $nodename }],
171 pct - Tool to manage Linux Containers (LXC) on Proxmox VE
179 pct is a tool to manages Linux Containers (LXC). You can create
180 and destroy containers, and control execution
181 (start/stop/suspend/resume). Besides that, you can use pct to set
182 parameters in the associated config file, like network configuration or
187 Create a container based on a Debian template
188 (provided you downloaded the template via the webgui before)
190 pct create 100 /var/lib/vz/template/cache/debian-8.0-standard_8.0-1_amd64.tar.gz
196 Start a login session via getty
200 Enter the lxc namespace and run a shell as root user
204 Display the configuration
208 Add a network interface called eth0, bridged to the host bridge vmbr0,
209 set the address and gateway, while it's running
211 pct set 100 -net0 name=eth0,bridge=vmbr0,ip=192.168.15.147/24,gw=192.168.15.1
213 Reduce the memory of the container to 512MB
215 pct set -memory 512 100
219 /etc/pve/lxc/<vmid>.conf
221 Configuration file for the container <vmid>
225 L<B<qm(1)>>, L<B<pvesh(1)>>
227 =include pve_copyright