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
|
25
|
|
|
25
|
|
38997
|
use Moose; |
|
25
|
|
|
|
|
7320300
|
|
|
25
|
|
|
|
|
200
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
with 'Net::ISC::DHCPd::Config::Root'; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# need to put this somewhere everyone has access to it and we don't need to |
113
|
|
|
|
|
|
|
# "use N:I:D:Config;" |
114
|
|
|
|
|
|
|
sub children { |
115
|
209
|
|
|
209
|
1
|
1779
|
return qw/ |
116
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Host |
117
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Class |
118
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Conditional |
119
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::SubClass |
120
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Subnet |
121
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Subnet6 |
122
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Include |
123
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::SharedNetwork |
124
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Function |
125
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::OptionSpace |
126
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::OptionCode |
127
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Option |
128
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Key |
129
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Group |
130
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Zone |
131
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::FailoverPeer |
132
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Authoritative |
133
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::Block |
134
|
|
|
|
|
|
|
Net::ISC::DHCPd::Config::KeyValue/; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
__PACKAGE__->create_children(__PACKAGE__->children()); |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
0
|
|
|
sub _build_root { $_[0] } |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 regex |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/regex>. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
0
|
1
|
|
sub regex { qr{\x00} } # should not be used |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
__PACKAGE__->meta->add_method(filehandle => sub { |
150
|
0
|
|
|
0
|
|
|
Carp::cluck('->filehandle is replaced with private attribute _filehandle'); |
151
|
0
|
|
|
|
|
|
shift->_filehandle; |
152
|
|
|
|
|
|
|
}); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 file |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Root/file>. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 parent |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/parent>. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 root |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/root>. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 parent |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This attribute is different from L<Net::ISC::DHCPd::Config::Role/parent>: |
171
|
|
|
|
|
|
|
It holds an undefined value, which is used to indicate that this object |
172
|
|
|
|
|
|
|
is the top node in the tree. See L<Net::ISC::DHCPd::Config::Include> |
173
|
|
|
|
|
|
|
if you want a different behavior. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
has parent => ( |
178
|
|
|
|
|
|
|
is => 'ro', |
179
|
|
|
|
|
|
|
isa => 'Undef', |
180
|
|
|
|
|
|
|
default => sub { undef }, |
181
|
|
|
|
|
|
|
); |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head2 children |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children>. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 hosts |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
List of parsed L<Net::ISC::DHCPd::Config::Host> objects. |
190
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children> for details on how to |
191
|
|
|
|
|
|
|
add, update or remove these objects. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head2 subnets |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
List of parsed L<Net::ISC::DHCPd::Config::Subnet> objects. |
196
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children> for details on how to |
197
|
|
|
|
|
|
|
add, update or remove these objects. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head2 sharednetworks |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
List of parsed L<Net::ISC::DHCPd::Config::SharedNetwork> objects. |
202
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children> for details on how to |
203
|
|
|
|
|
|
|
add, update or remove these objects. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head2 functions |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
List of parsed L<Net::ISC::DHCPd::Config::Function> objects. |
208
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children> for details on how to |
209
|
|
|
|
|
|
|
add, update or remove these objects. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head2 optionspaces |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
List of parsed L<Net::ISC::DHCPd::Config::OptionSpace> objects. |
214
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children> for details on how to |
215
|
|
|
|
|
|
|
add, update or remove these objects. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head2 options |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
List of parsed L<Net::ISC::DHCPd::Config::Option> objects. |
220
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children> for details on how to |
221
|
|
|
|
|
|
|
add, update or remove these objects. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head2 includes |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
List of parsed L<Net::ISC::DHCPd::Config::Include> objects. |
226
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children> for details on how to |
227
|
|
|
|
|
|
|
add, update or remove these objects. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head2 classes |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
List of parsed L<Net::ISC::DHCPd::Config::Class> objects. |
232
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children> for details on how to |
233
|
|
|
|
|
|
|
add, update or remove these objects. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head2 subclasses |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
List of parsed L<Net::ISC::DHCPd::Config::SubClass> objects. |
238
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children> for details on how to |
239
|
|
|
|
|
|
|
add, update or remove these objects. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head2 keyvalues |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
List of parsed L<Net::ISC::DHCPd::Config::KeyValue> objects. |
244
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/children> for details on how to |
245
|
|
|
|
|
|
|
add, update or remove these objects. |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=head1 METHODS |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=head2 parse |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Role/parse>. |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=head2 generate |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd::Config::Root/generate>. |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=head1 AUTHOR |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
See L<Net::ISC::DHCPd>. |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=cut |
264
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
265
|
|
|
|
|
|
|
1; |