summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2011-01-25 07:44:51 +1000
committerStephen Hemminger <stephen.hemminger@vyatta.com>2011-01-24 15:08:04 -0800
commita1087973b84c87fde430de4f66b188c0473fd54f (patch)
treeb09ff44cd0e1e74e510306a34973d8945b4c16e8
parent39f9647acbc45c1f7868d2f40342b276679ea3b8 (diff)
downloadvyatta-cfg-system-a1087973b84c87fde430de4f66b188c0473fd54f.tar.gz
vyatta-cfg-system-a1087973b84c87fde430de4f66b188c0473fd54f.zip
Don't fail if config.boot does not exist
Bug 6718 On livecd config.boot does not exist yet, so no existing hw-id mappings. (cherry picked from commit 37bbcaef6083a843cb3dd9976854a30ab7cebe16)
-rwxr-xr-xscripts/vyatta_net_name47
1 files changed, 28 insertions, 19 deletions
diff --git a/scripts/vyatta_net_name b/scripts/vyatta_net_name
index 7e6d2a8a..5de49b94 100755
--- a/scripts/vyatta_net_name
+++ b/scripts/vyatta_net_name
@@ -92,6 +92,33 @@ sub biosdevname {
return ($biosname eq '') ? $ifname : $biosname;
}
+# parse vyatta config.boot
+# if file does not then running before off livecd then return empty hash
+sub parse_config_boot {
+ my $interfaces = {};
+
+ if ( -f $BOOTFILE ) {
+ my $xcp = new XorpConfigParser();
+ $xcp->parse($BOOTFILE);
+
+ my $inode = $xcp->get_node(['interfaces']);
+ if ($inode) {
+ foreach my $child (@{$inode->{'children'}}) {
+ my $name = $child->{'name'};
+ next unless ($name =~ /^ethernet (.*)|^wireless (.*)/);
+
+ my $intf = $1;
+ my $hwid = get_hwid_from_children($child->{'children'});
+ next unless $hwid;
+
+ $interfaces->{$hwid} = $intf;
+ }
+ }
+ }
+
+ return $interfaces;
+}
+
# Determine network name to use based on Vyatta config during boot
sub coldplug {
my ($ifname, $hwaddr) = @_;
@@ -103,25 +130,7 @@ sub coldplug {
print {$log} "lookup $ifname $hwaddr\n";
# parse config file to produce map of existing hw-id values
- my $xcp = new XorpConfigParser();
- $xcp->parse($BOOTFILE);
-
- my $interfaces = { };
- my $inode = $xcp->get_node(['interfaces']);
- if ($inode) {
- foreach my $child (@{$inode->{'children'}}) {
- next unless ($child->{'name'} =~ /^ethernet (.*)|^wireless (.*)/);
-
- my $intf = $1;
- my $hwid = get_hwid_from_children($child->{'children'});
- next unless $hwid;
-
- print {$log} "config hw-id $hwid => $intf\n";
- $interfaces->{$hwid} = $intf;
- }
- } else {
- print {$log} "no interfaces found in $BOOTFILE\n";
- }
+ my $interfaces = parse_config_boot();
# is name already in config file
my $newname = $interfaces->{$hwaddr};