line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenVZ::Vzlist; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Call OpenVZ vzlist command from your program |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
#XXX: Need to handle version call |
6
|
|
|
|
|
|
|
#XXX: Need to use 'on_fail' option for validate_with for smoother error |
7
|
|
|
|
|
|
|
# handling. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
137412
|
use 5.006; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
93
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
68
|
|
13
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
69
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
1948
|
use namespace::autoclean; |
|
2
|
|
|
|
|
30240
|
|
|
2
|
|
|
|
|
13
|
|
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
2
|
|
235
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
134
|
|
18
|
2
|
|
|
2
|
|
2161
|
use List::MoreUtils qw( any ); |
|
2
|
|
|
|
|
296671
|
|
|
2
|
|
|
|
|
314
|
|
19
|
2
|
|
|
2
|
|
858
|
use OpenVZ ':all'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
17
|
|
20
|
2
|
|
|
2
|
|
768
|
use Params::Validate ':all'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
602
|
|
21
|
2
|
|
|
2
|
|
3171
|
use Regexp::Common qw( URI net ); |
|
2
|
|
|
|
|
9030
|
|
|
2
|
|
|
|
|
12
|
|
22
|
2
|
|
|
2
|
|
153174
|
use Scalar::Util 'blessed'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
134
|
|
23
|
2
|
|
|
2
|
|
11
|
use Sub::Exporter; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
25
|
|
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
2
|
|
824
|
use parent 'OpenVZ'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
26
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our $VERSION = '0.01'; # VERSION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our $AUTOLOAD; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
{ # "The secret to creativity is knowing how to hide your sources." -Albert Einstein |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
############################################################################ |
35
|
|
|
|
|
|
|
# Public Functions |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my @vzlist_exports; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
push @vzlist_exports, 'execute'; # imported from OpenVZ |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
############################################################################ |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my @fields = qw( |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
bootorder cpulimit cpuunits ctid description hostname ioprio ip laverage name onboot ostemplate status uptime |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
push @fields, map { ( $_, "$_.h", "$_.s" ) } qw( diskinodes diskspace ); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
push @fields, map { ( $_, "$_.b", "$_.f", "$_.l", "$_.m" ) } qw( |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
dcachesize dgramrcvbuf kmemsize lockedpages numfile numflock numiptent numothersock numproc numpty numsiginfo numtcpsock |
54
|
|
|
|
|
|
|
oomguarpages othersockbuf physpages privvmpages shmpages swappages tcprcvbuf tcpsndbuf vmguarpages |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $fields_rx = join q{|}, @fields; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
push @vzlist_exports, 'known_fields'; |
61
|
|
|
|
|
|
|
|
62
|
1
|
50
|
|
1
|
1
|
19365
|
sub known_fields { return wantarray ? @fields : \@fields } |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
############################################################################ |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my %spec = do { |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my %hash = ( |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# XXX: Annoying. Need to submit a bug for this. |
71
|
|
|
|
|
|
|
## no critic qw( Variables::ProhibitPunctuationVars ) |
72
|
|
|
|
|
|
|
all => { type => UNDEF, optional => 1 }, |
73
|
|
|
|
|
|
|
description => { type => SCALAR, optional => 1, regex => qr/^.+$/ }, |
74
|
|
|
|
|
|
|
output => { type => SCALAR, optional => 1, regex => qr/^(?:$fields_rx)(?:,$fields_rx)*$/i }, |
75
|
|
|
|
|
|
|
sort => { type => SCALAR, optional => 1, regex => qr/^-?(?:$fields_rx)$/i }, |
76
|
|
|
|
|
|
|
## use critic |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my %same = ( |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
all => [qw( list name no-header stopped )], |
83
|
|
|
|
|
|
|
description => [qw( hostname name_filter )], |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
for my $key ( keys %same ) { |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
$hash{ $_ } = $hash{ $key } for @{ $same{ $key } }; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
%hash; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
}; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my %hash = ( command => 'vzlist' ); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
push @vzlist_exports, 'vzlist'; # imported from OpenVZ |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub vzlist { ## no critic qw( Subroutines::RequireArgUnpacking ) |
102
|
|
|
|
|
|
|
|
103
|
10
|
100
|
|
10
|
1
|
60055
|
shift if blessed $_[0]; |
104
|
|
|
|
|
|
|
|
105
|
10
|
|
|
|
|
281
|
my %arg = validate_with( params => \@_, spec => \%spec ); |
106
|
|
|
|
|
|
|
|
107
|
2
|
|
|
|
|
20
|
my @params; |
108
|
|
|
|
|
|
|
|
109
|
2
|
|
|
|
|
11
|
for my $arg_name ( keys %arg ) { |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
0
|
push @params, "--$arg_name"; |
112
|
|
|
|
|
|
|
|
113
|
0
|
0
|
0
|
|
|
0
|
push @params, $arg{ $arg_name } |
114
|
|
|
|
|
|
|
if defined $arg{ $arg_name } && $arg{ $arg_name } ne ''; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
2
|
|
|
|
|
9
|
@params = grep { $_ ne '' } @params; |
|
0
|
|
|
|
|
0
|
|
119
|
|
|
|
|
|
|
|
120
|
2
|
|
|
|
|
12
|
$hash{ params } = \@params; |
121
|
|
|
|
|
|
|
|
122
|
2
|
|
|
|
|
21
|
return execute( \%hash ); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
} ## end sub vzlist |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
############################################################################ |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
push @vzlist_exports, 'known_options'; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my @vzlist = map { "[$_]" } keys %spec; |
131
|
|
|
|
|
|
|
|
132
|
1
|
50
|
|
1
|
1
|
56
|
sub known_options { return wantarray ? @vzlist : \@vzlist } |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
############################################################################ |
135
|
|
|
|
|
|
|
# Internal Functions |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# for oop stuff |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# XXX: Do we need/want to support methods for the various options (what is returned from subcommand_specs)? |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# sub AUTOLOAD { ## no critic qw( Subroutines::RequireArgUnpacking ClassHierarchies::ProhibitAutoloading ) |
142
|
|
|
|
|
|
|
# |
143
|
|
|
|
|
|
|
# carp "$_[0] is not an object" |
144
|
|
|
|
|
|
|
# unless blessed $_[0]; |
145
|
|
|
|
|
|
|
# |
146
|
|
|
|
|
|
|
# ( my $subcommand = $AUTOLOAD ) =~ s/^.*:://; |
147
|
|
|
|
|
|
|
# |
148
|
|
|
|
|
|
|
# carp "$subcommand is not a valid method" |
149
|
|
|
|
|
|
|
# unless exists $vzctl{ $subcommand }; |
150
|
|
|
|
|
|
|
# |
151
|
|
|
|
|
|
|
# ## no critic qw( TestingAndDebugging::ProhibitNoStrict References::ProhibitDoubleSigils ) |
152
|
|
|
|
|
|
|
# no strict 'refs'; |
153
|
|
|
|
|
|
|
# *$AUTOLOAD = _generate_subcommand( undef, $subcommand ); |
154
|
|
|
|
|
|
|
# |
155
|
|
|
|
|
|
|
# goto &$AUTOLOAD; |
156
|
|
|
|
|
|
|
# ## use critic |
157
|
|
|
|
|
|
|
# |
158
|
|
|
|
|
|
|
# } ## end sub AUTOLOAD |
159
|
|
|
|
|
|
|
# |
160
|
|
|
|
|
|
|
# # AUTOLOAD assumes DESTROY exists |
161
|
|
|
|
|
|
|
# DESTROY { } |
162
|
|
|
|
|
|
|
# |
163
|
|
|
|
|
|
|
# push @vzctl_exports, ( $_ => \&_generate_subcommand ) for keys %vzctl; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
############################################################################ |
166
|
|
|
|
|
|
|
# Setup exporter |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
my $config = { |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
exports => \@vzlist_exports, |
171
|
|
|
|
|
|
|
groups => {}, |
172
|
|
|
|
|
|
|
collectors => [], |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
}; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Sub::Exporter::setup_exporter( $config ); |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
} # Coming out from under! |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
1; |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
__END__ |