diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-04-06 09:42:02 -0700 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-04-06 09:42:02 -0700 |
commit | 2aa8a18e97fb5081691dca399ceada8fcae21ec7 (patch) | |
tree | 424e806f068b6406ec00af98ea1bbb729ee435f1 | |
parent | 6c2c77f8195037dc429784c5ae0ae795daa54739 (diff) | |
download | vyatta-cfg-qos-2aa8a18e97fb5081691dca399ceada8fcae21ec7.tar.gz vyatta-cfg-qos-2aa8a18e97fb5081691dca399ceada8fcae21ec7.zip |
Add input interface template
Also change how interface qos-policy is generated, using a template
for templates rather than using hardcode expansion.
-rwxr-xr-x | gen-interface-templates.pl | 76 | ||||
-rw-r--r-- | interface-templates/qos-policy/in/node.def | 5 | ||||
-rw-r--r-- | interface-templates/qos-policy/out/node.def | 5 |
3 files changed, 51 insertions, 35 deletions
diff --git a/gen-interface-templates.pl b/gen-interface-templates.pl index 31816aa..8fb221c 100755 --- a/gen-interface-templates.pl +++ b/gen-interface-templates.pl @@ -42,6 +42,8 @@ my %interface_hash = ( 'tunnel/node.tag' => '$VAR(@)', 'bridge/node.tag' => '$VAR(@)', 'openvpn/node.tag' => '$VAR(@)', + 'input/node.tag' => '$VAR(@)', + 'wirelessmodem/node.tag' => '$VAR(@)', 'wireless/node.tag' => '$VAR(@)', 'wireless/node.tag/vif/node.tag' => '$VAR(../@).$VAR(@)', @@ -58,41 +60,48 @@ my %interface_hash = ( ); sub gen_template { - my ( $outpath, $ifname ) = @_; - $ifname =~ s#@\)#..\/..\/@\)#g; + my ( $inpath, $outpath, $ifname ) = @_; print $outpath, "\n" if ($debug); - $outpath .= "/qos-policy"; - mkdir $outpath - or die "Can't mkdir $outpath: $!"; - - open my $node, '>', "$outpath/node.def" - or die "Can't open $outpath/node.def: $!"; - print $node "help: Set Quality of Service (QOS) policy for interface\n"; - close $node - or die "Can't write $outpath/node.def: $!"; - - foreach my $dir qw(in out) { - my $path = "$outpath/$dir"; - - mkdir $path - or die "Can't create directory: $path: $!"; - open my $node, '>', "$path/node.def" - or die "Can't open $path/node.def: $!"; - select $node; - print <<EOF; -type: txt -help: Set ${dir}bound QOS policy for interface -allowed: /opt/vyatta/sbin/vyatta-qos.pl --list-policy $dir -update: /opt/vyatta/sbin/vyatta-qos.pl --update-interface $ifname $dir \$VAR(@) -delete: /opt/vyatta/sbin/vyatta-qos.pl --delete-interface $ifname $dir -EOF - select STDOUT; - close $node - or die "Can't write $path/node.def: $!"; + opendir my $d, $inpath + or die "Can't open: $inpath:$!"; + + # walk through sample templates + foreach my $name ( grep { !/^\./ } readdir $d ) { + my $in = "$inpath/$name"; + my $out = "$outpath/$name"; + + # recurse into subdirectory + if ( -d $in ) { + my $subif = $ifname; + $subif =~ s#@\)#../@)#g if ($name ne 'node.tag'); + + ( -d $out ) + or mkdir($out) + or die "Can't create $out: $!"; + + gen_template( $in, $out, $subif ); + next; + } + + print "in: $in out: $out\n" if ($debug); + open my $inf, '<', $in or die "Can't open $in: $!"; + open my $outf, '>', $out or die "Can't open $out: $!"; + + while ( my $line = <$inf> ) { + $line =~ s#\$IFNAME#$ifname#; + print $outf $line; + } + close $inf; + close $outf or die "Close error $out:$!"; } + closedir $d; } +die "Usage: $0 output_directory\n" if ( $#ARGV < 0 ); + +my $outdir = $ARGV[0]; + sub mkdir_p { my $path = shift; @@ -104,15 +113,12 @@ sub mkdir_p { return mkdir($path); } -die "Usage: $0 output_directory\n" if ( $#ARGV < 0 ); - -my $outdir = $ARGV[0]; - foreach my $if_tree ( keys %interface_hash ) { + my $inpath = "interface-templates"; my $outpath = "$outdir/interfaces/$if_tree"; ( -d $outpath ) or mkdir_p($outpath) or die "Can't create $outpath:$!"; - gen_template( $outpath, $interface_hash{$if_tree} ); + gen_template( $inpath, $outpath, $interface_hash{$if_tree} ); } diff --git a/interface-templates/qos-policy/in/node.def b/interface-templates/qos-policy/in/node.def new file mode 100644 index 0000000..67d3e4b --- /dev/null +++ b/interface-templates/qos-policy/in/node.def @@ -0,0 +1,5 @@ +type: txt +help: Set inbound QOS policy for interface +allowed: /opt/vyatta/sbin/vyatta-qos.pl --list-policy in +update: /opt/vyatta/sbin/vyatta-qos.pl --update-interface $IFNAME in $VAR(@) +delete: /opt/vyatta/sbin/vyatta-qos.pl --delete-interface $IFNAME in diff --git a/interface-templates/qos-policy/out/node.def b/interface-templates/qos-policy/out/node.def new file mode 100644 index 0000000..1a4e213 --- /dev/null +++ b/interface-templates/qos-policy/out/node.def @@ -0,0 +1,5 @@ +type: txt +help: Set outbound QOS policy for interface +allowed: /opt/vyatta/sbin/vyatta-qos.pl --list-policy out +update: /opt/vyatta/sbin/vyatta-qos.pl --update-interface $IFNAME out $VAR(@) +delete: /opt/vyatta/sbin/vyatta-qos.pl --delete-interface $IFNAME out |