-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathvtysh2templates
executable file
·119 lines (107 loc) · 2.5 KB
/
vtysh2templates
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/perl
# create templates from output of "vtysh -c list"
sub mk_node_def {
local ($p, $help) = @_;
if ( ! -d $p ) {
mkdir $p
or die "Can\'t create $p: $!";
}
if ( ! -r "$p/node.def" ) {
open(NODE_DEF, ">", "$p/node.def")
or die "Can\'t create $p/node.def: $!";
print NODE_DEF "help: $help\n";
close NODE_DEF;
}
}
sub add_run { # add run field to given node.def
local ($node_def) = @_;
local $has_run=0;
if ( -r $node_def ) {
open(IN, "<", $node_def)
or die "Can\'t read $node_def: $!";
while (<IN>) {
$has_run=1 if (/^run:/);
}
close IN;
}
if ( ! $has_run ) {
open(NODE_DEF, ">>", "$p/node.def")
or die "Can\'t append run command to $p/node.def: $!";
print NODE_DEF 'run: vtysh -c "$*"', "\n";
close NODE_DEF;
}
}
sub recursive_process { # path, help, arg ...
local $p = shift;
local $help = shift;
while (@_ > 0) {
local $a = shift;
if ( $a =~ /^\(/ ) {
$a =~ s/^\(//;
$a =~ s/\)$//;
for $aa ( split /\|/, $a ) {
local @args;
push @args, $aa, @_;
recursive_process($p,$help,@args);
}
return;
} else {
if ( $a eq "detail" ) {
$help =~ s/ / detailed /;
} elsif ( $a =~ /(bgp|ospf6|ospf|ripng|rip|isis|prefix-list)/ ) {
local $protocol = uc $1;
$help =~ s/PROTOCOL/$protocol/;
}
if ( $a =~ /[A-Z]/ ) {
$p .= "/node.tag";
if ( $help =~ /for given/ ) {
$help .= ", ";
} else {
$help .= " for given ";
}
if ( $a =~ /(A.B.C.D\/M|X:.*\/M)/ ) {
$help .= "network";
} elsif ( $a =~ /(A.B.C.D|X:.*)/ ) {
$help .= "address";
} elsif ( $a =~ /LINE/ ) {
$help .= "LINE";
} elsif ( $a =~ /WORD/ ) {
$help .= "WORD";
} elsif ( $a =~ /AA:NN/ ) {
$help .= "extended attributes";
} else {
$help .= $a;
}
} elsif ( $a =~ /<1-65535>/ ) {
$p .= "/node.tag";
$help .= "number";
} elsif ( $a eq '*' ) {
$p .= "/node.tag";
$help .= "wild card";
} else {
$p .= "/$a";
}
mk_node_def($p, $help);
}
}
add_run("$p/node.def");
}
while (<>) {
local $help;
chop;
s/^\s+//;
if ( s/^(show)\s+// ) {
$help = "Show PROTOCOL information";
} elsif ( s/^(debug)\s+// ) {
$help = "Enable PROTOCOL debugging";
} elsif ( s/^(undebug|no debug)\s+// ) {
$help = "Disable PROTOCOL debugging";
} elsif ( s/^(clear)\s+// ) {
$help = "Clear PROTOCOL statistics or status";
} else {
s/(\w+)\s+//;
$help = $1;
}
recursive_process("templates/$1", $help, split);
}
exit 0;