diff options
author | Scott Hain <shain@chef.io> | 2017-11-15 17:02:49 -0800 |
---|---|---|
committer | Scott Hain <shain@chef.io> | 2017-12-11 14:31:04 -0800 |
commit | 449db1eb35c37f3adc7d8c22ffe535de43b300b7 (patch) | |
tree | f53e1a6e6d570f6c9598a90f9f7f3022ba7328ea | |
parent | ef5083c3996b3bafeabe589cb1d0316f6eeefd96 (diff) | |
download | chef-449db1eb35c37f3adc7d8c22ffe535de43b300b7.tar.gz |
Fix for ipaddress issues
Signed-off-by: Scott Hain <shain@chef.io>
-rw-r--r-- | lib/chef/provider/ifconfig.rb | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/chef/provider/ifconfig.rb b/lib/chef/provider/ifconfig.rb index 4f32baaadb..af2463b668 100644 --- a/lib/chef/provider/ifconfig.rb +++ b/lib/chef/provider/ifconfig.rb @@ -65,15 +65,24 @@ class Chef @status = shell_out("ifconfig") @status.stdout.each_line do |line| - if !line[0..9].strip.empty? - @int_name = line[0..9].strip - @interfaces[@int_name] = { "hwaddr" => (line =~ /(HWaddr)/ ? ($') : "nil").strip.chomp } + addr_regex = /^(\w+):?(\d*):?\ .+$/ + if line =~ addr_regex + if line.match(addr_regex).nil? + @int_name = "nil" + elsif line.match(addr_regex)[2] == "" + @int_name = line.match(addr_regex)[1] + @interfaces[@int_name] = Hash.new + @interfaces[@int_name]["mtu"] = (line =~ /mtu (\S+)/ ? Regexp.last_match(1) : "nil") if line =~ /mtu/ && @interfaces[@int_name]["mtu"].nil? + else + @int_name = "#{line.match(addr_regex)[1]}:#{line.match(addr_regex)[2]}" + @interfaces[@int_name] = Hash.new + @interfaces[@int_name]["mtu"] = (line =~ /mtu (\S+)/ ? Regexp.last_match(1) : "nil") if line =~ /mtu/ && @interfaces[@int_name]["mtu"].nil? + end else - @interfaces[@int_name]["inet_addr"] = (line =~ /inet addr:(\S+)/ ? Regexp.last_match(1) : "nil") if line =~ /inet addr:/ - @interfaces[@int_name]["bcast"] = (line =~ /Bcast:(\S+)/ ? Regexp.last_match(1) : "nil") if line =~ /Bcast:/ - @interfaces[@int_name]["mask"] = (line =~ /Mask:(\S+)/ ? Regexp.last_match(1) : "nil") if line =~ /Mask:/ - @interfaces[@int_name]["mtu"] = (line =~ /MTU:(\S+)/ ? Regexp.last_match(1) : "nil") if line =~ /MTU:/ - @interfaces[@int_name]["metric"] = (line =~ /Metric:(\S+)/ ? Regexp.last_match(1) : "nil") if line =~ /Metric:/ + @interfaces[@int_name]["inet_addr"] = (line =~ /inet (\S+)/ ? Regexp.last_match(1) : "nil") if line =~ /inet/ && @interfaces[@int_name]["inet_addr"].nil? + @interfaces[@int_name]["bcast"] = (line =~ /broadcast (\S+)/ ? Regexp.last_match(1) : "nil") if line =~ /broadcast/ && @interfaces[@int_name]["bcast"].nil? + @interfaces[@int_name]["mask"] = (line =~ /netmask (\S+)/ ? Regexp.last_match(1) : "nil") if line =~ /netmask/ && @interfaces[@int_name]["mask"].nil? + @interfaces[@int_name]["metric"] = (line =~ /Metric:(\S+)/ ? Regexp.last_match(1) : "nil") if line =~ /Metric:/ && @interfaces[@int_name]["metric"].nil? end next unless @interfaces.key?(new_resource.device) |