Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #276 from opscode/lcg/option-number-two

avoid monkeypatching the encaps_lookup() method
  • Loading branch information...
commit 2f2cb54cc1166b006b9f64bacde3045f225f241d 2 parents 159bc0e + 51923fd
@lamont-granquist lamont-granquist authored
View
12 lib/ohai/plugins/darwin/network.rb
@@ -34,7 +34,7 @@ def parse_media(media_string)
media[line_array[i]]["options"] << opt unless media[line_array[i]]["options"].include?(opt)
end
else
- media[line_array[i]]["options"] = $1.split(",")
+ media[line_array[i]]["options"] = $1.split(",")
end
else
if line_array[i].eql?("autoselect")
@@ -50,7 +50,7 @@ def parse_media(media_string)
media
end
- def encaps_lookup(ifname)
+ def darwin_encaps_lookup(ifname)
return "Loopback" if ifname.eql?("lo")
return "1394" if ifname.eql?("fw")
return "IPIP" if ifname.eql?("gif")
@@ -79,7 +79,7 @@ def locate_interface(ifaces, ifname, mac)
return ifc if addr.eql? mac
end
end
-
+
nil
end
@@ -90,7 +90,7 @@ def locate_interface(ifaces, ifname, mac)
network[:interfaces] = Mash.new unless network[:interfaces]
counters Mash.new unless counters
counters[:network] = Mash.new unless counters[:network]
-
+
so = shell_out("route -n get default")
so.stdout.lines do |line|
if line =~ /(\w+): ([\w\.]+)/
@@ -102,7 +102,7 @@ def locate_interface(ifaces, ifname, mac)
end
end
end
-
+
iface = Mash.new
so = shell_out("ifconfig -a")
cint = nil
@@ -120,7 +120,7 @@ def locate_interface(ifaces, ifname, mac)
if cint =~ /^(\w+)(\d+.*)/
iface[cint][:type] = $1
iface[cint][:number] = $2
- iface[cint][:encapsulation] = encaps_lookup($1)
+ iface[cint][:encapsulation] = darwin_encaps_lookup($1)
end
end
if line =~ /^\s+ether ([0-9a-f\:]+)/
View
12 lib/ohai/plugins/linux/network.rb
@@ -21,7 +21,7 @@
provides "counters/network", "counters/network/interfaces"
provides "ipaddress", "ip6address", "macaddress"
- def encaps_lookup(encap)
+ def linux_encaps_lookup(encap)
return "Loopback" if encap.eql?("Local Loopback") || encap.eql?("loopback")
return "PPP" if encap.eql?("Point-to-Point Protocol")
return "SLIP" if encap.eql?("Serial Line IP")
@@ -44,7 +44,7 @@ def encaps_lookup(encap)
counters[:network] = Mash.new unless counters[:network]
# Match the lead line for an interface from iproute2
- # 3: eth0.11@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
+ # 3: eth0.11@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
# The '@eth0:' portion doesn't exist on primary interfaces and thus is optional in the regex
IPROUTE_INT_REGEX = /^(\d+): ([0-9a-zA-Z@:\.\-_]*?)(@[0-9a-zA-Z]+|):\s/
@@ -84,7 +84,7 @@ def encaps_lookup(encap)
end
end
if line =~ /link\/(\w+) ([\da-f\:]+) /
- iface[cint][:encapsulation] = encaps_lookup($1)
+ iface[cint][:encapsulation] = linux_encaps_lookup($1)
unless $2 == "00:00:00:00:00:00"
iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
iface[cint][:addresses][$2.upcase] = { "family" => "lladdr" }
@@ -160,7 +160,7 @@ def encaps_lookup(encap)
net_counters[tmp_int][:tx] = Mash.new unless net_counters[tmp_int][:tx]
net_counters[tmp_int][:tx][:queuelen] = $1
end
-
+
if line =~ /vlan id (\d+)/
tmp_id = $1
iface[tmp_int][:vlan] = Mash.new unless iface[tmp_int][:vlan]
@@ -324,7 +324,7 @@ def encaps_lookup(encap)
cint = nil
so.stdout.lines do |line|
tmp_addr = nil
- # dev_valid_name in the kernel only excludes slashes, nulls, spaces
+ # dev_valid_name in the kernel only excludes slashes, nulls, spaces
# http://git.kernel.org/?p=linux/kernel/git/stable/linux-stable.git;a=blob;f=net/core/dev.c#l851
if line =~ /^([0-9a-zA-Z@\.\:\-_]+)\s+/
cint = $1
@@ -335,7 +335,7 @@ def encaps_lookup(encap)
end
end
if line =~ /Link encap:(Local Loopback)/ || line =~ /Link encap:(.+?)\s/
- iface[cint][:encapsulation] = encaps_lookup($1)
+ iface[cint][:encapsulation] = linux_encaps_lookup($1)
end
if line =~ /HWaddr (.+?)\s/
iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
View
4 lib/ohai/plugins/sigar/network.rb
@@ -22,7 +22,7 @@
provides "network", "network/interfaces"
provides "counters/network", "counters/network/interfaces"
- def encaps_lookup(encap)
+ def sigar_encaps_lookup(encap)
return "Loopback" if encap.eql?("Local Loopback")
return "PPP" if encap.eql?("Point-to-Point Protocol")
return "SLIP" if encap.eql?("Serial Line IP")
@@ -45,7 +45,7 @@ def fetch_interfaces(sigar)
end
ifconfig = sigar.net_interface_config(cint)
- iface[cint][:encapsulation] = encaps_lookup(ifconfig.type)
+ iface[cint][:encapsulation] = sigar_encaps_lookup(ifconfig.type)
iface[cint][:addresses] = Mash.new
# Backwards compat: loopback has no hwaddr
View
4 lib/ohai/plugins/solaris2/network.rb
@@ -57,7 +57,7 @@
provides "network", "network/interfaces"
provides "counters/network", "counters/network/interfaces"
- def encaps_lookup(ifname)
+ def solaris_encaps_lookup(ifname)
return "Ethernet" if ifname.eql?("e1000g")
return "Ethernet" if ifname.eql?("eri")
return "Ethernet" if ifname.eql?("net")
@@ -100,7 +100,7 @@ def arpname_to_ifname(iface, arpname)
if cint =~ /^(\w+)(\d+.*)/
iface[cint][:type] = $1
iface[cint][:number] = $2
- iface[cint][:encapsulation] = encaps_lookup($1)
+ iface[cint][:encapsulation] = solaris_encaps_lookup($1)
end
end
if line =~ /\s+inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) netmask (([0-9a-f]){1,8})\s*$/
View
4 lib/ohai/plugins/windows/network.rb
@@ -20,7 +20,7 @@
provides "network", "network/interfaces"
provides "counters/network", "counters/network/interfaces"
- def encaps_lookup(encap)
+ def windows_encaps_lookup(encap)
return "Ethernet" if encap.eql?("Ethernet 802.3")
encap
end
@@ -95,7 +95,7 @@ def encaps_lookup(encap)
iface[cint][:mtu] = iface[cint][:configuration][:mtu]
iface[cint][:type] = iface[cint][:instance][:adapter_type]
iface[cint][:arp] = {}
- iface[cint][:encapsulation] = encaps_lookup(iface[cint][:instance][:adapter_type])
+ iface[cint][:encapsulation] = windows_encaps_lookup(iface[cint][:instance][:adapter_type])
if iface[cint][:configuration][:default_ip_gateway] != nil and iface[cint][:configuration][:default_ip_gateway].size > 0
network[:default_gateway] = iface[cint][:configuration][:default_ip_gateway].first
network[:default_interface] = cint
Please sign in to comment.
Something went wrong with that request. Please try again.