| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package OpenVZ; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# no critic qw( ErrorHandling::RequireUseOfExceptions ) |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Base class for OpenVZ utilities like vzctl |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#XXX: We need to load and parse the VZ system config file. |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
22
|
|
|
22
|
|
245555
|
use 5.006; |
|
|
22
|
|
|
|
|
76
|
|
|
|
22
|
|
|
|
|
945
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
22
|
|
|
22
|
|
121
|
use strict; |
|
|
22
|
|
|
|
|
60
|
|
|
|
22
|
|
|
|
|
776
|
|
|
13
|
22
|
|
|
22
|
|
128
|
use warnings; |
|
|
22
|
|
|
|
|
40
|
|
|
|
22
|
|
|
|
|
1083
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# This way, we don't need to remember to use autoclean in our submodules. |
|
16
|
|
|
|
|
|
|
#use namespace::autoclean (); |
|
17
|
|
|
|
|
|
|
#sub import { return namespace::autoclean->import( -cleanee => scalar caller ) } |
|
18
|
22
|
|
|
22
|
|
24031
|
use namespace::sweep (); |
|
|
22
|
|
|
|
|
501783
|
|
|
|
22
|
|
|
|
|
2204
|
|
|
19
|
|
|
|
|
|
|
sub import { return namespace::sweep->import( -cleanee => scalar caller, -also => qr/^_\w*$/ ) } |
|
20
|
|
|
|
|
|
|
|
|
21
|
22
|
|
|
22
|
|
239
|
use Carp; |
|
|
22
|
|
|
|
|
55
|
|
|
|
22
|
|
|
|
|
1591
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#use Config::NameValue; |
|
24
|
|
|
|
|
|
|
#use Regexp::Common qw( URI net ); |
|
25
|
|
|
|
|
|
|
|
|
26
|
22
|
|
|
22
|
|
27178
|
use File::Which; |
|
|
22
|
|
|
|
|
26514
|
|
|
|
22
|
|
|
|
|
1243
|
|
|
27
|
22
|
|
|
22
|
|
21523
|
use IPC::Run3::Simple; |
|
|
22
|
|
|
|
|
1211941
|
|
|
|
22
|
|
|
|
|
1422
|
|
|
28
|
22
|
|
|
22
|
|
4373
|
use Params::Validate qw( validate ARRAYREF ); |
|
|
22
|
|
|
|
|
29580
|
|
|
|
22
|
|
|
|
|
1331
|
|
|
29
|
22
|
|
|
22
|
|
145
|
use Scalar::Util 'blessed'; |
|
|
22
|
|
|
|
|
51
|
|
|
|
22
|
|
|
|
|
1031
|
|
|
30
|
22
|
|
|
22
|
|
38653
|
use Sub::Exporter; |
|
|
22
|
|
|
|
|
291725
|
|
|
|
22
|
|
|
|
|
167
|
|
|
31
|
22
|
|
|
22
|
|
114444
|
use Sub::Exporter::Util 'curry_method'; |
|
|
22
|
|
|
|
|
43413
|
|
|
|
22
|
|
|
|
|
160
|
|
|
32
|
22
|
|
|
22
|
|
26322
|
use Sub::Exporter::ForMethods 'method_installer'; |
|
|
22
|
|
|
|
|
19258
|
|
|
|
22
|
|
|
|
|
167
|
|
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
our $VERSION = '0.01'; # VERSION |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
############################################################################ |
|
37
|
|
|
|
|
|
|
# Public Functions |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
{ # Quick! Hide!! |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my @exports; |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# @exports holds the names of functions to be exported. The easiest way to |
|
45
|
|
|
|
|
|
|
# maintain this is to push the name of the function right before it is |
|
46
|
|
|
|
|
|
|
# defined. |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#push @exports, 'new'; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $object; ## no critic qw( Bangs::ProhibitVagueNames ) |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub new { ## no critic qw( Bangs::ProhibitVagueNames Subroutines::RequireArgUnpacking ) |
|
53
|
|
|
|
|
|
|
|
|
54
|
3606
|
100
|
66
|
3606
|
1
|
79142147
|
shift if blessed $_[0] or $_[0] eq __PACKAGE__; |
|
55
|
3606
|
100
|
|
|
|
31301
|
croak 'OpenVZ is designed to be an abstract class' if @_ == 0; |
|
56
|
3605
|
|
33
|
|
|
54794
|
return bless \$object, ref $_[0] || $_[0]; ## no critic qw( Bangs::ProhibitVagueNames ) |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
## use critic |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my %program; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Determines if the specified command is installed, what its path is and |
|
64
|
|
|
|
|
|
|
# caches it. Used in execute. |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $find_command = sub { |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
shift if blessed $_[0] or $_[0] eq __PACKAGE__; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
#my ( $pgm, $params ) = @_; |
|
71
|
|
|
|
|
|
|
my $pgm = shift; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
return 1 |
|
74
|
|
|
|
|
|
|
if exists $program{ path }{ $pgm }; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$program{ path }{ $pgm } = which( $pgm ) |
|
77
|
|
|
|
|
|
|
or croak "Could not find $pgm in path ($ENV{PATH})"; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
return 1; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
}; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
push @exports, 'execute'; |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub execute { ## no critic qw( Subroutines::RequireArgUnpacking ) |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# We're doing the funky twisty stuff here so we can handle either functional or oop style calls. |
|
88
|
|
|
|
|
|
|
# I think this is because of the way Sub::Exporter handles things, but I'm not sure. |
|
89
|
3814
|
50
|
33
|
3814
|
1
|
2025330
|
shift if blessed $_[0] or $_[0] eq __PACKAGE__; |
|
90
|
3814
|
100
|
|
|
|
22543
|
shift if blessed $_[0]; |
|
91
|
|
|
|
|
|
|
|
|
92
|
3814
|
|
|
|
|
174546
|
my %arg = validate( |
|
93
|
|
|
|
|
|
|
@_, { |
|
94
|
|
|
|
|
|
|
'command' => { callbacks => { 'find command path' => $find_command } }, |
|
95
|
|
|
|
|
|
|
'params' => { type => ARRAYREF, optional => 1 }, |
|
96
|
|
|
|
|
|
|
} ); |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# XXX: Need to handle also the case of a hashref |
|
99
|
|
|
|
|
|
|
|
|
100
|
3794
|
|
|
|
|
55950
|
my @args = $program{ path }{ $arg{ command } }; |
|
101
|
3794
|
100
|
|
|
|
23056
|
push @args, @{ $arg{ params } } if exists $arg{ params }; |
|
|
3790
|
|
|
|
|
33612
|
|
|
102
|
3794
|
|
|
|
|
40495
|
return run3( \@args ); |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
} ## end sub execute |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
############################################################################ |
|
107
|
|
|
|
|
|
|
# Utility Functions - not for general consumption |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
############################################################################ |
|
110
|
|
|
|
|
|
|
# Setup exporter |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my %exports = map { ( $_ => curry_method ) } @exports; |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $config = { |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
exports => \%exports, |
|
117
|
|
|
|
|
|
|
installer => method_installer, |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
}; |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Sub::Exporter::setup_exporter( $config ); |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
} ## end hiding |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
__END__ |