line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Linux::Virt::Plugin::Openvz; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Linux::Virt::Plugin::Openvz::VERSION = '0.15'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
BEGIN { |
6
|
1
|
|
|
1
|
|
2709
|
$Linux::Virt::Plugin::Openvz::AUTHORITY = 'cpan:TEX'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
# ABSTRACT: OpenVZ plugin for Linux::Virt |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
32
|
use 5.010_000; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
40
|
|
11
|
1
|
|
|
1
|
|
6
|
use mro 'c3'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
12
|
1
|
|
|
1
|
|
31
|
use feature ':5.10'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
196
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
9
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
15
|
1
|
|
|
1
|
|
8796
|
use namespace::autoclean; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
12
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# use IO::Handle; |
18
|
|
|
|
|
|
|
# use autodie; |
19
|
|
|
|
|
|
|
# use MooseX::Params::Validate; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
extends 'Linux::Virt::Plugin'; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
0
|
|
|
sub _init_priority { return 10; } |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub is_vm { |
26
|
0
|
|
|
0
|
|
|
my $self = shift; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# OpenVZ |
29
|
0
|
0
|
0
|
|
|
|
if ( -d "/proc/vz" && -e "/proc/vz/veinfo" && !-e "/proc/vz/version" ) { |
|
|
|
0
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $ret = qx(/bin/cat /proc/vz/veinfo | /usr/bin/wc -l); |
31
|
0
|
|
|
|
|
|
chomp($ret); |
32
|
0
|
0
|
|
|
|
|
if ( $ret == 1 ) { |
33
|
0
|
|
|
|
|
|
return 1; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} ## end if ( -d "/proc/vz" && ...) |
36
|
0
|
|
|
|
|
|
return; |
37
|
|
|
|
|
|
|
} ## end sub is_vm |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub is_host { |
40
|
0
|
|
|
0
|
|
|
my $self = shift; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# OpenVZ |
43
|
0
|
0
|
0
|
|
|
|
if ( -d "/proc/vz" && -e "/proc/vz/veinfo" ) { |
44
|
0
|
|
|
|
|
|
my $ret = qx(/bin/cat /proc/vz/veinfo | /usr/bin/wc -l); |
45
|
0
|
|
|
|
|
|
chomp($ret); |
46
|
0
|
0
|
0
|
|
|
|
if ( $ret >= 1 && -e "/proc/vz/version" ) { |
47
|
0
|
|
|
|
|
|
return 1; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} ## end if ( -d "/proc/vz" && ...) |
50
|
0
|
|
|
|
|
|
return; |
51
|
|
|
|
|
|
|
} ## end sub is_host |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub vms { |
54
|
0
|
|
|
0
|
|
|
my $self = shift; |
55
|
0
|
|
|
|
|
|
my $vserver_ref = shift; |
56
|
0
|
|
0
|
|
|
|
my $opts = shift || {}; |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
return unless -x '/usr/sbin/vzlist'; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
local $ENV{LANG} = "C"; |
61
|
0
|
|
|
|
|
|
my $OVZ; |
62
|
0
|
0
|
|
|
|
|
if ( !open( $OVZ, '-|', "/usr/sbin/vzlist" ) ) { |
63
|
0
|
|
|
|
|
|
my $msg = "Could not execute /usr/sbin/vzlist! Is vzctl installed?: $!"; |
64
|
0
|
|
|
|
|
|
$self->logger()->log( message => $msg, level => 'warning', ); |
65
|
0
|
|
|
|
|
|
return; |
66
|
|
|
|
|
|
|
} |
67
|
0
|
|
|
|
|
|
while ( my $line = <$OVZ> ) { |
68
|
0
|
0
|
|
|
|
|
next if $line =~ m/^\s+CTID\s+NPROC\s+STATUS\s+IP_ADDR\s+HOSTNAME/; |
69
|
0
|
|
|
|
|
|
my ( $ctid, $nrpoc, $status, $ip, $hostname ) = split /\s+/, $line; |
70
|
0
|
0
|
|
|
|
|
next unless $status =~ m/running/; |
71
|
0
|
|
|
|
|
|
$hostname =~ s/^\s+//; |
72
|
0
|
|
|
|
|
|
$hostname =~ s/\s+$//; |
73
|
0
|
|
|
|
|
|
my $name = $hostname; |
74
|
0
|
|
|
|
|
|
$vserver_ref->{$name}{'virt'}{'type'} = 'openvz'; |
75
|
0
|
|
|
|
|
|
$vserver_ref->{$name}{'ctx'} = $ctid; |
76
|
0
|
|
|
|
|
|
$vserver_ref->{$name}{'proc'} = $nrpoc; |
77
|
0
|
|
|
|
|
|
$vserver_ref->{$name}{'ips'}{$ip}{'ip'} = $ip; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
} ## end while ( my $line = <$OVZ>) |
80
|
0
|
|
|
|
|
|
close($OVZ); |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return 1; |
83
|
|
|
|
|
|
|
} ## end sub vms |
84
|
|
|
|
|
|
|
|
85
|
1
|
|
|
1
|
|
1091
|
no Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
86
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=pod |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=encoding utf-8 |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 NAME |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Linux::Virt::Plugin::Openvz - OpenVZ plugin for Linux::Virt |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 METHODS |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 is_host |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Returns a true value if this is run on a OpenVZ capable host. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 is_vm |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Returns a true value if this is run inside an OpenVZ VE. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 vms |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
List all running OpenVZ VMs. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 NAME |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Linux::Virt::Plugin::Openvz - OpenVZ plugin for Linux::Virt. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 AUTHOR |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Dominik Schulz <dominik.schulz@gauner.org> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Dominik Schulz. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
127
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |