script/ciscoospf2yaml

filter: Statementstmt 75.0% 21 / 28 Branchbran 12.5% 1 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 68.1% 30 / 44 CC 5 SCAR 16.2
CC
5
Cov
61%
main
12.6
usage
2.0
BEGIN
1.0
CRAP 5.0
« script/ospfd2yaml ↑ Summary blib/lib/OSPF/LSDB.pm »
1 #!/usr/bin/perl
2  
3 ##########################################################################
4 # Copyright (c) 2010-2012 Alexander Bluhm <alexander.bluhm@gmx.net>
5 #
6 # Permission to use, copy, modify, and distribute this software for any
7 # purpose with or without fee is hereby granted, provided that the above
8 # copyright notice and this permission notice appear in all copies.
9 #
10 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 ##########################################################################
18  
19 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Getopt::Long qw(:config posix_default bundling);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use OSPF::LSDB::Cisco;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use OSPF::LSDB::YAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 sub usage(@) {
26 1 ▶ print STDERR "Error: @_\n" if @_;
Subroutine usage: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
27 1 print STDERR <<EOF;
28 Convert Cisco OSPF link state database to YAML file. If the show
29 ip ospf content files are not given on the command line, ssh is
30 invoked to log into the router.
31  
32 Usage: $0 [-h] [-B boundary] [-E external] [-H user\@host]
33 [-I selfid] [-N network] [-R router] [-S summary] [ospf.yaml]
34 -h help, print usage
35 -B boundary file containg output of 'show ip ospf database asbr-summary'
36 -E external file containg output of 'show ip ospf database external'
37 -H user\@host use user\@host for ssh login
38 -I selfid file containg output of 'show ip ospf summary'
39 -N network file containg output of 'show ip ospf database network'
40 -R router file containg output of 'show ip ospf database router'
41 -S summary file containg output of 'show ip ospf database summary'
42 ospf.yaml output file, default stdout
43 EOF
44 1 exit(2);
45 }
46  
47 sub main() {
48 1 ▶ my(%files, $ssh);
Subroutine main: called CC=4 SCAR=25.3
49 GetOptions(
50 1 ▶ 'h' => sub { usage() },
Subroutine __ANON__: called CC=1 SCAR=0.0
51 'B=s' => \$files{boundary},
52 'E=s' => \$files{external},
53 'H=s' => \$ssh,
54 'I=s' => \$files{selfid},
55 'N=s' => \$files{network},
56 'R=s' => \$files{router},
57 'S=s' => \$files{summary},
58 1 ▶ ) or usage("Bad option");
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("h", sub { &usage(); } , "B=s", \$files{"boundary"}, "E=s", \$files{"external"}, "H=s", \$ssh, "I=s", \$files{"selfid"}, "N=s", \$files{"network"}, "R=s", \$files{"router"}, "S=s", \$files{"summary"}) or &usage("Bad option") 0 0 0
59 0 ▶ usage("Only one arguments allowed") if @ARGV > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @ARGV > 1 0 0 0
60  
61 0 my $cisco = OSPF::LSDB::Cisco->new(ssh => $ssh);
62 0 $cisco->parse(%files);
63  
64 0 my $yaml = OSPF::LSDB::YAML->new($cisco);
65 0 ▶ if (@ARGV > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV > 0) { } 0 0 0
66 0 $yaml->DumpFile($ARGV[0]);
67 } else {
68 0 print $yaml->Dump();
69 }
70 }
71  
72 main();
« script/ospfd2yaml ↑ Summary blib/lib/OSPF/LSDB.pm »