Netsync/Network.pm

filter: Statementstmt 17.2% 31 / 180 Branchbran 0.0% 0 / 98 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 40.0% 8 / 20 Podpod 100% 12 / 12 totaltotal 15.1% 51 / 337 CC 72 SCAR 45.0
CC
72
Cov
10%
node_dump
272.0
device_dump
110.0
interface_dump
90.0
CRAP 89.8
« Netsync/Configurator.pm ↑ Summary Netsync/Scribe.pm »
1 package App::Netsync::Network; #XXX This package should be object-oriented.
2  
3 =head1 NAME
4  
5 App::Netsync::Network - methods for manipulating network structures
6  
7 =head1 DESCRIPTION
8  
9 This module is responsible for for manipulating an internal view of a network.
10  
11 =head1 SYNOPSIS
12  
13 use App::Netsync 'devices_interfaces';
14 use App::Netsync::Network;
15 use feature 'say';
16  
17 my %node;
18 $node{'ip'} = '10.0.0.1';
19 $node{'hostname'} = 'host1';
20 $node{'session'} = App::Netsync::SNMP::Session $node{'ip'};
21 $node{'info'} = App::Netsync::SNMP::Info $session;
22  
23 my $serial2if2ifName = device_interfaces ($node{'info'}->vendor,$node{'session'});
24  
25 node_initialize (\%node,$serial2if2ifName);
26 say node_string \%node;
27 node_dump \%node;
28  
29 # or
30  
31 device_initialize (\%node,$_,$serial2if2ifName->{$_}) foreach keys $serial2if2ifName;
32 foreach my $serial (keys %{$node{'devices'}}) {
33 my $device = $node{'devices'}{$serial};
34 say device_string $device;
35 device_dump $device;
36 }
37  
38 # or
39  
40 foreach my $serial (keys %serial2if2ifName) {
41 $node->{'devices'}{$serial} = \%device;
42 my $device = $node{'devices'}{$serial};
43 $device->{'node'} = $node;
44  
45 my $if2ifName = $serial2if2ifName{$serial};
46 interface_initialize ($device,$if2ifName->{$_},$_) foreach keys %$if2ifName;
47 }
48  
49 foreach my $serial (keys %{$node{'devices'}}) {
50 my $device = $node{'devices'}{$serial};
51 foreach my $ifName (keys %{$device->{'interfaces'}}) {
52 my interface = device->{'interfaces'}{$ifName};
53 say interface_string $interface;
54 interface_dump $interface;
55 }
56 }
57  
58  
59 my %nodes;
60 $nodes{'10.0.0.1'} = \%node;
61 $nodes{'10.0.0.2'}{'ip'} = '10.0.0.2';
62 $nodes{'10.0.0.3'}{'ip'} = '10.0.0.3';
63 $nodes{'10.0.0.4'}{'ip'} = '10.0.0.4';
64 $nodes{'10.0.0.5'}{'ip'} = '10.0.0.5';
65  
66 my $n = node_find (\%nodes,'10.0.0.5');
67 $n->{'ip'} == '10.0.0.5';
68  
69 $n->{'devices'}{'1A2B3C4D5E6F'}{'serial'} = '1A2B3C4D5E6F';
70  
71 my $d = device_find (\%nodes,'1A2B3C4D5E6F');
72 $d->{'serial'} == '1A2B3C4D5E6F';
73  
74 $d->{'interfaces'}{'ethernet1/1/1'}{'ifName'} = ethernet1/1/1;
75  
76 my $i = interface_find ($n->{'devices'},'ethernet1/1/1');
77 $i->{'ifName'} = 'ethernet1/1/1';
78  
79 =cut
80  
81  
82 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
83 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
85 1 ▶use feature 'say';
Subroutine BEGIN: called CC=1 SCAR=0.0
86 1 ▶use autodie; #XXX Is autodie adequate?
Subroutine BEGIN: called CC=1 SCAR=0.0
87  
88 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
89 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
90  
91 1 our ($SCRIPT,$VERSION);
92 1 our %config;
93  
94 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
95 1 ($SCRIPT) = fileparse ($0,"\.[^.]*");
96 1 ($VERSION) = version->declare('v4.0.0');
97  
98 1 require Exporter;
99 1 our @ISA = ('Exporter');
100 1 our @EXPORT = (
101 'node_initialize','device_initialize','interface_initialize',
102 'node_string' ,'device_string' ,'interface_string',
103 'node_dump' ,'device_dump' ,'interface_dump',
104 'node_find' ,'device_find' ,'interface_find',
105 );
106  
107 1 $config{'Indent'} = 4;
108 1 $config{'Quiet'} = 0;
109 1 $config{'Verbose'} = 0;
110 }
111  
112  
113 =head1 METHODS
114  
115 =head2 node_initialize
116  
117 initialize a new network node
118  
119 B<Arguments>
120  
121 I<( $node , \%serial2if2ifName )>
122  
123 =over 3
124  
125 =item node
126  
127 the node to initialize
128  
129 C<$node>
130  
131 {
132 'devices' => {
133 $serial => $device,
134 },
135 'hostname' => SCALAR,
136 'info' => SNMP::Info,
137 'ip' => SCALAR,
138 'session' => SNMP::Session,
139 }
140  
141 =item serial2if2ifName
142  
143 a mapping of interfaces to devices (see App::Netsync::device_interfaces)
144  
145 =back
146  
147 =cut
148  
149 0 ▶sub node_initialize {
Subroutine node_initialize: not called CC=4 SCAR=30.0
Pod documented
150 0 ▶ warn 'too few arguments' if @_ < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 0 0 0
151 0 ▶ warn 'too many arguments' if @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 2 0 0 0
152 0 my ($node,$serial2if2ifName) = @_;
153  
154 0 foreach my $serial (keys %$serial2if2ifName) {
155 0 device_initialize ($node,$serial,$serial2if2ifName->{$serial});
156 }
157 0 return $node;
158 }
159  
160  
161 =head2 device_initialize
162  
163 initialize a new network device
164  
165 C<$device>
166  
167 {
168 'interfaces' => {
169 $ifName => $interface,
170 },
171 'node' => $node,
172 'identified' => SCALAR,
173 'serial' => $serial,
174 }
175  
176 B<Arguments>
177  
178 I<( $node , $serial , \%if2ifName )>
179  
180 =over 3
181  
182 =item node
183  
184 the node to add a new device to
185  
186 =item serial
187  
188 the serial number (unique identifier) of the new device (see node_initialize)
189  
190 =item if2ifName
191  
192 a mapping of SNMP interface IIDs to interface names (see device_interfaces)
193  
194 =back
195  
196 =cut
197  
198 0 ▶sub device_initialize {
Subroutine device_initialize: not called CC=5 SCAR=34.0
Pod documented
199 0 ▶ warn 'too few arguments' if @_ < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 0 0 0
200 0 ▶ warn 'too many arguments' if @_ > 3;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 3 0 0 0
201 0 my ($node,$serial,$if2ifName) = @_;
202 0 ▶ $if2ifName //= {};
Condition0%0/2
$if2ifName //= {}
l!l
00
MC/DC0%0/1
$if2ifName //= {}
$if2ifName
Truth table0%0/2
A
A= $if2ifName
Aresult
11
00
203  
204 0 $serial = uc $serial;
205 0 $node->{'devices'}{$serial}{'serial'} = $serial;
206 0 my $device = $node->{'devices'}{$serial};
207 0 $device->{'node'} = $node;
208 0 foreach my $if (keys %$if2ifName) {
209 0 interface_initialize ($device,$if2ifName->{$if},$if);
210 }
211 0 $device->{'identified'} = 0;
212 0 return $device;
213 }
214  
215  
216 =head2 interface_initialize
217  
218 initialize a new network interface
219  
220 C<$interface>
221  
222 {
223 'device' => $device,
224 'ifName' => $ifName,
225 'IID' => SCALAR,
226 'info' => {
227 $field => SCALAR,
228 },
229 'identified' => SCALAR,
230 }
231  
232 B<Arguments>
233  
234 I<( $device , $ifName , $IID [, \%fields ] )>
235  
236 =over 3
237  
238 =item device
239  
240 the device to add a new interface to
241  
242 =item ifName
243  
244 the name of the new interface
245  
246 =item IID
247  
248 the IID of the new interface
249  
250 =item fields
251  
252 interface-specific key-value pairs
253  
254 =back
255  
256 =cut
257  
258 0 ▶sub interface_initialize {
Subroutine interface_initialize: not called CC=6 SCAR=37.4
Pod documented
259 0 ▶ warn 'too few arguments' if @_ < 3;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 0 0 0
260 0 ▶ warn 'too many arguments' if @_ > 4;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 4 0 0 0
261 0 my ($device,$ifName,$IID,$fields) = @_;
262 0 ▶ $fields //= {};
Condition0%0/2
$fields //= {}
l!l
00
MC/DC0%0/1
$fields //= {}
$fields
Truth table0%0/2
A
A= $fields
Aresult
11
00
263  
264 0 $device->{'interfaces'}{$ifName}{'ifName'} = $ifName;
265 0 my $interface = $device->{'interfaces'}{$ifName};
266 0 $interface->{'device'} = $device;
267 0 $interface->{'IID'} = $IID;
268 0 $interface->{'info'}{$_} = $fields->{$_} foreach keys %$fields;
269 0 ▶ $interface->{'identified'} = (scalar keys %$fields > 0) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %$fields > 0 ? : 0 0 0
270 0 return $interface;
271 }
272  
273  
274  
275  
276 ################################################################################
277  
278  
279  
280  
281 =head2 node_string
282  
283 converts $node structure(s) to strings
284  
285 B<Arguments>
286  
287 I<( @nodes )>
288  
289 =over 3
290  
291 =item nodes
292  
293 an array of nodes to stringify
294  
295 =back
296  
297 =cut
298  
299 0 ▶sub node_string {
Subroutine node_string: not called CC=6 SCAR=37.4
Pod documented
300 0 ▶ warn 'too few arguments' if @_ < 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 1 0 0 0
301 0 my (@nodes) = @_;
302  
303 0 my @node_strings;
304 0 foreach my $node (@nodes) {
305 0 my $node_string;
306 0 ▶ if (defined $node->{'ip'} and defined $node->{'hostname'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $node->{"ip"} and defined $node->{"hostname"}) 0 0 0
Condition0%0/3
defined $node->{"ip"} and defined $node->{"hostname"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $node->{"ip"} and defined $node->{"hostname"}
defined $node->{"ip"} defined $node->{"hostname"}
Truth table0%0/3
A and B
A= defined $node->{"ip"}B= defined $node->{"hostname"}
ABresult
0X0
100
111
307 0 $node_string = $node->{'ip'}.' ('.$node->{'hostname'}.')';
308 }
309 0 push (@node_strings,$node_string);
310 }
311 0 ▶ return $node_strings[0] if @nodes == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @nodes == 1 0 0 0
312 0 return @node_strings;
313 }
314  
315  
316 =head2 device_string
317  
318 converts $device structures to strings
319  
320 B<Arguments>
321  
322 I<( @devices )>
323  
324 =over 3
325  
326 =item devices
327  
328 an array of devices to stringify
329  
330 =back
331  
332 =cut
333  
334 0 ▶sub device_string {
Subroutine device_string: not called CC=6 SCAR=37.4
Pod documented
335 0 ▶ warn 'too few arguments' if @_ < 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 1 0 0 0
336 0 my (@devices) = @_;
337  
338 0 my @device_strings;
339 0 foreach my $device (@devices) {
340 0 my $device_string;
341 0 ▶ if (defined $device->{'serial'} and defined $device->{'node'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $device->{"serial"} and defined $device->{"node"}) 0 0 0
Condition0%0/3
defined $device->{"serial"} and defined $device->{"node"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $device->{"serial"} and defined $device->{"node"}
defined $device->{"serial"} defined $device->{"node"}
Truth table0%0/3
A and B
A= defined $device->{"serial"}B= defined $device->{"node"}
ABresult
0X0
100
111
342 0 $device_string = $device->{'serial'}.' at '.node_string $device->{'node'};
343 }
344 0 push (@device_strings,$device_string);
345 }
346 0 ▶ return $device_strings[0] if @devices == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @devices == 1 0 0 0
347 0 return @device_strings;
348 }
349  
350  
351 =head2 interface_string
352  
353 converts $interface structures to strings
354  
355 B<Arguments>
356  
357 I<( @interfaces )>
358  
359 =over 3
360  
361 =item interfaces
362  
363 an array of devices to stringify
364  
365 =back
366  
367 =cut
368  
369 0 ▶sub interface_string {
Subroutine interface_string: not called CC=8 SCAR=42.8
Pod documented
370 0 ▶ warn 'too few arguments' if @_ < 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 1 0 0 0
371 0 my (@interfaces) = @_;
372  
373 0 my @interface_strings;
374 0 foreach my $interface (@interfaces) {
375 0 my $interface_string;
376 0 ▶ if ($interface->{'ifName'} // $interface->{'IID'} // $interface->{'device'} // 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((($interface->{"ifName"} // $interface->{"IID"}) // $interface->{"device"}) // 0) 0 0 0
Condition0%0/8
(($interface->{"ifName"} // $interface->{"IID"}) // $interface->{"device"}) // 0
l!l
00
($interface->{"ifName"} // $interface->{"IID"}) // $interface->{"device"}
l!l&&r!l&&!r
000
$interface->{"ifName"} // $interface->{"IID"}
l!l&&r!l&&!r
000
MC/DC0%0/3
(($interface->{"ifName"} // $interface->{"IID"}) // $interface->{"device"}) // 0
$interface->{"ifName"} $interface->{"IID"} $interface->{"device"}
Truth table0%0/4
A // B // C
A= $interface->{"ifName"}B= $interface->{"IID"}C= $interface->{"device"}
ABCresult
1XX1
01X1
0011
0000
377 0 $interface_string = $interface->{'ifName'}.' ('.$interface->{'IID'}.')';
378 0 $interface_string .= ' on '.device_string $interface->{'device'};
379 }
380 0 push (@interface_strings,$interface_string);
381 }
382 0 ▶ return $interface_strings[0] if @interfaces == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @interfaces == 1 0 0 0
383 0 return @interface_strings;
384 }
385  
386  
387  
388  
389 ################################################################################
390  
391  
392  
393  
394 =head2 node_dump
395  
396 prints a node structure
397  
398 B<Arguments>
399  
400 I<( @nodes )>
401  
402 =over 3
403  
404 =item nodes
405  
406 an array of nodes to print
407  
408 =back
409  
410 =cut
411  
412 0 ▶sub node_dump {
Subroutine node_dump: not called CC=16 SCAR=56.1
Pod documented
413 0 ▶ warn 'too few arguments' if @_ < 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 1 0 0 0
414 0 my (@nodes) = @_;
415  
416 0 foreach my $node (@nodes) {
417 0 say node_string $node;
418  
419 0 my $device_count = 0;
420 0 ▶ if (defined $node->{'devices'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $node->{"devices"}) 0 0 0
421 0 $device_count = scalar keys %{$node->{'devices'}};
422  
423 0 my ($identified_device_count,$interface_count,$identified_interface_count) = (0,0,0);
424 0 foreach my $serial (keys %{$node->{'devices'}}) {
425 0 my $device = $node->{'devices'}{$serial};
426 0 ▶ ++$identified_device_count if $device->{'identified'};
Branch: 1 branch
BranchTrueFalseTotal
if $device->{"identified"} 0 0 0
427 0 ▶ next unless defined $device->{'interfaces'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $device->{"interfaces"} 0 0 0
428 0 $interface_count += scalar keys %{$device->{'interfaces'}};
429 0 foreach my $ifName (keys %{$device->{'interfaces'}}) {
430 0 my $interface = $device->{'interfaces'}{$ifName};
431 0 ▶ ++$identified_interface_count if $interface->{'identified'};
Branch: 1 branch
BranchTrueFalseTotal
if $interface->{"identified"} 0 0 0
432 }
433 }
434 0 print ((' 'x$config{'Indent'}).$device_count.' device');
435 0 ▶ print 's' if $device_count > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $device_count > 1 0 0 0
436 0 ▶ print ' ('.$identified_device_count.' identified)' if $identified_device_count > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $identified_device_count > 0 0 0 0
437 0 print "\n";
438 0 print ((' 'x$config{'Indent'}).$interface_count.' interface');
439 0 ▶ print 's' if $interface_count > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $interface_count > 1 0 0 0
440 0 ▶ print ' ('.$identified_interface_count.' identified)' if $identified_interface_count > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $identified_interface_count > 0 0 0 0
441 0 print "\n";
442 }
443  
444 0 ▶ if (defined $node->{'info'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $node->{"info"}) 0 0 0
445 0 my $info = $node->{'info'};
446 0 ▶ if ($device_count == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($device_count == 1) 0 0 0
447 #say ((' 'x$config{'Indent'}).$info->class);
448 0 say ((' 'x$config{'Indent'}).$info->vendor.' '.$info->model);
449 0 say ((' 'x$config{'Indent'}).$info->serial);
450 }
451 }
452 }
453 0 ▶ say scalar (@nodes).' nodes' if @nodes > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @nodes > 1 0 0 0
454 }
455  
456  
457 =head2 device_dump
458  
459 prints a device structure
460  
461 B<Arguments>
462  
463 I<( @devices )>
464  
465 =over 3
466  
467 =item devices
468  
469 an array of devices to print
470  
471 =back
472  
473 =cut
474  
475 0 ▶sub device_dump {
Subroutine device_dump: not called CC=10 SCAR=47.0
Pod documented
476 0 ▶ warn 'too few arguments' if @_ < 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 1 0 0 0
477 0 my (@devices) = @_;
478  
479 0 foreach my $device (@devices) {
480 0 say device_string $device;
481  
482 0 ▶ if (defined $device->{'identified'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $device->{"identified"}) 0 0 0
483 0 ▶ say ((' 'x$config{'Indent'}).(($device->{'identified'}) ? 'identified' : 'unidentified'));
Branch: 1 branch
BranchTrueFalseTotal
$device->{'identified'} ? : 0 0 0
484 }
485  
486 0 ▶ if (defined $device->{'interfaces'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $device->{"interfaces"}) 0 0 0
487 0 my $interface_count = scalar keys %{$device->{'interfaces'}};
488 0 my $identified_interface_count = 0;
489 0 foreach my $ifName (keys %{$device->{'interfaces'}}) {
490 0 my $interface = $device->{'interfaces'}{$ifName};
491 0 ▶ ++$identified_interface_count if $interface->{'identified'};
Branch: 1 branch
BranchTrueFalseTotal
if $interface->{"identified"} 0 0 0
492 }
493 0 print ((' 'x$config{'Indent'}).$interface_count.' interface');
494 0 ▶ print 's' if $interface_count > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $interface_count > 1 0 0 0
495 0 say ' ('.$identified_interface_count.' identified)';
496 }
497 }
498 0 ▶ say scalar (@devices).' devices' if @devices > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @devices > 1 0 0 0
499 }
500  
501  
502 =head2 interface_dump
503  
504 prints an interface structure
505  
506 B<Arguments>
507  
508 I<( @interfaces )>
509  
510 =over 3
511  
512 =item interfaces
513  
514 an array of interfaces to print
515  
516 =back
517  
518 =cut
519  
520 0 ▶sub interface_dump {
Subroutine interface_dump: not called CC=9 SCAR=45.0
Pod documented
521 0 ▶ warn 'too few arguments' if @_ < 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 1 0 0 0
522 0 my (@interfaces) = @_;
523  
524 0 foreach my $interface (@interfaces) {
525 0 say interface_string $interface;
526  
527 0 ▶ if (defined $interface->{'identified'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $interface->{"identified"}) 0 0 0
528 0 ▶ say ((' 'x$config{'Indent'}).(($interface->{'identified'}) ? 'identified' : 'unidentified'));
Branch: 1 branch
BranchTrueFalseTotal
$interface->{'identified'} ? : 0 0 0
529 }
530  
531 0 ▶ if (defined $interface->{'info'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $interface->{"info"}) 0 0 0
532 0 foreach my $field (sort keys %{$interface->{'info'}}) {
533 0 print ((' 'x$config{'Indent'}).$field.': ');
534 0 ▶ say (($interface->{'info'}{$field} =~ /[\S]+/) ? $interface->{'info'}{$field} : '(empty)');
Branch: 1 branch
BranchTrueFalseTotal
$interface->{'info'}{$field} =~ /[\S]+/ ? : 0 0 0
535 }
536 }
537 }
538 0 ▶ say scalar (@interfaces).' interfaces' if @interfaces > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @interfaces > 1 0 0 0
539 }
540  
541  
542  
543  
544 ################################################################################
545  
546  
547  
548  
549 =head2 node_find
550  
551 check for a node in a set of nodes
552  
553 B<Arguments>
554  
555 I<( \%nodes , $ip )>
556  
557 =over 3
558  
559 =item nodes
560  
561 an array of nodes to search
562  
563 =item ip
564  
565 the IP address of the node
566  
567 =back
568  
569 =cut
570  
571 0 ▶sub node_find {
Subroutine node_find: not called CC=3 SCAR=24.8
Pod documented
572 0 ▶ warn 'too few arguments' if @_ < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 0 0 0
573 0 ▶ warn 'too many arguments' if @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 2 0 0 0
574 0 my ($nodes,$ip) = @_;
575  
576 0 return $nodes->{$ip};
577 }
578  
579  
580 =head2 device_find
581  
582 check for a device in a set of nodes
583  
584 B<Arguments>
585  
586 I<( \%nodes , $serial )>
587  
588 =over 3
589  
590 =item nodes
591  
592 an array of nodes to search
593  
594 =item serial
595  
596 a unique device identifier
597  
598 =back
599  
600 =cut
601  
602 0 ▶sub device_find {
Subroutine device_find: not called CC=5 SCAR=34.0
Pod documented
603 0 ▶ warn 'too few arguments' if @_ < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 0 0 0
604 0 ▶ warn 'too many arguments' if @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 2 0 0 0
605 0 my ($nodes,$serial) = @_;
606 0 $serial = uc $serial;
607  
608 0 foreach my $ip (keys %$nodes) {
609 0 my $node = $nodes->{$ip};
610 0 ▶ if (defined $node->{'devices'}{$serial}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $node->{"devices"}{$serial}) 0 0 0
611 0 my $device = $node->{'devices'}{$serial};
612 0 $device->{'identified'} = 1;
613 0 return $device;
614 }
615 }
616 0 return undef;
617 }
618  
619  
620 =head2 interface_find
621  
622 check for a interface in a set of devices
623  
624 B<Arguments>
625  
626 I<( $devices , $ifName )>
627  
628 =over 3
629  
630 =item devices
631  
632 an array of devices to search
633  
634 =item ifName
635  
636 a unique interface identifier
637  
638 =back
639  
640 =cut
641  
642 0 ▶sub interface_find {
Subroutine interface_find: not called CC=5 SCAR=34.0
Pod documented
643 0 ▶ warn 'too few arguments' if @_ < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 0 0 0
644 0 ▶ warn 'too many arguments' if @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 2 0 0 0
645 0 my ($devices,$ifName) = @_;
646  
647 0 foreach my $serial (keys %$devices) {
648 0 my $device = $devices->{$serial};
649 0 ▶ if (defined $device->{'interfaces'}{$ifName}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $device->{"interfaces"}{$ifName}) 0 0 0
650 0 my $interface = $device->{'interfaces'}{$ifName};
651 0 $interface->{'identified'} = 1;
652 0 return $interface;
653 }
654 }
655 0 return undef;
656 }
657  
658  
659 =head1 AUTHOR
660  
661 David Tucker, C<< <dmtucker at ucsc.edu> >>
662  
663 =head1 BUGS
664  
665 B<I<This module should be changed to use object-orientation.
666 Until then, all of the included functions are exported!>>
667  
668 Please report any bugs or feature requests to C<bug-netsync at rt.cpan.org>, or through
669 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-Netsync>. I will be notified, and then you'll
670 automatically be notified of progress on your bug as I make changes.
671  
672 =head1 SUPPORT
673  
674 You can find documentation for this module with the perldoc command.
675  
676 perldoc App::Netsync
677  
678 You can also look for information at:
679  
680 =over 4
681  
682 =item * RT: CPAN's request tracker (report bugs here)
683  
684 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=App-Netsync>
685  
686 =item * AnnoCPAN: Annotated CPAN documentation
687  
688 L<http://annocpan.org/dist/App-Netsync>
689  
690 =item * CPAN Ratings
691  
692 L<http://cpanratings.perl.org/d/App-Netsync>
693  
694 =item * Search CPAN
695  
696 L<http://search.cpan.org/dist/App-Netsync/>
697  
698 =back
699  
700 =head1 LICENSE
701  
702 Copyright 2013 David Tucker.
703  
704 This program is free software; you can redistribute it and/or modify it
705 under the terms of either: the GNU General Public License as published
706 by the Free Software Foundation; or the Artistic License.
707  
708 See L<http://dev.perl.org/licenses/> for more information.
709  
710 =cut
711  
712  
713 1 1;
« Netsync/Configurator.pm ↑ Summary Netsync/Scribe.pm »