]>
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
=> "Unlock the VM.",
36 additionalProperties
=> 0,
38 vmid
=> get_standard_option
('pve-vmid', { completion
=> \
&PVE
::LXC
::complete_ctid
}),
41 returns
=> { type
=> 'null'},
45 my $vmid = $param->{vmid
};
47 PVE
::LXC
::lock_container
($vmid, 5, sub {
48 my $conf = PVE
::LXC
::load_config
($vmid);
50 PVE
::LXC
::write_config
($vmid, $conf);
56 __PACKAGE__-
>register_method ({
60 description
=> "Launch a console for the specified container.",
62 additionalProperties
=> 0,
64 vmid
=> get_standard_option
('pve-vmid', { completion
=> \
&PVE
::LXC
::complete_ctid_running
}),
67 returns
=> { type
=> 'null' },
72 # test if container exists on this node
73 my $conf = PVE
::LXC
::load_config
($param->{vmid
});
75 my $cmd = PVE
::LXC
::get_console_command
($param->{vmid
}, $conf);
79 __PACKAGE__-
>register_method ({
83 description
=> "Launch a shell for the specified container.",
85 additionalProperties
=> 0,
87 vmid
=> get_standard_option
('pve-vmid', { completion
=> \
&PVE
::LXC
::complete_ctid_running
}),
90 returns
=> { type
=> 'null' },
95 # test if container exists on this node
96 PVE
::LXC
::load_config
($param->{vmid
});
98 exec('lxc-attach', '-n', $param->{vmid
});
101 __PACKAGE__-
>register_method ({
105 description
=> "Launch a command inside the specified container.",
107 additionalProperties
=> 0,
109 vmid
=> get_standard_option
('pve-vmid', { completion
=> \
&PVE
::LXC
::complete_ctid_running
}),
110 'extra-args' => get_standard_option
('extra-args'),
113 returns
=> { type
=> 'null' },
118 # test if container exists on this node
119 PVE
::LXC
::load_config
($param->{vmid
});
121 if (!@{$param->{'extra-args'}}) {
122 die "missing command";
124 exec('lxc-attach', '-n', $param->{vmid
}, '--', @{$param->{'extra-args'}});
128 list
=> [ 'PVE::API2::LXC', 'vmlist', [], { node
=> $nodename }, sub {
130 return if !scalar(@$res);
131 my $format = "%-10s %-10s %-20s\n";
132 printf($format, 'VMID', 'Status', 'Name');
133 foreach my $d (sort {$a->{vmid
} <=> $b->{vmid
} } @$res) {
134 printf($format, $d->{vmid
}, $d->{status
}, $d->{name
});
137 config
=> [ "PVE::API2::LXC::Config", 'vm_config', ['vmid'],
138 { node
=> $nodename }, sub {
140 foreach my $k (sort (keys %$config)) {
141 next if $k eq 'digest';
142 my $v = $config->{$k};
143 if ($k eq 'description') {
144 $v = PVE
::Tools
::encode_text
($v);
149 set
=> [ 'PVE::API2::LXC::Config', 'update_vm', ['vmid'], { node
=> $nodename }],
151 create
=> [ 'PVE::API2::LXC', 'create_vm', ['vmid', 'ostemplate'], { node
=> $nodename }, $upid_exit ],
152 restore
=> [ 'PVE::API2::LXC', 'create_vm', ['vmid', 'ostemplate'], { node
=> $nodename, restore
=> 1 }, $upid_exit ],
154 start
=> [ 'PVE::API2::LXC::Status', 'vm_start', ['vmid'], { node
=> $nodename }, $upid_exit],
155 suspend
=> [ 'PVE::API2::LXC::Status', 'vm_suspend', ['vmid'], { node
=> $nodename }, $upid_exit],
156 resume
=> [ 'PVE::API2::LXC::Status', 'vm_resume', ['vmid'], { node
=> $nodename }, $upid_exit],
157 shutdown => [ 'PVE::API2::LXC::Status', 'vm_shutdown', ['vmid'], { node
=> $nodename }, $upid_exit],
158 stop
=> [ 'PVE::API2::LXC::Status', 'vm_stop', ['vmid'], { node
=> $nodename }, $upid_exit],
160 migrate
=> [ "PVE::API2::LXC", 'migrate_vm', ['vmid', 'target'], { node
=> $nodename }, $upid_exit],
162 console
=> [ __PACKAGE__
, 'console', ['vmid']],
163 enter
=> [ __PACKAGE__
, 'enter', ['vmid']],
164 unlock
=> [ __PACKAGE__
, 'unlock', ['vmid']],
165 exec => [ __PACKAGE__
, 'exec', ['vmid', 'extra-args']],
167 destroy
=> [ 'PVE::API2::LXC', 'destroy_vm', ['vmid'],
168 { node
=> $nodename }, $upid_exit ],
170 snapshot
=> [ "PVE::API2::LXC::Snapshot", 'snapshot', ['vmid', 'snapname'],
171 { node
=> $nodename } , $upid_exit ],
173 delsnapshot
=> [ "PVE::API2::LXC::Snapshot", 'delsnapshot', ['vmid', 'snapname'], { node
=> $nodename } , $upid_exit ],
175 listsnapshot
=> [ "PVE::API2::LXC::Snapshot", 'list', ['vmid'], { node
=> $nodename },
178 foreach my $e (@$res) {
179 my $headline = $e->{description
} || 'no-description';
180 $headline =~ s/\n.*//sg;
181 my $parent = $e->{parent
} // 'no-parent';
182 printf("%-20s %-20s %s\n", $e->{name
}, $parent, $headline);
186 rollback
=> [ "PVE::API2::LXC::Snapshot", 'rollback', ['vmid', 'snapname'], { node
=> $nodename } , $upid_exit ],
188 template
=> [ "PVE::API2::LXC", 'template', ['vmid'], { node
=> $nodename }],
198 pct - Tool to manage Linux Containers (LXC) on Proxmox VE
206 pct is a tool to manages Linux Containers (LXC). You can create
207 and destroy containers, and control execution
208 (start/stop/suspend/resume). Besides that, you can use pct to set
209 parameters in the associated config file, like network configuration or
214 Create a container based on a Debian template
215 (provided you downloaded the template via the webgui before)
217 pct create 100 /var/lib/vz/template/cache/debian-8.0-standard_8.0-1_amd64.tar.gz
223 Start a login session via getty
227 Enter the lxc namespace and run a shell as root user
231 Display the configuration
235 Add a network interface called eth0, bridged to the host bridge vmbr0,
236 set the address and gateway, while it's running
238 pct set 100 -net0 name=eth0,bridge=vmbr0,ip=192.168.15.147/24,gw=192.168.15.1
240 Reduce the memory of the container to 512MB
242 pct set -memory 512 100
246 /etc/pve/lxc/<vmid>.conf
248 Configuration file for the container <vmid>
252 L<B<qm(1)>>, L<B<pvesh(1)>>
254 =include pve_copyright