]> git.proxmox.com Git - pve-manager.git/blob - bin/pvectl
834c9e2b0e1fbd216155f0567c5e2aa803cd795e
[pve-manager.git] / bin / pvectl
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use PVE::Tools qw(extract_param);
6 use PVE::Cluster qw(cfs_register_file cfs_read_file);
7 use PVE::SafeSyslog;
8 use PVE::INotify;
9 use PVE::RPCEnvironment;
10 use PVE::CLIHandler;
11 use PVE::API2::OpenVZ;
12
13 use Data::Dumper; # fixme: remove
14
15 use base qw(PVE::CLIHandler);
16
17 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
18
19 initlog('pvectl');
20
21 die "please run as root\n" if $> != 0;
22
23 PVE::INotify::inotify_init();
24 my $nodename = PVE::INotify::nodename();
25
26 my $rpcenv = PVE::RPCEnvironment->init('cli');
27
28 $rpcenv->init_request();
29 $rpcenv->set_language($ENV{LANG});
30 $rpcenv->set_user('root@pam');
31
32 my $upid_exit = sub {
33 my $upid = shift;
34 my $status = PVE::Tools::upid_read_status($upid);
35 exit($status eq 'OK' ? 0 : -1);
36 };
37
38 my $cmddef = {
39
40 list => [ "PVE::API2::OpenVZ", 'vmlist', [],
41 { node => $nodename }, sub {
42 my $vmlist = shift;
43
44 exit 0 if (!scalar(@$vmlist));
45
46 printf "%10s %-20s %-10s %-10s %-12s\n",
47 qw(VMID NAME STATUS MEM(MB) DISK(GB));
48
49 foreach my $rec (sort { $a->{vmid} <=> $b->{vmid} } @$vmlist) {
50 printf "%10s %-20s %-10s %-10s %-12.2f\n", $rec->{vmid}, $rec->{name} || '',
51 $rec->{status},
52 ($rec->{maxmem} || 0)/(1024*1024),
53 ($rec->{maxdisk} || 0)/(1024*1024*1024);
54 }
55 } ],
56
57 create => [ 'PVE::API2::OpenVZ', 'create_vm', ['vmid', 'ostemplate'], { node => $nodename }, $upid_exit ],
58 destroy => [ 'PVE::API2::OpenVZ', 'destroy_vm', ['vmid'], { node => $nodename }, $upid_exit ],
59
60 set => [ "PVE::API2::OpenVZ", 'update_vm', ['vmid'], { node => $nodename } ],
61
62 config => [ "PVE::API2::OpenVZ", 'vm_config', ['vmid'],
63 { node => $nodename }, sub {
64 my $config = shift;
65 foreach my $k (sort (keys %$config)) {
66 next if $k eq 'digest';
67 my $v = $config->{$k};
68 if ($k eq 'description') {
69 $v = PVE::Tools::encode_text($v);
70 }
71 print "$k: $v\n";
72 }
73 }],
74
75 start => [ 'PVE::API2::OpenVZ', 'vm_start', ['vmid'], { node => $nodename }, $upid_exit],
76 shutdown => [ 'PVE::API2::OpenVZ', 'vm_shutdown', ['vmid'], { node => $nodename }, $upid_exit],
77 stop => [ 'PVE::API2::OpenVZ', 'vm_stop', ['vmid'], { node => $nodename }, $upid_exit],
78 mount => [ 'PVE::API2::OpenVZ', 'vm_mount', ['vmid'], { node => $nodename }, $upid_exit],
79 umount => [ 'PVE::API2::OpenVZ', 'vm_umount', ['vmid'], { node => $nodename }, $upid_exit],
80 migrate => [ "PVE::API2::OpenVZ", 'migrate_vm', ['vmid', 'target'], { node => $nodename }, $upid_exit],
81 };
82
83 my $cmd = shift;
84
85 PVE::CLIHandler::handle_cmd($cmddef, "pvectl", $cmd, \@ARGV, undef, $0);
86
87 exit 0;
88
89 __END__
90
91 =head1 NAME
92
93 pvectl - vzctl wrapper to manage OpenVZ containers
94
95 =head1 SYNOPSIS
96
97 =include synopsis
98
99 =head1 DESCRIPTION
100
101 This is a small wrapper around vztl.
102
103 =include pve_copyright