]>
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_config
($vmid, 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'}});
127 __PACKAGE__-
>register_method ({
131 description
=> "Run a filesystem check (fsck) on a container volume.",
133 additionalProperties
=> 0,
135 vmid
=> get_standard_option
('pve-vmid', { completion
=> \
&PVE
::LXC
::complete_ctid_stopped
}),
139 description
=> "Force checking, even if the filesystem seems clean",
145 description
=> "A volume on which to run the filesystem check",
146 enum
=> [PVE
::LXC
::mountpoint_names
()],
150 returns
=> { type
=> 'null' },
154 my $vmid = $param->{'vmid'};
155 my $device = defined($param->{'device'}) ?
$param->{'device'} : 'rootfs';
157 my $command = ['fsck', '-a', '-l'];
158 push(@$command, '-f') if $param->{force
};
160 # critical path: all of this will be done while the container is locked
163 my $conf = PVE
::LXC
::load_config
($vmid);
164 my $storage_cfg = PVE
::Storage
::config
();
166 defined($conf->{$device}) || die "cannot run command on unexisting mountpoint $device\n";
168 my $mount_point = $device eq 'rootfs' ? PVE
::LXC
::parse_ct_rootfs
($conf->{$device}) :
169 PVE
::LXC
::parse_ct_mountpoint
($conf->{$device});
171 my $volid = $mount_point->{volume
};
174 my $storage_id = PVE
::Storage
::parse_volume_id
($volid, 1);
177 my (undef, undef, undef, undef, undef, undef, $format) =
178 PVE
::Storage
::parse_volname
($storage_cfg, $volid);
180 die "unable to run fsck for '$volid' (format == $format)\n"
183 $path = PVE
::Storage
::path
($storage_cfg, $volid);
186 if (($volid =~ m
|^/.+|) && (-b
$volid)) {
187 # pass block devices directly
190 die "path '$volid' does not point to a block device\n";
194 push(@$command, $path);
196 PVE
::LXC
::check_running
($vmid) &&
197 die "cannot run fsck on active container\n";
199 PVE
::Tools
::run_command
($command);
202 PVE
::LXC
::lock_config
($vmid, $do_fsck);
207 list
=> [ 'PVE::API2::LXC', 'vmlist', [], { node
=> $nodename }, sub {
209 return if !scalar(@$res);
210 my $format = "%-10s %-10s %-20s\n";
211 printf($format, 'VMID', 'Status', 'Name');
212 foreach my $d (sort {$a->{vmid
} <=> $b->{vmid
} } @$res) {
213 printf($format, $d->{vmid
}, $d->{status
}, $d->{name
});
216 config
=> [ "PVE::API2::LXC::Config", 'vm_config', ['vmid'],
217 { node
=> $nodename }, sub {
219 foreach my $k (sort (keys %$config)) {
220 next if $k eq 'digest';
221 my $v = $config->{$k};
222 if ($k eq 'description') {
223 $v = PVE
::Tools
::encode_text
($v);
228 set
=> [ 'PVE::API2::LXC::Config', 'update_vm', ['vmid'], { node
=> $nodename }],
230 resize
=> [ "PVE::API2::LXC", 'resize_vm', ['vmid', 'disk', 'size'], { node
=> $nodename } ],
232 create
=> [ 'PVE::API2::LXC', 'create_vm', ['vmid', 'ostemplate'], { node
=> $nodename }, $upid_exit ],
233 restore
=> [ 'PVE::API2::LXC', 'create_vm', ['vmid', 'ostemplate'], { node
=> $nodename, restore
=> 1 }, $upid_exit ],
235 start
=> [ 'PVE::API2::LXC::Status', 'vm_start', ['vmid'], { node
=> $nodename }, $upid_exit],
236 suspend
=> [ 'PVE::API2::LXC::Status', 'vm_suspend', ['vmid'], { node
=> $nodename }, $upid_exit],
237 resume
=> [ 'PVE::API2::LXC::Status', 'vm_resume', ['vmid'], { node
=> $nodename }, $upid_exit],
238 shutdown => [ 'PVE::API2::LXC::Status', 'vm_shutdown', ['vmid'], { node
=> $nodename }, $upid_exit],
239 stop
=> [ 'PVE::API2::LXC::Status', 'vm_stop', ['vmid'], { node
=> $nodename }, $upid_exit],
241 clone
=> [ "PVE::API2::LXC", 'clone_vm', ['vmid', 'newid'], { node
=> $nodename }, $upid_exit ],
242 migrate
=> [ "PVE::API2::LXC", 'migrate_vm', ['vmid', 'target'], { node
=> $nodename }, $upid_exit],
244 console
=> [ __PACKAGE__
, 'console', ['vmid']],
245 enter
=> [ __PACKAGE__
, 'enter', ['vmid']],
246 unlock
=> [ __PACKAGE__
, 'unlock', ['vmid']],
247 exec => [ __PACKAGE__
, 'exec', ['vmid', 'extra-args']],
248 fsck
=> [ __PACKAGE__
, 'fsck', ['vmid']],
250 destroy
=> [ 'PVE::API2::LXC', 'destroy_vm', ['vmid'],
251 { node
=> $nodename }, $upid_exit ],
253 snapshot
=> [ "PVE::API2::LXC::Snapshot", 'snapshot', ['vmid', 'snapname'],
254 { node
=> $nodename } , $upid_exit ],
256 delsnapshot
=> [ "PVE::API2::LXC::Snapshot", 'delsnapshot', ['vmid', 'snapname'], { node
=> $nodename } , $upid_exit ],
258 listsnapshot
=> [ "PVE::API2::LXC::Snapshot", 'list', ['vmid'], { node
=> $nodename },
261 foreach my $e (@$res) {
262 my $headline = $e->{description
} || 'no-description';
263 $headline =~ s/\n.*//sg;
264 my $parent = $e->{parent
} // 'no-parent';
265 printf("%-20s %-20s %s\n", $e->{name
}, $parent, $headline);
269 rollback
=> [ "PVE::API2::LXC::Snapshot", 'rollback', ['vmid', 'snapname'], { node
=> $nodename } , $upid_exit ],
271 template
=> [ "PVE::API2::LXC", 'template', ['vmid'], { node
=> $nodename }],
281 pct - Tool to manage Linux Containers (LXC) on Proxmox VE
289 pct is a tool to manages Linux Containers (LXC). You can create
290 and destroy containers, and control execution
291 (start/stop/suspend/resume). Besides that, you can use pct to set
292 parameters in the associated config file, like network configuration or
297 Create a container based on a Debian template
298 (provided you downloaded the template via the webgui before)
300 pct create 100 /var/lib/vz/template/cache/debian-8.0-standard_8.0-1_amd64.tar.gz
306 Start a login session via getty
310 Enter the lxc namespace and run a shell as root user
314 Display the configuration
318 Add a network interface called eth0, bridged to the host bridge vmbr0,
319 set the address and gateway, while it's running
321 pct set 100 -net0 name=eth0,bridge=vmbr0,ip=192.168.15.147/24,gw=192.168.15.1
323 Reduce the memory of the container to 512MB
325 pct set -memory 512 100
329 /etc/pve/lxc/<vmid>.conf
331 Configuration file for the container <vmid>
335 L<B<qm(1)>>, L<B<pvesh(1)>>
337 =include pve_copyright