Virt/Plugin/Vserver.pm

filter: Statementstmt 14.0% 32 / 228 Branchbran 0.0% 0 / 96 Conditioncond 0.0% 0 / 30 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 50.0% 10 / 20 Podpod 100% 6 / 6 totaltotal 12.0% 48 / 397 CC 66 SCAR 65.9
CC
66
Cov
9%
vms
1560.0
_get_vs_name_by_ctx
56.0
is_host
30.0
CRAP 728.3
↑ Summary Virt/Plugin/Libvirt.pm »
1 package Linux::Virt::Plugin::Vserver;
2 {
3 2 $Linux::Virt::Plugin::Vserver::VERSION = '0.15';
4 }
5 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 $Linux::Virt::Plugin::Vserver::AUTHORITY = 'cpan:TEX';
7 }
8 # ABSTRACT: Linux-Vserver plugin for Linux::Virt
9  
10 2 ▶use 5.010_000;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use feature ':5.10';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # use IO::Handle;
18 # use autodie;
19 # use MooseX::Params::Validate;
20  
21 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use English '-no_match_vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use File::Blarf;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 2 extends 'Linux::Virt::Plugin';
26  
27 0 ▶sub _init_priority { return 10; }
Subroutine _init_priority: not called CC=1 SCAR=6.9
28  
29 # Check if this is a Vserver/VE
30 # undef - no vserver
31 # 1 - Linux-Vserver
32 0 ▶sub is_vm {
Subroutine is_vm: not called CC=4 SCAR=30.0
Pod documented
33 0 my $self = shift;
34  
35 # Linux-Vserver
36 0 ▶ if ( open( my $FH, '<', "/proc/self/status" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $FH, "<", "/proc/self/status") 0 0 0
37 0 local $/ = undef;
38 0 my $proc = $FH;
39 0 close($FH);
40 0 ▶ if ( $proc =~ m/(s_context|VxID):\s+(\d+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proc =~ /(s_context|VxID):\s+(\d+)/) 0 0 0
41 0 my $cid = $2;
42 0 ▶ if ($cid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cid) 0 0 0
43  
44 # Ok, this is a Linux-Vserver
45 0 return 1;
46 }
47 } ## end if ( $proc =~ m/(s_context|VxID):\s+(\d+)/)
48 } ## end if ( open( my $FH, '<'...))
49  
50 # No Vserver
51 0 return;
52 } ## end sub is_vm
53  
54 # Check if this is a Linux-Vserver Host (i.e. running an vserver-enabled kernel)
55 # undef - no vserver
56 # 1 - Linux Vserver
57 0 ▶sub is_host {
Subroutine is_host: not called CC=5 SCAR=34.0
Pod documented
58 0 my $self = shift;
59  
60 # Linux-Vserver
61 0 ▶ if ( open( my $FH, '<', "/proc/self/status" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $FH, "<", "/proc/self/status") 0 0 0
62 0 local $/ = undef;
63 0 my $proc = <$FH>;
64 0 close($FH);
65 0 ▶ if ( $proc =~ m/(s_context|VxID):\s+(\d+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proc =~ /(s_context|VxID):\s+(\d+)/) 0 0 0
66 0 my $cid = $2;
67 0 ▶ if ( $cid && $cid == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cid and $cid == 0) 0 0 0
Condition0%0/3
$cid and $cid == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$cid and $cid == 0
$cid $cid == 0
Truth table0%0/3
A and B
A= $cidB= $cid == 0
ABresult
0X0
100
111
68 0 return 1;
69 }
70 } ## end if ( $proc =~ m/(s_context|VxID):\s+(\d+)/)
71 } ## end if ( open( my $FH, '<'...))
72  
73 # No Vserver-enabled host
74 0 return;
75 } ## end sub is_host
76  
77 0 ▶sub _get_arch_by_ctx {
Subroutine _get_arch_by_ctx: not called CC=5 SCAR=34.0
78 0 my $self = shift;
79 0 my $ctx = shift;
80  
81 0 my $ctx_file = "/proc/virtual/$ctx/nsproxy";
82 0 ▶ if ( -f $ctx_file && open( my $FH, "<", $ctx_file ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $ctx_file and open my $FH, "<", $ctx_file) 0 0 0
Condition0%0/3
-f $ctx_file and open my $FH, "<", $ctx_file
!ll&&!rl&&r
000
MC/DC0%0/2
-f $ctx_file and open my $FH, "<", $ctx_file
-f $ctx_file open my $FH, "<", $ctx_file
Truth table0%0/3
A and B
A= -f $ctx_fileB= open my $FH, "<", $ctx_file
ABresult
0X0
100
111
83 0 ▶ while ( my $line = <$FH> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $FH)) 0 0 0
84 0 ▶ if ( $line =~ m/^Machine:\s*(\S+)\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^Machine:\s*(\S+)\s*$/) 0 0 0
85 0 my $arch = $1;
86 0 close($FH);
87 0 return $arch;
88 }
89 } ## end while ( my $line = <$FH> )
90 0 close($FH);
91 } ## end if ( -f $ctx_file && open...)
92 0 return;
93 } ## end sub _get_arch_by_ctx
94  
95 # We can't rely on the names reported by
96 # vserver-stat, they are often truncated,
97 # so we'll find the name by the (possible)
98 # dynamic context id in /etc/vserver/<vs>/run
99 0 ▶sub _get_vs_name_by_ctx {
Subroutine _get_vs_name_by_ctx: not called CC=7 SCAR=40.3
100 0 my $self = shift;
101 0 my $ctx = shift;
102  
103 0 my $name = undef;
104  
105 0 my $basedir = "/etc/vservers";
106 0 ▶ if ( opendir( my $DH, $basedir ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir my $DH, $basedir) 0 0 0
107 0 ▶ while ( my $vs_name = readdir($DH) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $vs_name = readdir $DH)) 0 0 0
108 0 my $entry = "$basedir/$vs_name";
109  
110 # skip non-dirs
111 0 ▶ next if ( !-d $entry );
Branch: 1 branch
BranchTrueFalseTotal
unless -d $entry 0 0 0
112  
113 # skip self and parent
114 0 ▶ next if $entry =~ m/\.\.?/;
Branch: 1 branch
BranchTrueFalseTotal
if $entry =~ /\.\.?/ 0 0 0
115 0 my $ctx_file = "$entry/run";
116 0 ▶ if ( -f $ctx_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $ctx_file) 0 0 0
117 0 my $ctx_test = &File::Blarf::slurp( $ctx_file, { Chomp => 1, } );
118 0 $ctx_test =~ s/^\s+//;
119 0 $ctx_test =~ s/\s+$//;
120 0 ▶ if ( $ctx eq $ctx_test ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx eq $ctx_test) 0 0 0
121 0 closedir($DH);
122 0 return $vs_name;
123 }
124 } ## end if ( -f $ctx_file )
125 } ## end while ( my $vs_name = readdir...)
126 0 closedir($DH);
127 } ## end if ( opendir( my $DH, ...))
128 0 return;
129 } ## end sub _get_vs_name_by_ctx
130  
131 0 ▶sub vms {
Subroutine vms: not called CC=39 SCAR=73.5
Pod documented
132 0 my $self = shift;
133 0 my $vserver_ref = shift;
134 0 ▶ my $opts = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
135 0 local $ENV{LANG} = "C";
136 0 my $VSS;
137 0 ▶ if ( !open( $VSS, '-|', "/usr/sbin/vserver-stat" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open $VSS, "-|", "/usr/sbin/vserver-stat") 0 0 0
138 0 my $msg = "Could not execute /usr/sbin/vserver-stat! Is util-vserver installed?: $!";
139 0 $self->logger()->log( message => $msg, level => 'error', );
140 0 return;
141 }
142 0 ▶ while ( my $line = <$VSS> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $VSS)) 0 0 0
143 0 ▶ next if $line =~ m/^CTX\s+PROC\s+VSZ/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^CTX\s+PROC\s+VSZ/ 0 0 0
144 0 $line =~ s/^\s+//;
145 0 $line =~ s/\s+$//;
146 0 my ( $ctx, $proc, $vsz, $rss, $usertime, $systime, $uptime, $name ) = split( /\s+/, $line );
147 0 ▶ $name = $self->_get_vs_name_by_ctx($ctx) || $name;
Condition0%0/3
$self->_get_vs_name_by_ctx($ctx) || $name
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_get_vs_name_by_ctx($ctx) || $name
$self->_get_vs_name_by_ctx($ctx) $name
Truth table0%0/3
A || B
A= $self->_get_vs_name_by_ctx($ctx)B= $name
ABresult
1X1
011
000
148 0 $vserver_ref->{$name}{'ctx'} = $ctx;
149 0 $vserver_ref->{$name}{'proc'} = $proc;
150 0 $vserver_ref->{$name}{'vsz'} = $vsz;
151 0 $vserver_ref->{$name}{'rss'} = $rss;
152 0 $vserver_ref->{$name}{'usertime'} = $usertime;
153 0 $vserver_ref->{$name}{'systime'} = $systime;
154 0 $vserver_ref->{$name}{'uptime'} = $uptime;
155 0 $vserver_ref->{$name}{'name'} = $name;
156  
157 } ## end while ( my $line = <$VSS>)
158 0 close($VSS);
159  
160 # post-process all vservers, gather remaining information
161 # - get init status (apps/init/mark -> default?)
162 # - get utsnodename
163 # - get caps
164 # - get limits
165 # - get ips
166 0 foreach my $name ( keys %{$vserver_ref} ) {
167  
168 # this is a linux-vserver
169 0 $vserver_ref->{$name}{'virt'}{'type'} = 'vserver';
170  
171 # read arch from nsproxy
172 0 $vserver_ref->{$name}{'virt'}{'arch'} = $self->_get_arch_by_ctx( $vserver_ref->{$name}{'ctx'} );
173  
174 # get vdir from /etc/vservers/<vs>/vdir symlink
175 0 my $vdir = "/etc/vservers/$name/vdir";
176 0 ▶ if ( -l $vdir ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-l $vdir) 0 0 0
177 0 $vserver_ref->{$name}{'vdir'} = readlink($vdir);
178 }
179  
180 # all spaces may be reported in GB or MB, so convert if needed
181 # convert GB to MB
182 0 foreach my $prop (qw(vsz rss)) {
183  
184 # remove trailing MB indicator
185 0 $vserver_ref->{$name}{$prop} =~ s/m$//i;
186 0 ▶ if ( $vserver_ref->{$name}{$prop} =~ m/g$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vserver_ref->{$name}{$prop} =~ /g$/i) 0 0 0
187 0 $vserver_ref->{$name}{$prop} =~ s/g$//i;
188 0 $vserver_ref->{$name}{$prop} *= 1024;
189 }
190 } ## end foreach my $prop (qw(vsz rss))
191  
192 # all time are reported as XdYhZ or XhYmZ or XmYsZ
193 # convert all to seconds
194 0 foreach my $prop (qw(usertime systime uptime)) {
195 0 my ( $day, $hour, $minute, $second, $ms );
196 0 ▶ if ( $vserver_ref->{$name}{$prop} =~ m/^(\d+)d0?(\d+)h0?(\d+)$/i ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($vserver_ref->{$name}{$prop} =~ /^(\d+)d0?(\d+)h0?(\d+)$/i) { } 0 0 0
elsif ($vserver_ref->{$name}{$prop} =~ /^(\d+)h0?(\d+)m0?(\d+)$/i) { } 0 0 0
elsif ($vserver_ref->{$name}{$prop} =~ /^(\d+)m0?(\d+)s0?(\d+)$/i) { } 0 0 0
197 0 ( $day, $hour, $minute, $second, $ms ) = ( $1, $2, $3, 0, 0 );
198 }
199 elsif ( $vserver_ref->{$name}{$prop} =~ m/^(\d+)h0?(\d+)m0?(\d+)$/i ) {
200 0 ( $day, $hour, $minute, $second, $ms ) = ( 0, $1, $2, $3, 0 );
201 }
202 elsif ( $vserver_ref->{$name}{$prop} =~ m/^(\d+)m0?(\d+)s0?(\d+)$/i ) {
203 0 ( $day, $hour, $minute, $second, $ms ) = ( 0, 0, $1, $2, $3 );
204 }
205 else {
206 0 ( $day, $hour, $minute, $second, $ms ) = ( 0, 0, 0, 0, 0 );
207 }
208 0 $vserver_ref->{$name}{$prop} = $second + $minute * 60 + $hour * 60 * 60 + $day * 60 * 60 * 24;
209 } ## end foreach my $prop (qw(usertime systime uptime))
210  
211 # - get init status (apps/init/mark -> default?)
212 0 $vserver_ref->{$name}{'init'} = 0;
213 0 my $init_file = "/etc/vservers/$name/apps/init/mark";
214 0 ▶ if ( -e $init_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $init_file) 0 0 0
215 0 ▶ if ( open( my $FH, "<", $init_file ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $FH, "<", $init_file) 0 0 0
216 0 my $mark = <$FH>;
217 0 close($FH);
218 0 chomp($mark);
219 0 ▶ if ( $mark eq 'default' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mark eq "default") 0 0 0
220 0 $vserver_ref->{$name}{'init'} = 1;
221 }
222 } ## end if ( open( my $FH, "<"...))
223 } ## end if ( -e $init_file )
224  
225 # - get utsnodename
226 0 $vserver_ref->{$name}{'utsnodename'} = $name;
227 0 my $uts_nodename_file = "/etc/vservers/$name/uts/nodename";
228 0 ▶ if ( -e $uts_nodename_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $uts_nodename_file) 0 0 0
229 0 ▶ if ( open( my $FH, "<", $uts_nodename_file ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $FH, "<", $uts_nodename_file) 0 0 0
230 0 my $uts_nodename = <$FH>;
231 0 close($FH);
232 0 chomp($uts_nodename);
233 0 $vserver_ref->{$name}{'utsnodename'} = $uts_nodename;
234 } ## end if ( open( my $FH, "<"...))
235 } ## end if ( -e $uts_nodename_file)
236  
237 # - get caps
238 # see http://www.linux-vserver.org/Capabilities_and_Flags
239 # and http://www.linux-vserver.org/util-vserver:Capabilities_and_Flags
240 0 foreach my $cap_name (qw(ccapabilities flags nflags bcapabilities ncapabilities)) {
241 0 $vserver_ref->{$name}{$cap_name} = undef;
242 0 my $caps_file = "/etc/vservers/$name/$cap_name";
243 0 ▶ if ( -e $caps_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $caps_file) 0 0 0
244 0 ▶ if ( open( my $FH, "<", $caps_file ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $FH, "<", $caps_file) 0 0 0
245 0 ▶ while ( my $cap = <$FH> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $cap = readline $FH)) 0 0 0
246 0 chomp($cap);
247 0 $vserver_ref->{$name}{$cap_name}{$cap} = 1;
248 }
249 0 close($FH);
250 } ## end if ( open( my $FH, "<"...))
251 } ## end if ( -e $caps_file )
252 } ## end foreach my $cap_name (qw(ccapabilities flags nflags bcapabilities ncapabilities))
253  
254 # - get limits
255 0 my $limits_file = "/proc/virtual/" . $vserver_ref->{$name}{'ctx'} . "/limit";
256 0 ▶ if ( -e $limits_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $limits_file) 0 0 0
257 0 ▶ if ( open( my $FH, "<", $limits_file ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $FH, "<", $limits_file) 0 0 0
258 0 ▶ while ( my $line = <$FH> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $FH)) 0 0 0
259 0 chomp($line);
260  
261 # table header
262 0 ▶ next if $line =~ m/^Limit\s+/i;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^Limit\s+/i 0 0 0
263 0 my ( $res, $current, $min, $max, $soft, $hard, $hits ) = split( /[\s\/]+/, $line );
264  
265 # remove trailing ':'
266 0 $res =~ s/:$//;
267  
268 # remove trailing '/'
269 0 $min =~ s#/$##;
270 0 $soft =~ s#/$##;
271  
272 # skip resources w/o limit
273 0 ▶ next if ( $min == -1 && $max == -1 );
Branch: 1 branch
BranchTrueFalseTotal
if $min == -1 and $max == -1 0 0 0
Condition0%0/3
$min == -1 and $max == -1
!ll&&!rl&&r
000
MC/DC0%0/2
$min == -1 and $max == -1
$min == -1 $max == -1
Truth table0%0/3
A and B
A= $min == -1B= $max == -1
ABresult
0X0
100
111
274  
275 0 $vserver_ref->{$name}{'limits'}{$res}{'current'} = $current;
276 0 $vserver_ref->{$name}{'limits'}{$res}{'min'} = $min;
277 0 $vserver_ref->{$name}{'limits'}{$res}{'max'} = $max;
278 0 $vserver_ref->{$name}{'limits'}{$res}{'soft'} = $soft;
279 0 $vserver_ref->{$name}{'limits'}{$res}{'hard'} = $hard;
280 0 $vserver_ref->{$name}{'limits'}{$res}{'hits'} = $hits;
281 } ## end while ( my $line = <$FH> )
282 0 close($FH);
283 } ## end if ( open( my $FH, "<"...))
284 } ## end if ( -e $limits_file )
285  
286 # - get ips
287 # any interfaces defined at all?
288 0 my $if_dir = '/etc/vservers/'.$name.'/interfaces';
289 0 ▶ if ( -d $if_dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $if_dir) 0 0 0
290 0 ▶ if ( opendir( my $DH, $if_dir ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir my $DH, $if_dir) 0 0 0
291 0 ▶ while ( my $dir_entry = readdir($DH) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $dir_entry = readdir $DH)) 0 0 0
292 0 ▶ next if $dir_entry =~ m/\.\.?/;
Branch: 1 branch
BranchTrueFalseTotal
if $dir_entry =~ /\.\.?/ 0 0 0
293 0 my $dir = "$if_dir/$dir_entry";
294 0 my $ip_file = "$dir/ip";
295 0 my $dev_file = "$dir/dev";
296 0 my $prefix_file = "$dir/prefix";
297 0 my ( $ip, $dev, $prefix );
298 0 ▶ if ( -f $ip_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $ip_file) 0 0 0
299 0 $ip = File::Blarf::slurp( $ip_file, { Chomp => 1, } );
300 }
301 0 ▶ if ( -f $dev_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $dev_file) 0 0 0
302 0 $dev = File::Blarf::slurp( $dev_file, { Chomp => 1, } );
303 }
304 0 ▶ if ( -f $prefix_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $prefix_file) 0 0 0
305 0 $prefix = File::Blarf::slurp( $prefix_file, { Chomp => 1, } );
306 }
307 0 ▶ if ( $ip && $dev && $prefix ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ip and $dev and $prefix) 0 0 0
Condition0%0/6
$ip and $dev and $prefix
!ll&&!rl&&r
000
$ip and $dev
!ll&&!rl&&r
000
MC/DC0%0/3
$ip and $dev and $prefix
$ip $dev $prefix
Truth table0%0/4
A and B and C
A= $ipB= $devC= $prefix
ABCresult
0XX0
10X0
1100
1111
308 0 my $key = $self->_get_ip_hash_key( $ip, $prefix, $dev );
309 0 $vserver_ref->{$name}{'ips'}{$key}{'ip'} = $ip;
310 0 $vserver_ref->{$name}{'ips'}{$key}{'prefix'} = $prefix;
311 0 $vserver_ref->{$name}{'ips'}{$key}{'dev'} = $dev;
312 } ## end if ( $ip && $dev && $prefix)
313 } ## end while ( my $dir_entry = readdir...)
314 0 closedir($DH);
315 } ## end if ( opendir( my $DH, ...))
316 } ## end if ( -d $if_dir )
317 } ## end foreach my $name ( keys %{$vserver_ref...})
318  
319 0 return 1;
320 } ## end sub vms
321  
322 0 ▶sub _get_ip_hash_key {
Subroutine _get_ip_hash_key: not called CC=4 SCAR=30.0
323 0 my $self = shift;
324 0 ▶ my $ip = shift // '';
Condition0%0/2
shift() // ""
l!l
00
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
325 0 ▶ my $prefix = shift // '';
Condition0%0/2
shift() // ""
l!l
00
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
326 0 ▶ my $dev = shift // '';
Condition0%0/2
shift() // ""
l!l
00
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
327  
328 0 return $ip . '/' . $prefix . 'dev' . $dev;
329 } ## end sub _get_ip_hash_key
330  
331 0 ▶sub is_running {
Subroutine is_running: not called CC=2 SCAR=17.9
Pod documented
332 0 my $self = shift;
333 0 my $vsname = shift;
334  
335 # remove domain part
336 0 $vsname =~ s/\.[a-z0-9]$//i;
337  
338 0 my $vs_ref = {};
339  
340 0 $self->vms($vs_ref);
341  
342 0 ▶ if ( $vs_ref->{$vsname} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vs_ref->{$vsname}) { } 0 0 0
343 0 return 1;
344 }
345 else {
346 0 return;
347 }
348 } ## end sub is_running
349  
350 0 ▶sub start {
Subroutine start: not called CC=3 SCAR=24.8
Pod documented
351 0 my $self = shift;
352 0 my $vsname = shift;
353 0 ▶ my $opts = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
354  
355 0 my $cmd = "/usr/sbin/vserver $vsname start >/dev/null 2>&1";
356 0 $self->sys()->run_cmd( $cmd, $opts );
357  
358 0 ▶ if ( !$self->is_running($vsname) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_running($vsname)) 0 0 0
359 0 sleep(120);
360 }
361  
362 0 return $self->is_running($vsname);
363 } ## end sub start
364  
365 0 ▶sub stop {
Subroutine stop: not called CC=5 SCAR=34.0
Pod documented
366 0 my $self = shift;
367 0 my $vsname = shift;
368 0 ▶ my $opts = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
369  
370 0 my $cmd = "/usr/sbin/vserver $vsname stop >/dev/null 2>&1";
371  
372 0 my $max_tries = 10;
373  
374 0 foreach my $try ( 1 .. $max_tries ) {
375 0 $self->sys()->run_cmd( $cmd, $opts );
376 0 ▶ last if ( !$self->is_running($vsname) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_running($vsname) 0 0 0
377 0 sleep 30;
378 }
379  
380 # vserver $vsname stop
381 0 ▶ if ( $self->is_running($vsname) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_running($vsname)) { } 0 0 0
382 0 my $msg = "Could not stop Vserver! Aborting.";
383 0 return;
384 }
385 else {
386 0 return 1;
387 }
388 } ## end sub stop
389  
390 2 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
391 2 __PACKAGE__->meta->make_immutable;
392  
393 2 1;
394  
395 __END__
↑ Summary Virt/Plugin/Libvirt.pm »