line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::ISC::DHCPd::Config; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config - Parse and create ISC DHCPd config |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Net::ISC::DHCPd::Config; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $config = Net::ISC::DHCPd::Config->new( |
12
|
|
|
|
|
|
|
file => '/etc/dhcpd3/dhcpd.conf', |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# parse the config |
16
|
|
|
|
|
|
|
$config->parse; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# parsing includes are lazy |
19
|
|
|
|
|
|
|
for my $include ($config->includes) { |
20
|
|
|
|
|
|
|
$include->parse; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
print $config->includes->[0]->hosts->[0]->dump; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$config->add_host({ |
26
|
|
|
|
|
|
|
name => 'foo', |
27
|
|
|
|
|
|
|
filenames => [{ file => 'pxelinux.0' }], |
28
|
|
|
|
|
|
|
}); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
if($config->find_hosts({ name => 'foo' })) { |
31
|
|
|
|
|
|
|
say "Found host by name='foo'"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
if($config->remove_includes({ file => 'some/file' })) { |
34
|
|
|
|
|
|
|
say "Removed included file by file='some/file'"; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
print $config->generate; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 DESCRIPTION |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
An object constructed from this class represents the config for a |
42
|
|
|
|
|
|
|
given dhcpd server. The L<config file|/file> passed on to the construted |
43
|
|
|
|
|
|
|
can either be read or written to. As shown in the L</SYNOPSIS>, the |
44
|
|
|
|
|
|
|
object has the method C<parse>, which will read the config (line by line) |
45
|
|
|
|
|
|
|
and create the appropriate objects representing each part of the config. |
46
|
|
|
|
|
|
|
The result is an object L<graph|http://en.wikipedia.org/wiki/Graph_theory> |
47
|
|
|
|
|
|
|
where the objects has pointer back to the L</parent> and any number of |
48
|
|
|
|
|
|
|
children of different types. (Ex: L</hosts>, L</subnets>, ...) |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
It is also possible to start from scratch with an empty object, and |
51
|
|
|
|
|
|
|
use any of the C<add_foo> methods to create the object graph. After |
52
|
|
|
|
|
|
|
creating/modifying the graph, the actual config text can be retrieved |
53
|
|
|
|
|
|
|
using L</generate>. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
This class does the role L<Net::ISC::DHCPd::Config::Root>. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 POSSIBLE CONFIG GRAPH |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Config |
60
|
|
|
|
|
|
|
|- Config::Authoritative |
61
|
|
|
|
|
|
|
|- Config::Class |
62
|
|
|
|
|
|
|
|- Config::SubClass |
63
|
|
|
|
|
|
|
|- Config::Include |
64
|
|
|
|
|
|
|
|- Config::Conditional |
65
|
|
|
|
|
|
|
|- Config::FailoverPeer |
66
|
|
|
|
|
|
|
|- Config::Subnet |
67
|
|
|
|
|
|
|
| |- Config::Option |
68
|
|
|
|
|
|
|
| |- Config::Declaration |
69
|
|
|
|
|
|
|
| |- Config::Range |
70
|
|
|
|
|
|
|
| |- Config::Host |
71
|
|
|
|
|
|
|
| | |- ... |
72
|
|
|
|
|
|
|
| |- Config::Filename |
73
|
|
|
|
|
|
|
| '- Config::Pool |
74
|
|
|
|
|
|
|
| |- Option |
75
|
|
|
|
|
|
|
| |- Range |
76
|
|
|
|
|
|
|
| '- KeyValue |
77
|
|
|
|
|
|
|
| |
78
|
|
|
|
|
|
|
|- Config::SharedNetwork |
79
|
|
|
|
|
|
|
| |- Config::Subnet |
80
|
|
|
|
|
|
|
| | |- ... |
81
|
|
|
|
|
|
|
| |- Config::Declaration |
82
|
|
|
|
|
|
|
| '- Config::KeyValue |
83
|
|
|
|
|
|
|
| |
84
|
|
|
|
|
|
|
|- Config::Group |
85
|
|
|
|
|
|
|
| |- Config::Host |
86
|
|
|
|
|
|
|
| | |- ... |
87
|
|
|
|
|
|
|
| |- Config::Option |
88
|
|
|
|
|
|
|
| |- Config::Declaration |
89
|
|
|
|
|
|
|
| '- Config::KeyValue |
90
|
|
|
|
|
|
|
| |
91
|
|
|
|
|
|
|
|- Config::Host |
92
|
|
|
|
|
|
|
| |- Config::Option |
93
|
|
|
|
|
|
|
| |- Config::Filename |
94
|
|
|
|
|
|
|
| |- Config::Declaration |
95
|
|
|
|
|
|
|
| '- Config::KeyValue |
96
|
|
|
|
|
|
|
| |
97
|
|
|
|
|
|
|
|- Config::OptionSpace |
98
|
|
|
|
|
|
|
|- Config::OptionCode |
99
|
|
|
|
|
|
|
| |
100
|
|
|
|
|
|
|
|- Config::Option |
101
|
|
|
|
|
|
|
|- Config::Declaration * |
102
|
|
|
|
|
|
|
|- Config::Function |
103
|
|
|
|
|
|
|
|- Config::KeyValue |
104
|
|
|
|
|
|
|
'- Config::Single * |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
24
|
|
|
24
|
|
94998
|
use Moose; |
|
24
|
|
|
|
|
10441411
|
|
|
24
|
|
|
|
|
222
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
with 'Net::ISC::DHCPd::Config::Root'; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub children { |
113
|
152
|
|
|
152
|
1
|
1235
|
return qw/ |
114
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Host |
115
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Class |
116
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Conditional |
117
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::SubClass |
118
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Subnet |
119
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Subnet6 |
120
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Include |
121
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::SharedNetwork |
122
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Function |
123
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::OptionSpace |
124
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::OptionCode |
125
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Option |
126
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Key |
127
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Group |
128
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Zone |
129
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::FailoverPeer |
130
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Authoritative |
131
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Block |
132
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::KeyValue/; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
__PACKAGE__->create_children(__PACKAGE__->children()); |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
0
|
|
|
sub _build_root { $_[0] } |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 regex |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/regex>. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
0
|
1
|
|
sub regex { qr{\x00} } # should not be used |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
__PACKAGE__->meta->add_method(filehandle => sub { |
148
|
0
|
|
|
0
|
|
|
Carp::cluck('->filehandle is replaced with private attribute _filehandle'); |
149
|
0
|
|
|
|
|
|
shift->_filehandle; |
150
|
|
|
|
|
|
|
}); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 file |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Root/file>. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 parent |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/parent>. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 root |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/root>. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 parent |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This attribute is different from L<Net::ISC::DHCPd::Config::Role/parent>: |
169
|
|
|
|
|
|
|
It holds an undefined value, which is used to indicate that this object |
170
|
|
|
|
|
|
|
is the top node in the tree. See L<Net::ISC::DHCPd::Config::Include> |
171
|
|
|
|
|
|
|
if you want a different behavior. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
has parent => ( |
176
|
|
|
|
|
|
|
is => 'ro', |
177
|
|
|
|
|
|
|
isa => 'Undef', |
178
|
|
|
|
|
|
|
default => sub { undef }, |
179
|
|
|
|
|
|
|
); |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 children |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children>. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 hosts |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
List of parsed L<Net::ISC::DHCPd::Config::Host> objects. |
188
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children> for details on how to |
189
|
|
|
|
|
|
|
add, update or remove these objects. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head2 subnets |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
List of parsed L<Net::ISC::DHCPd::Config::Subnet> objects. |
194
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children> for details on how to |
195
|
|
|
|
|
|
|
add, update or remove these objects. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head2 sharednetworks |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
List of parsed L<Net::ISC::DHCPd::Config::SharedNetwork> objects. |
200
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children> for details on how to |
201
|
|
|
|
|
|
|
add, update or remove these objects. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head2 functions |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
List of parsed L<Net::ISC::DHCPd::Config::Function> objects. |
206
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children> for details on how to |
207
|
|
|
|
|
|
|
add, update or remove these objects. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head2 optionspaces |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
List of parsed L<Net::ISC::DHCPd::Config::OptionSpace> objects. |
212
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children> for details on how to |
213
|
|
|
|
|
|
|
add, update or remove these objects. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head2 options |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
List of parsed L<Net::ISC::DHCPd::Config::Option> objects. |
218
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children> for details on how to |
219
|
|
|
|
|
|
|
add, update or remove these objects. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head2 includes |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
List of parsed L<Net::ISC::DHCPd::Config::Include> objects. |
224
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children> for details on how to |
225
|
|
|
|
|
|
|
add, update or remove these objects. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head2 classes |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
List of parsed L<Net::ISC::DHCPd::Config::Class> objects. |
230
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children> for details on how to |
231
|
|
|
|
|
|
|
add, update or remove these objects. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head2 subclasses |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
List of parsed L<Net::ISC::DHCPd::Config::SubClass> objects. |
236
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children> for details on how to |
237
|
|
|
|
|
|
|
add, update or remove these objects. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head2 keyvalues |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
List of parsed L<Net::ISC::DHCPd::Config::KeyValue> objects. |
242
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children> for details on how to |
243
|
|
|
|
|
|
|
add, update or remove these objects. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 METHODS |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=head2 parse |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/parse>. |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=head2 generate |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Root/generate>. |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head1 AUTHOR |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd>. |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=cut |
262
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
263
|
|
|
|
|
|
|
1; |