From 31747ed42038d00499099d11abf1e33b3ef7c26f Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Tue, 10 Feb 2009 14:21:20 -0800 Subject: Add new option for checking name validity Many templates should allow any known interface type, since interface may be created later. So create some generic hooks for validation. --- lib/Vyatta/Interface.pm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'lib/Vyatta') diff --git a/lib/Vyatta/Interface.pm b/lib/Vyatta/Interface.pm index ea9c40f..017b7e4 100644 --- a/lib/Vyatta/Interface.pm +++ b/lib/Vyatta/Interface.pm @@ -77,6 +77,9 @@ sub new { my $class = ref($that) || $that; my ($dev, $vif); + # need argument to constructor + return unless $name; + # Strip off vif from name if ( $name =~ m/(\w)+\.(\d)+/ ) { $dev = $1; @@ -87,20 +90,21 @@ sub new { foreach my $prefix (keys %net_prefix) { next unless $dev =~ /$prefix/; - my $path = $net_prefix{$prefix}{path}; + my $type = $net_prefix{$prefix}{path}; my $vifpath = $net_prefix{$prefix}{vif}; # Interface name has vif, but this type doesn't support vif! return if ( $vif && !$vifpath ); # Check path if given - return if ( $#_ >= 0 && join( ' ', @_ ) ne $path ); + return if ( $#_ >= 0 && join( ' ', @_ ) ne $type ); - $path = "interfaces $path $dev"; + my $path = "interfaces $type $dev"; $path .= " $vifpath $vif" if $vif; my $self = { name => $name, + type => $type, path => $path, dev => $dev, vif => $vif, @@ -108,7 +112,6 @@ sub new { bless $self, $class; return $self; - } return; # nothing @@ -135,6 +138,11 @@ sub physicalDevice { return $self->{dev}; } +sub type { + my $self = shift; + return $self->{type}; +} + ## Configuration checks sub configured { -- cgit v1.2.3