line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
9
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
33
|
|
|
1
|
|
|
|
|
92
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
BEGIN { |
12
|
1
|
|
|
1
|
|
5
|
use Exporter (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
13
|
1
|
|
|
1
|
|
6
|
use AutoLoader qw(AUTOLOAD); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
14
|
1
|
|
|
1
|
|
38
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $AUTOLOAD); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
151
|
|
15
|
1
|
|
|
1
|
|
2
|
$VERSION = do { my @r=(q$Revision: 1.8 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r }; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
8
|
|
16
|
1
|
|
|
|
|
12
|
@ISA = qw(); |
17
|
1
|
|
|
|
|
3
|
@EXPORT = qw(); |
18
|
1
|
|
|
|
|
2
|
@EXPORT_OK = qw(); |
19
|
1
|
|
|
|
|
906
|
%EXPORT_TAGS = qw(); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $wet; |
23
|
|
|
|
|
|
|
my %poolIDs; |
24
|
|
|
|
|
|
|
my %poolNames; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new { |
27
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
28
|
0
|
|
|
|
|
|
my $Pool = { |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
bless $Pool, $proto; |
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
if (@_) { |
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
|
|
|
|
|
|
|
sub populate { |
44
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
return $wet if (defined($wet)); |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my @masters = NBU->masters; my $master = $masters[0]; |
|
0
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
die "Could not open pool pipe\n" unless my $pipe = NBU->cmd("vmpool -h ".$master->name." -listall |"); |
51
|
0
|
|
|
|
|
|
$wet = 0; |
52
|
0
|
|
|
|
|
|
my $number; |
53
|
0
|
|
|
|
|
|
my ($name, $host, $user, $group, $description); |
54
|
0
|
|
|
|
|
|
while (<$pipe>) { |
55
|
0
|
|
|
|
|
|
chop; s/[\s]*$//; |
|
0
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if (/^=================/) { |
57
|
0
|
0
|
|
|
|
|
if ($number) { |
58
|
0
|
|
|
|
|
|
$proto->new($number, $name); |
59
|
|
|
|
|
|
|
} |
60
|
0
|
|
|
|
|
|
$number = undef; |
61
|
|
|
|
|
|
|
} |
62
|
0
|
0
|
|
|
|
|
$number = $1 if (/^pool number:[\s]+([\d]+)/); |
63
|
0
|
0
|
|
|
|
|
$name = $1 if (/^pool name:[\s]+([\S]+)/); |
64
|
0
|
0
|
|
|
|
|
$host = $1 if (/^pool host:[\s]+([\S]+)/); |
65
|
0
|
0
|
|
|
|
|
$user = $1 if (/^pool user:[\s]+([\S]+)/); |
66
|
0
|
0
|
|
|
|
|
$group = $1 if (/^pool group:[\s]+([\S]+)/); |
67
|
0
|
0
|
|
|
|
|
$description = $1 if (/^pool description:[\s]+([\S].*)/); |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$wet += 1; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
|
close($pipe); |
72
|
0
|
|
|
|
|
|
return $wet; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub byName { |
76
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
77
|
0
|
|
|
|
|
|
my $name = shift; |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
$proto->populate if (!$wet); |
80
|
0
|
|
|
|
|
|
return $poolNames{$name}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub byID { |
84
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
85
|
0
|
|
|
|
|
|
my $id = shift; |
86
|
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
|
$proto->populate if (!$wet); |
88
|
0
|
|
|
|
|
|
return $poolIDs{$id}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub name { |
92
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
return $self->{NAME}; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub id { |
98
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
return $self->{ID}; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub list { |
104
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
105
|
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
|
$proto->populate if (!$wet); |
107
|
0
|
|
|
|
|
|
return (values %poolIDs); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my %post; |
111
|
|
|
|
|
|
|
sub scratch { |
112
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
my @masters = NBU->masters; my $master = $masters[0]; |
|
0
|
|
|
|
|
|
|
115
|
0
|
0
|
|
|
|
|
if (!exists($post{$master->name})) { |
116
|
0
|
0
|
|
|
|
|
die "Could not open pool pipe\n" unless my $pipe = NBU->cmd("vmpool -h ".$master->name." -listscratch |"); |
117
|
0
|
|
|
|
|
|
<$pipe>; |
118
|
0
|
|
|
|
|
|
while (<$pipe>) { |
119
|
0
|
|
|
|
|
|
chop; |
120
|
0
|
0
|
|
|
|
|
next if (/^=================/); |
121
|
0
|
|
|
|
|
|
$post{$master->name} = $_; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
0
|
0
|
|
|
|
|
if (defined(my $name = $post{$master->name})) { |
125
|
0
|
|
|
|
|
|
return $proto->byName($name); |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
|
return undef; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |