use strict;
use warnings;
-use lib qw(. ..);
-use PVE::SafeSyslog;
-use PVE::Tools qw(extract_param);
-use PVE::Cluster;
-use PVE::INotify;
-use PVE::RPCEnvironment;
-use PVE::JSONSchema qw(get_standard_option);
-use PVE::CLIHandler;
-use PVE::API2::LXC;
+use PVE::CLI::pct;
-use Data::Dumper;
-
-use base qw(PVE::CLIHandler);
-
-$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
-
-initlog ('pct');
-
-die "please run as root\n" if $> != 0;
-
-PVE::INotify::inotify_init();
-
-my $rpcenv = PVE::RPCEnvironment->init('cli');
-$rpcenv->init_request();
-$rpcenv->set_language($ENV{LANG});
-$rpcenv->set_user('root@pam');
-
-my $nodename = PVE::INotify::nodename();
-
-my $upid_exit = sub {
- my $upid = shift;
- my $status = PVE::Tools::upid_read_status($upid);
- exit($status eq 'OK' ? 0 : -1);
-};
-
-__PACKAGE__->register_method ({
- name => 'console',
- path => 'console',
- method => 'GET',
- description => "Launch a console for the specified container.",
- parameters => {
- additionalProperties => 0,
- properties => {
- vmid => get_standard_option('pve-vmid'),
- },
- },
- returns => { type => 'null' },
-
- code => sub {
- my ($param) = @_;
-
- # test if container exists on this node
- PVE::LXC::load_config($param->{vmid});
-
- exec('lxc-console', '-n', $param->{vmid});
- }});
-
-__PACKAGE__->register_method ({
- name => 'enter',
- path => 'enter',
- method => 'GET',
- description => "Launch a shell for the specified container.",
- parameters => {
- additionalProperties => 0,
- properties => {
- vmid => get_standard_option('pve-vmid'),
- },
- },
- returns => { type => 'null' },
-
- code => sub {
- my ($param) = @_;
-
- # test if container exists on this node
- PVE::LXC::load_config($param->{vmid});
-
- exec('lxc-attach', '-n', $param->{vmid});
- }});
-
-my $cmddef = {
- #test => [ __PACKAGE__, 'test', [], {}, sub {} ],
- list=> [ 'PVE::API2::LXC', 'vmlist', [], { node => $nodename }, sub {
- my $res = shift;
- return if !scalar(@$res);
- my $format = "%-10s %-10s %-20s\n";
- printf($format, 'VMID', 'Status', 'Name');
- foreach my $d (sort {$a->{vmid} <=> $b->{vmid} } @$res) {
- printf($format, $d->{vmid}, $d->{status}, $d->{name});
- }
- }],
- config => [ "PVE::API2::LXC", 'vm_config', ['vmid'],
- { node => $nodename }, sub {
- my $config = shift;
- foreach my $k (sort (keys %$config)) {
- next if $k eq 'digest';
- my $v = $config->{$k};
- if ($k eq 'description') {
- $v = PVE::Tools::encode_text($v);
- }
- print "$k: $v\n";
- }
- }],
- set => [ 'PVE::API2::LXC', 'update_vm', ['vmid'], { node => $nodename }],
-
- create => [ 'PVE::API2::LXC', 'create_vm', ['vmid', 'ostemplate'], { node => $nodename }, $upid_exit ],
- restore => [ 'PVE::API2::LXC', 'create_vm', ['vmid', 'ostemplate'], { node => $nodename, restore => 1 }, $upid_exit ],
-
- start => [ 'PVE::API2::LXC', 'vm_start', ['vmid'], { node => $nodename }, $upid_exit],
- suspend => [ 'PVE::API2::LXC', 'vm_suspend', ['vmid'], { node => $nodename }, $upid_exit],
- resume => [ 'PVE::API2::LXC', 'vm_resume', ['vmid'], { node => $nodename }, $upid_exit],
- shutdown => [ 'PVE::API2::LXC', 'vm_shutdown', ['vmid'], { node => $nodename }, $upid_exit],
- stop => [ 'PVE::API2::LXC', 'vm_stop', ['vmid'], { node => $nodename }, $upid_exit],
- migrate => [ "PVE::API2::LXC", 'migrate_vm', ['vmid', 'target'], { node => $nodename }, $upid_exit],
-
- console => [ __PACKAGE__, 'console', ['vmid']],
- enter => [ __PACKAGE__, 'enter', ['vmid']],
-
- destroy => [ 'PVE::API2::LXC', 'destroy_vm', ['vmid'],
- { node => $nodename }, $upid_exit ],
-
- snapshot => [ "PVE::API2::LXC", 'snapshot', ['vmid', 'snapname'],
- { node => $nodename } , $upid_exit ],
-};
-
-my $cmd = shift;
-
-PVE::CLIHandler::handle_cmd($cmddef, "pct", $cmd, \@ARGV, undef, $0);
-
-exit 0;
-
-__END__
-
-=head1 NAME
-
-pct - Tool to manage Linux Containers on Proxmox VE
-
-=head1 SYNOPSIS
-
-=include synopsis
-
-=head1 DESCRIPTION
-
-Tool to manage linux containers.
-
-=include pve_copyright
+PVE::CLI::pct->run_cli_handler();