BasicObject
Match the lead line for an interface from iproute2 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
From sigar: include/sigar.h sigar_net_route_t
Author |
Adam Jacob (<adam@opscode.com>) |
Copyright |
Copyright (c) 2008 Opscode, Inc. |
License |
Apache License, Version 2.0 |
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
# File lib/ohai/plugins/uptime.rb, line 19 def _seconds_to_human(seconds) days = seconds.to_i / 86400 seconds -= 86400 * days hours = seconds.to_i / 3600 seconds -= 3600 * hours minutes = seconds.to_i / 60 seconds -= 60 * minutes if days > 1 return sprintf("%d days %02d hours %02d minutes %02d seconds", days, hours, minutes, seconds) elsif days == 1 return sprintf("%d day %02d hours %02d minutes %02d seconds", days, hours, minutes, seconds) elsif hours > 0 return sprintf("%d hours %02d minutes %02d seconds", hours, minutes, seconds) elsif minutes > 0 return sprintf("%d minutes %02d seconds", minutes, seconds) else return sprintf("%02d seconds", seconds) end end
# File lib/ohai/plugins/solaris2/network.rb, line 67 def arpname_to_ifname(iface, arpname) iface.keys.each do |ifn| return ifn if ifn.split(':')[0].eql?(arpname) end nil end
Make top-level cloud hashes
# File lib/ohai/plugins/cloud.rb, line 25 def create_objects cloud Mash.new cloud[:public_ips] = Array.new cloud[:private_ips] = Array.new end
# File lib/ohai/plugins/windows/network.rb, line 23 def encaps_lookup(encap) return "Ethernet" if encap.eql?("Ethernet 802.3") encap end
# File lib/ohai/plugins/darwin/network.rb, line 80 def excluded_setting?(setting) setting.match('_sw_cksum') end
# File lib/ohai/plugins/network.rb, line 38 def find_ip_and_mac(addresses, match = nil) ip = nil; mac = nil; ip6 = nil addresses.keys.each do |addr| if match.nil? ip = addr if addresses[addr]["family"].eql?("inet") else ip = addr if addresses[addr]["family"].eql?("inet") && network_contains_address(match, addr, addresses[addr]) end ip6 = addr if addresses[addr]["family"].eql?("inet6") && addresses[addr]["scope"].eql?("Global") mac = addr if addresses[addr]["family"].eql?("lladdr") break if (ip and mac) end Ohai::Log.debug("Found IPv4 address #{ip} with MAC #{mac} #{match.nil? ? '' : 'matching address ' + match}") Ohai::Log.debug("Found IPv6 address #{ip6}") if ip6 [ip, mac, ip6] end
# File lib/ohai/plugins/passwd.rb, line 5 def fix_encoding(str) str.force_encoding(Encoding.default_external) if str.respond_to?(:force_encoding) str end
# File lib/ohai/plugins/sigar/network_route.rb, line 24 def flags(flags) f = "" if (flags & Sigar::RTF_UP) != 0 f += "U" end if (flags & Sigar::RTF_GATEWAY) != 0 f += "G" end if (flags & Sigar::RTF_HOST) != 0 f += "H" end f end
Fill cloud hash with ec2 values
# File lib/ohai/plugins/cloud.rb, line 45 def get_ec2_values cloud[:public_ips] << ec2['public_ipv4'] cloud[:private_ips] << ec2['local_ipv4'] cloud[:public_ipv4] = ec2['public_ipv4'] cloud[:public_hostname] = ec2['public_hostname'] cloud[:local_ipv4] = ec2['local_ipv4'] cloud[:local_hostname] = ec2['local_hostname'] cloud[:provider] = "ec2" end
# File lib/ohai/plugins/cloud.rb, line 104 def get_eucalyptus_values cloud[:public_ips] << eucalyptus['public_ipv4'] cloud[:private_ips] << eucalyptus['local_ipv4'] cloud[:public_ipv4] = eucalyptus['public_ipv4'] cloud[:public_hostname] = eucalyptus['public_hostname'] cloud[:local_ipv4] = eucalyptus['local_ipv4'] cloud[:local_hostname] = eucalyptus['local_hostname'] cloud[:provider] = "eucalyptus" end
Names rackspace ip address
name<Symbol> |
Use :public_ip or :private_ip |
eth<Symbol> |
Interface name of public or private ip |
# File lib/ohai/plugins/rackspace.rb, line 59 def get_ip_address(name, eth) network[:interfaces][eth][:addresses].each do |key, info| rackspace[name] = key if info['family'] == 'inet' end end
# File lib/ohai/plugins/eucalyptus.rb, line 30 def get_mac_address(addresses) detected_addresses = addresses.detect { |address, keypair| keypair == {"family"=>"lladdr"} } if detected_addresses return detected_addresses.first else return "" end end
Fill cloud hash with rackspace values
# File lib/ohai/plugins/cloud.rb, line 75 def get_rackspace_values cloud[:public_ips] << rackspace['public_ip'] cloud[:private_ips] << rackspace['private_ip'] cloud[:public_ipv4] = rackspace['public_ipv4'] cloud[:public_hostname] = rackspace['public_hostname'] cloud[:local_ipv4] = rackspace['local_ipv4'] cloud[:local_hostname] = rackspace['local_hostname'] cloud[:provider] = "rackspace" end
Author |
Adam Jacob (<adam@opscode.com>) |
Copyright |
Copyright (c) 2008 Opscode, Inc. |
License |
Apache License, Version 2.0 |
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
# File lib/ohai/plugins/linux/platform.rb, line 19 def get_redhatish_platform(contents) contents[/^Red Hat/] ? "redhat" : contents[/(\w+)/, 1].downcase end
# File lib/ohai/plugins/linux/platform.rb, line 23 def get_redhatish_version(contents) contents[/Rawhide/] ? contents[/((\d+) \(Rawhide\))/, 1].downcase : contents[/release ([\d\.]+)/, 1] end
# File lib/ohai/plugins/ec2.rb, line 30 def has_ec2_mac? network[:interfaces].values.each do |iface| unless iface[:arp].nil? if iface[:arp].value?("fe:ff:ff:ff:ff:ff") Ohai::Log.debug("has_ec2_mac? == true") return true end end end Ohai::Log.debug("has_ec2_mac? == false") false end
# File lib/ohai/plugins/eucalyptus.rb, line 39 def has_euca_mac? network[:interfaces].values.each do |iface| has_mac = (get_mac_address(iface[:addresses]) =~ /^[dD]0:0[dD]:/) Ohai::Log.debug("has_euca_mac? == #{!!has_mac}") return true if has_mac end Ohai::Log.debug("has_euca_mac? == false") false end
Checks for matching rackspace kernel name
true |
If kernel name matches |
false |
Otherwise |
# File lib/ohai/plugins/rackspace.rb, line 27 def has_rackspace_kernel? kernel[:release].split('-').last.eql?("rscloud") end
Checks for matching rackspace arp mac
true |
If mac address matches |
false |
Otherwise |
# File lib/ohai/plugins/rackspace.rb, line 36 def has_rackspace_mac? network[:interfaces].values.each do |iface| unless iface[:arp].nil? return true if iface[:arp].value?("00:00:0c:07:ac:01") or iface[:arp].value?("00:00:0c:9f:f0:01") end end false end
# File lib/ohai/plugins/darwin/network.rb, line 84 def locate_interface(ifaces, ifname, mac) return ifname unless ifaces[ifname].nil? # oh well, time to go hunting! return ifname.chop if ifname.match /\*$/ ifaces.keys.each do |ifc| ifaces[ifc][:addresses].keys.each do |addr| return ifc if addr.eql? mac end end nil end
# File lib/ohai/plugins/ec2.rb, line 43 def looks_like_ec2? # Try non-blocking connect so we don't "block" if # the Xen environment is *not* EC2 hint?('ec2') || has_ec2_mac? && can_metadata_connect?(EC2_METADATA_ADDR,80) end
# File lib/ohai/plugins/eucalyptus.rb, line 50 def looks_like_euca? # Try non-blocking connect so we don't "block" if # the Xen environment is *not* EC2 hint?('eucalyptus') || has_euca_mac? && can_metadata_connect?(EC2_METADATA_ADDR,80) end
Identifies the rackspace cloud
true |
If the rackspace cloud can be identified |
false |
Otherwise |
# File lib/ohai/plugins/rackspace.rb, line 50 def looks_like_rackspace? hint?('rackspace') || has_rackspace_mac? || has_rackspace_kernel? end
# File lib/ohai/plugins/windows/kernel.rb, line 23 def machine_lookup(sys_type) return "i386" if sys_type.eql?("X86-based PC") return "x86_64" if sys_type.eql?("x64-based PC") sys_type end
# File lib/ohai/plugins/network.rb, line 55 def network_contains_address(address_to_match, network_ip, network_opts) if network_opts[:peer] network_opts[:peer] == address_to_match else network = IPAddress "#{network_ip}/#{network_opts[:netmask]}" host = IPAddress address_to_match network.include?(host) end end
Is current cloud ec2?
true |
If ec2 Hash is defined |
false |
Otherwise |
# File lib/ohai/plugins/cloud.rb, line 40 def on_ec2? ec2 != nil end
Is current cloud eucalyptus?
true |
If eucalyptus Hash is defined |
false |
Otherwise |
# File lib/ohai/plugins/cloud.rb, line 100 def on_eucalyptus? eucalyptus != nil end
Is current cloud rackspace?
true |
If rackspace Hash is defined |
false |
Otherwise |
# File lib/ohai/plugins/cloud.rb, line 70 def on_rackspace? rackspace != nil end
# File lib/ohai/plugins/windows/kernel.rb, line 29 def os_lookup(sys_type) return "Unknown" if sys_type.to_s.eql?("0") return "Other" if sys_type.to_s.eql?("1") return "MSDOS" if sys_type.to_s.eql?("14") return "WIN3x" if sys_type.to_s.eql?("15") return "WIN95" if sys_type.to_s.eql?("16") return "WIN98" if sys_type.to_s.eql?("17") return "WINNT" if sys_type.to_s.eql?("18") return "WINCE" if sys_type.to_s.eql?("19") return nil end
# File lib/ohai/plugins/darwin/network.rb, line 34 def parse_media(media_string) media = Hash.new line_array = media_string.split(' ') 0.upto(line_array.length - 1) do |i| unless line_array[i].eql?("none") if line_array[i + 1] =~ /^\<([a-zA-Z\-\,]+)\>$/ media[line_array[i]] = Hash.new unless media.has_key?(line_array[i]) if media[line_array[i]].has_key?("options") $1.split(",").each do |opt| media[line_array[i]]["options"] << opt unless media[line_array[i]]["options"].include?(opt) end else media[line_array[i]]["options"] = $1.split(",") end else if line_array[i].eql?("autoselect") media["autoselect"] = Hash.new unless media.has_key?("autoselect") media["autoselect"]["options"] = [] end end else media["none"] = { "options" => [] } end end media end
Generated with the Darkfish Rdoc Generator 2.