lib/NBU/Pool.pm

filter: Statementstmt 29.8% 26 / 87 Branchbran 0.0% 0 / 40 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 42.8% 6 / 14 Podpod 0.0% 0 / 8 totaltotal 21.4% 32 / 149 CC 21 SCAR 41.6
CC
21
Cov
20%
populate
156.0
scratch
42.0
new
6.0
CRAP 64.2
« lib/NBU/Schedule.pm ↑ Summary lib/NBU/Class.pm »
1 #
2 # Copyright (c) 2002 Paul Winkeler. All Rights Reserved.
3 # This program is free software; you may redistribute it and/or modify it under
4 # the same terms as Perl itself.
5 #
6 package NBU::Pool;
7  
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶ use AutoLoader qw(AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 $VERSION = do { my @r=(q$Revision: 1.8 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r };
16 1 @ISA = qw();
17 1 @EXPORT = qw();
18 1 @EXPORT_OK = qw();
19 1 %EXPORT_TAGS = qw();
20 }
21  
22 1 my $wet;
23 my %poolIDs;
24 1 my %poolNames;
25  
26 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
27 0 my $proto = shift;
28 0 my $Pool = {
29 };
30  
31 0 bless $Pool, $proto;
32  
33 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
34 0 my $id = $Pool->{ID} = shift;
35 0 my $name = $Pool->{NAME} = shift;
36  
37 0 $poolIDs{$id} = $Pool;
38 0 $poolNames{$name} = $Pool;
39 }
40 0 return $Pool;
41 }
42  
43 0 ▶sub populate {
Subroutine populate: not called CC=12 SCAR=50.5
Pod undocumented
44 0 my $proto = shift;
45  
46 0 ▶ return $wet if (defined($wet));
Branch: 1 branch
BranchTrueFalseTotal
if defined $wet 0 0 0
47  
48 0 my @masters = NBU->masters; my $master = $masters[0];
49  
50 0 ▶ die "Could not open pool pipe\n" unless my $pipe = NBU->cmd("vmpool -h ".$master->name." -listall |");
Branch: 1 branch
BranchTrueFalseTotal
unless my $pipe = "NBU"->cmd('vmpool -h ' . $master->name . ' -listall |') 0 0 0
51 0 $wet = 0;
52 0 my $number;
53 0 my ($name, $host, $user, $group, $description);
54 0 ▶ while (<$pipe>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $pipe)) 0 0 0
55 0 chop; s/[\s]*$//;
56 0 ▶ if (/^=================/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^=================/) 0 0 0
57 0 ▶ if ($number) {
Branch: 1 branch
BranchTrueFalseTotal
if ($number) 0 0 0
58 0 $proto->new($number, $name);
59 }
60 0 $number = undef;
61 }
62 0 ▶ $number = $1 if (/^pool number:[\s]+([\d]+)/);
Branch: 1 branch
BranchTrueFalseTotal
if /^pool number:[\s]+([\d]+)/ 0 0 0
63 0 ▶ $name = $1 if (/^pool name:[\s]+([\S]+)/);
Branch: 1 branch
BranchTrueFalseTotal
if /^pool name:[\s]+([\S]+)/ 0 0 0
64 0 ▶ $host = $1 if (/^pool host:[\s]+([\S]+)/);
Branch: 1 branch
BranchTrueFalseTotal
if /^pool host:[\s]+([\S]+)/ 0 0 0
65 0 ▶ $user = $1 if (/^pool user:[\s]+([\S]+)/);
Branch: 1 branch
BranchTrueFalseTotal
if /^pool user:[\s]+([\S]+)/ 0 0 0
66 0 ▶ $group = $1 if (/^pool group:[\s]+([\S]+)/);
Branch: 1 branch
BranchTrueFalseTotal
if /^pool group:[\s]+([\S]+)/ 0 0 0
67 0 ▶ $description = $1 if (/^pool description:[\s]+([\S].*)/);
Branch: 1 branch
BranchTrueFalseTotal
if /^pool description:[\s]+([\S].*)/ 0 0 0
68  
69 0 $wet += 1;
70 }
71 0 close($pipe);
72 0 return $wet;
73 }
74  
75 0 ▶sub byName {
Subroutine byName: not called CC=2 SCAR=17.9
Pod undocumented
76 0 my $proto = shift;
77 0 my $name = shift;
78  
79 0 ▶ $proto->populate if (!$wet);
Branch: 1 branch
BranchTrueFalseTotal
unless $wet 0 0 0
80 0 return $poolNames{$name};
81 }
82  
83 0 ▶sub byID {
Subroutine byID: not called CC=2 SCAR=17.9
Pod undocumented
84 0 my $proto = shift;
85 0 my $id = shift;
86  
87 0 ▶ $proto->populate if (!$wet);
Branch: 1 branch
BranchTrueFalseTotal
unless $wet 0 0 0
88 0 return $poolIDs{$id};
89 }
90  
91 0 ▶sub name {
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
92 0 my $self = shift;
93  
94 0 return $self->{NAME};
95 }
96  
97 0 ▶sub id {
Subroutine id: not called CC=1 SCAR=6.9
Pod undocumented
98 0 my $self = shift;
99  
100 0 return $self->{ID};
101 }
102  
103 0 ▶sub list {
Subroutine list: not called CC=2 SCAR=17.9
Pod undocumented
104 0 my $proto = shift;
105  
106 0 ▶ $proto->populate if (!$wet);
Branch: 1 branch
BranchTrueFalseTotal
unless $wet 0 0 0
107 0 return (values %poolIDs);
108 }
109  
110 1 my %post;
111 0 ▶sub scratch {
Subroutine scratch: not called CC=6 SCAR=37.4
Pod undocumented
112 0 my $proto = shift;
113  
114 0 my @masters = NBU->masters; my $master = $masters[0];
115 0 ▶ if (!exists($post{$master->name})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $post{$master->name}) 0 0 0
116 0 ▶ die "Could not open pool pipe\n" unless my $pipe = NBU->cmd("vmpool -h ".$master->name." -listscratch |");
Branch: 1 branch
BranchTrueFalseTotal
unless my $pipe = "NBU"->cmd('vmpool -h ' . $master->name . ' -listscratch |') 0 0 0
117 0 <$pipe>;
118 0 ▶ while (<$pipe>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $pipe)) 0 0 0
119 0 chop;
120 0 ▶ next if (/^=================/);
Branch: 1 branch
BranchTrueFalseTotal
if /^=================/ 0 0 0
121 0 $post{$master->name} = $_;
122 }
123 }
124 0 ▶ if (defined(my $name = $post{$master->name})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $name = $post{$master->name})) 0 0 0
125 0 return $proto->byName($name);
126 }
127 0 return undef;
128 }
129  
130 1 1;
131  
132 __END__
« lib/NBU/Schedule.pm ↑ Summary lib/NBU/Class.pm »