]>
git.proxmox.com Git - pve-container.git/blob - src/pct
8 use PVE
::Tools
qw(extract_param);
11 use PVE
::RPCEnvironment
;
12 use PVE
::JSONSchema
qw(get_standard_option);
15 use PVE
::API2
::LXC
::Config
;
16 use PVE
::API2
::LXC
::Status
;
17 use PVE
::API2
::LXC
::Snapshot
;
21 use base
qw(PVE::CLIHandler);
23 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
27 die "please run as root\n" if $> != 0;
29 PVE
::INotify
::inotify_init
();
31 my $rpcenv = PVE
::RPCEnvironment-
>init('cli');
32 $rpcenv->init_request();
33 $rpcenv->set_language($ENV{LANG
});
34 $rpcenv->set_user('root@pam');
36 my $nodename = PVE
::INotify
::nodename
();
40 my $status = PVE
::Tools
::upid_read_status
($upid);
41 exit($status eq 'OK' ?
0 : -1);
44 __PACKAGE__-
>register_method ({
48 description
=> "Launch a console for the specified container.",
50 additionalProperties
=> 0,
52 vmid
=> get_standard_option
('pve-vmid'),
55 returns
=> { type
=> 'null' },
60 # test if container exists on this node
61 my $conf = PVE
::LXC
::load_config
($param->{vmid
});
63 my $cmd = PVE
::LXC
::get_console_command
($param->{vmid
}, $conf);
67 __PACKAGE__-
>register_method ({
71 description
=> "Launch a shell for the specified container.",
73 additionalProperties
=> 0,
75 vmid
=> get_standard_option
('pve-vmid'),
78 returns
=> { type
=> 'null' },
83 # test if container exists on this node
84 PVE
::LXC
::load_config
($param->{vmid
});
86 exec('lxc-attach', '-n', $param->{vmid
});
90 #test => [ __PACKAGE__, 'test', [], {}, sub {} ],
91 list
=> [ 'PVE::API2::LXC', 'vmlist', [], { node
=> $nodename }, sub {
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
});
100 config
=> [ "PVE::API2::LXC::Config", 'vm_config', ['vmid'],
101 { node
=> $nodename }, sub {
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);
112 set
=> [ 'PVE::API2::LXC::Config', 'update_vm', ['vmid'], { node
=> $nodename }],
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 ],
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],
123 migrate
=> [ "PVE::API2::LXC", 'migrate_vm', ['vmid', 'target'], { node
=> $nodename }, $upid_exit],
125 console
=> [ __PACKAGE__
, 'console', ['vmid']],
126 enter
=> [ __PACKAGE__
, 'enter', ['vmid']],
128 destroy
=> [ 'PVE::API2::LXC', 'destroy_vm', ['vmid'],
129 { node
=> $nodename }, $upid_exit ],
131 snapshot
=> [ "PVE::API2::LXC::Snapshot", 'snapshot', ['vmid', 'snapname'],
132 { node
=> $nodename } , $upid_exit ],
134 delsnapshot
=> [ "PVE::API2::LXC::Snapshot", 'delsnapshot', ['vmid', 'snapname'], { node
=> $nodename } , $upid_exit ],
136 listsnapshot
=> [ "PVE::API2::LXC::Snapshot", 'list', ['vmid'], { node
=> $nodename },
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);
147 rollback
=> [ "PVE::API2::LXC::Snapshot", 'rollback', ['vmid', 'snapname'], { node
=> $nodename } , $upid_exit ],
149 template
=> [ "PVE::API2::LXC", 'template', ['vmid'], { node
=> $nodename }],
154 PVE
::CLIHandler
::handle_cmd
($cmddef, "pct", $cmd, \
@ARGV, undef, $0);
162 pct - Tool to manage Linux Containers on Proxmox VE
170 Tool to manage linux containers.
172 =include pve_copyright