line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Conan::Configure::Xen; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
561
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1052
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub new { |
7
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
8
|
|
|
|
|
|
|
|
9
|
0
|
|
|
|
|
|
my $args = { |
10
|
|
|
|
|
|
|
basedir => '/xen/prod/etc/', |
11
|
|
|
|
|
|
|
@_, |
12
|
|
|
|
|
|
|
}; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# By default the IP isn't outputted, but rather |
15
|
|
|
|
|
|
|
# generated in the 'extra' field |
16
|
0
|
0
|
|
|
|
|
unless( $args->{generators}->{ip} ){ |
17
|
|
|
|
|
|
|
$args->{generators}->{ip} = sub { |
18
|
0
|
|
|
0
|
|
|
my $self = shift; |
19
|
0
|
|
|
|
|
|
return sprintf "#ip = '%s'\n", $self->{settings}->{ip}; |
20
|
0
|
|
|
|
|
|
}; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
0
|
0
|
|
|
|
|
unless( $args->{generators}->{netmask} ){ |
24
|
|
|
|
|
|
|
$args->{generators}->{netmask} = sub { |
25
|
0
|
|
|
0
|
|
|
my $self = shift; |
26
|
0
|
|
|
|
|
|
return sprintf "#netmask = '%s'\n", $self->{settings}->{netmask}; |
27
|
0
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
unless( $args->{generators}->{gateway} ){ |
31
|
|
|
|
|
|
|
$args->{generators}->{gateway} = sub { |
32
|
0
|
|
|
0
|
|
|
my $self = shift; |
33
|
0
|
|
|
|
|
|
return sprintf "#gateway = '%s'\n", $self->{settings}->{gateway}; |
34
|
0
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
unless( $args->{generators}->{extra} ){ |
38
|
|
|
|
|
|
|
$args->{generators}->{extra} = sub { |
39
|
0
|
|
|
0
|
|
|
my $self = shift; |
40
|
0
|
|
0
|
|
|
|
return sprintf "extra = ' ip=%s::%s:%s::eth0:off NFS=%s= %s %s ro clocksource=jiffies'\n", |
41
|
|
|
|
|
|
|
$self->{settings}->{ip}, |
42
|
|
|
|
|
|
|
$self->{settings}->{gateway}, |
43
|
|
|
|
|
|
|
$self->{settings}->{netmask}, |
44
|
|
|
|
|
|
|
$self->{settings}->{nfsroot}, |
45
|
|
|
|
|
|
|
$self->{settings}->{postboot}, |
46
|
|
|
|
|
|
|
$self->{settings}->{name} || $self->{name}; |
47
|
0
|
|
|
|
|
|
}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
bless $args => $class; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub generate { |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
56
|
0
|
|
|
|
|
|
my $output = sprintf "# This was generated on %s by %s\n", scalar localtime( time() ), 'Conan::Configure::Xen'; |
57
|
0
|
|
|
|
|
|
$output .= "# Please do not manually edit\n"; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
for my $key (qw/ |
60
|
|
|
|
|
|
|
name |
61
|
|
|
|
|
|
|
kernel |
62
|
|
|
|
|
|
|
memory |
63
|
|
|
|
|
|
|
vcpus |
64
|
|
|
|
|
|
|
vif |
65
|
|
|
|
|
|
|
ip |
66
|
|
|
|
|
|
|
netmask |
67
|
|
|
|
|
|
|
gateway |
68
|
|
|
|
|
|
|
on_poweroff |
69
|
|
|
|
|
|
|
on_reboot |
70
|
|
|
|
|
|
|
on_crash |
71
|
|
|
|
|
|
|
extra/){ |
72
|
0
|
0
|
|
|
|
|
if( exists $self->{generators}->{$key} ){ |
|
|
0
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my $sub = $self->{generators}->{$key}; |
74
|
0
|
|
|
|
|
|
$output .= $sub->($self); |
75
|
|
|
|
|
|
|
} elsif( defined $self->{settings}->{$key} ){ |
76
|
0
|
0
|
|
|
|
|
if( $key eq 'vif' ){ |
77
|
|
|
|
|
|
|
# This is the weird one |
78
|
0
|
|
|
|
|
|
$output .= $key . " = [ " . "'$self->{settings}->{$key}'" . " ]\n"; |
79
|
|
|
|
|
|
|
} else { |
80
|
0
|
|
|
|
|
|
$output .= $key . " = " . "'$self->{settings}->{$key}'" . "\n"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return $output; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub parse { |
90
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my %hostsettings; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my @files = glob "$self->{basedir}/*.cfg.tmpl $self->{basedir}/*.cfg"; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
s/\/{2,}/\//g for @files; |
97
|
|
|
|
|
|
|
|
98
|
0
|
0
|
|
|
|
|
croak "Name not defined" unless defined $self->{name}; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Get the hostconfig files |
101
|
0
|
|
|
|
|
|
my @hostconfig = grep { /$self->{name}/ } @files; |
|
0
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my $basename = $self->{name}; |
104
|
0
|
|
|
|
|
|
$basename =~ s/\d+//g; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
my @baseconfig = grep { /$basename\.cfg/ } @files; |
|
0
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
for( @baseconfig ){ |
109
|
0
|
|
|
|
|
|
my %hash2 = $self->parse_template( $_ ); |
110
|
0
|
|
|
|
|
|
@hostsettings{keys %hash2} = values %hash2; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
for( @hostconfig ){ |
114
|
0
|
|
|
|
|
|
my %hash2 = $self->parse_template( $_ ); |
115
|
0
|
|
|
|
|
|
@hostsettings{keys %hash2} = values %hash2; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
$self->{settings} = \%hostsettings; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# post parse stuff |
121
|
0
|
0
|
|
|
|
|
if( $self->{settings}->{NFS} ){ |
122
|
0
|
0
|
|
|
|
|
if( $self->{settings}->{version} ){ |
123
|
0
|
|
|
|
|
|
$self->{settings}->{NFS} .= "/" . $self->{settings}->{version}; |
124
|
|
|
|
|
|
|
# Strip duplicate / |
125
|
0
|
|
|
|
|
|
$self->{settings}->{NFS} =~ s,/+,/,g; |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
|
$self->{settings}->{nfsroot} = $self->{settings}->{NFS}; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
return $self->{settings}; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub host_template { |
134
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
my $filename = shift; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub parse_template { |
140
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
my $filename = shift; |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
my %settings; |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
open my $fd, "<$filename"; |
147
|
|
|
|
|
|
|
|
148
|
0
|
0
|
|
|
|
|
if( $fd ){ |
149
|
0
|
|
|
|
|
|
my @lines = <$fd>; |
150
|
0
|
|
|
|
|
|
chomp for @lines; |
151
|
0
|
|
|
|
|
|
s/#.*//g for @lines; |
152
|
|
|
|
|
|
|
|
153
|
0
|
0
|
|
|
|
|
%settings = map { ($1,$2) if /(\S+)\s*=\s*(?:\[\s*)?'(.*?)'/ } grep( ! /^\s*$/, @lines ); |
|
0
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
close $fd; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
return %settings; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
1; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
__END__ |