diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-11-17 20:42:38 -0800 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-11-17 20:42:38 -0800 |
commit | 2e958dfd2787cb7a347213d6c665fd03ab976a63 (patch) | |
tree | df9233894ff9b2c0e775ce1f24ed59a011a6a33b | |
parent | e7de8b95b1ba4e50abaa62013e84baa98ecdefa4 (diff) | |
download | vyatta-cfg-quagga-2e958dfd2787cb7a347213d6c665fd03ab976a63.tar.gz vyatta-cfg-quagga-2e958dfd2787cb7a347213d6c665fd03ab976a63.zip |
Cleanup bond-group syntax and commit checks
Move check for address and state of slave to commit which
allows for better error message.
-rwxr-xr-x | scripts/vyatta-bonding.pl | 38 | ||||
-rw-r--r-- | templates/interfaces/ethernet/node.tag/bond-group/node.def | 13 |
2 files changed, 32 insertions, 19 deletions
diff --git a/scripts/vyatta-bonding.pl b/scripts/vyatta-bonding.pl index 3737cebb..be09e754 100755 --- a/scripts/vyatta-bonding.pl +++ b/scripts/vyatta-bonding.pl @@ -181,25 +181,39 @@ sub change_hash { if_up($intf) if $bond_up; } -# bonding requires interface to be down before enslaving -# but enslaving automatically brings interface up! -sub add_port { +# Consistency checks prior to commit +sub commit_check { my ( $intf, $slave ) = @_; - my $slaveif = new Vyatta::Interface($slave); my $cfg = new Vyatta::Config; + + die "Bonding interface $intf does not exist\n" + unless ( -d "/sys/class/net/$intf" ); + + my $slaveif = new Vyatta::Interface($slave); + die "$slave: unknown interface type" unless $slaveif; $cfg->setLevel($slaveif->path()); + die "Error: can not add disabled interface $slave to bond-group $intf\n" + if $cfg->exists('disable'); + my @addr = $cfg->returnValues('address'); die "Error: can not add interface $slave with addresses to bond-group\n" if (@addr); +} - if ($slaveif->up()) { - if_down($slave); - } else { - die "Error: can not add disabled interface $slave to bond-group $intf\n" - if $cfg->exists('disable'); - } +# bonding requires interface to be down before enslaving +# but enslaving automatically brings interface up! +sub add_port { + my ( $intf, $slave ) = @_; + my $cfg = new Vyatta::Config; + my $slaveif = new Vyatta::Interface($slave); + die "$slave: unknown interface type" unless $slaveif; + + $cfg->setLevel($slaveif->path()); + my $old = $cfg->returnOrigValue('bond-group'); + if_down($slave) if ($slaveif->up()); + remove_slave($old, $slave) if $old; add_slave ($intf, $slave); } @@ -220,7 +234,7 @@ sub usage { exit 1; } -my ( $dev, $mode, $hash, $add_port, $rem_port ); +my ( $dev, $mode, $hash, $add_port, $rem_port, $check ); GetOptions( 'dev=s' => \$dev, @@ -228,10 +242,12 @@ GetOptions( 'hash=s' => \$hash, 'add=s' => \$add_port, 'remove=s' => \$rem_port, + 'check=s' => \$check, ) or usage(); die "$0: device not specified\n" unless $dev; +commit_check($dev, $check) if $check; change_mode( $dev, $mode ) if $mode; change_hash( $dev, $hash ) if $hash; add_port( $dev, $add_port ) if $add_port; diff --git a/templates/interfaces/ethernet/node.tag/bond-group/node.def b/templates/interfaces/ethernet/node.tag/bond-group/node.def index cb339a42..3fe9ddbe 100644 --- a/templates/interfaces/ethernet/node.tag/bond-group/node.def +++ b/templates/interfaces/ethernet/node.tag/bond-group/node.def @@ -1,15 +1,12 @@ priority: 319 type: txt help: Assign interface to bonding group -commit:expression: exec \ - "${vyatta_sbindir}/vyatta-interfaces.pl --dev=$VAR(@) --check=bonding" - allowed: ${vyatta_sbindir}/vyatta-interfaces.pl --show=bonding +syntax:expression: pattern $VAR(@) "^bond[0-9]+$" \ + ; "bond-group $VAR(@): not a valid name" + +commit:expression: exec "${vyatta_sbindir}/vyatta-bonding.pl --dev=$VAR(@) --check=$VAR(../@)" -update: OLDG=`${vyatta_sbindir}/vyatta-cli-expand-var.pl \\$VAR\(/interfaces/ethernet/$VAR(../@)/bond-group/@\)` - if [ -n "$OLDG" ]; then - sudo ${vyatta_sbindir}/vyatta-bonding.pl --dev=$OLDG --remove=$VAR(../@) - fi - sudo ${vyatta_sbindir}/vyatta-bonding.pl --dev=$VAR(@) --add=$VAR(../@) +update: sudo ${vyatta_sbindir}/vyatta-bonding.pl --dev=$VAR(@) --add=$VAR(../@) delete: sudo ${vyatta_sbindir}/vyatta-bonding.pl --dev=$VAR(@) --remove=$VAR(../@) |