Top Level Namespace
- Extended by:
- Ohai::Mixin::Ec2Metadata
Defined Under Namespace
Modules: DMI, Ohai Classes: Mash, String
Constant Summary collapse
- IPROUTE_INT_REGEX =
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
/^(\d+): ([0-9a-zA-Z@:\.\-_]*?)(@[0-9a-zA-Z]+|):\s/
- SIGAR_ROUTE_METHODS =
From sigar: include/sigar.h sigar_net_route_t
[:destination, :gateway, :mask, :flags, :refcnt, :use, :metric, :mtu, :window, :irtt, :ifname]
Constants included from Ohai::Mixin::Ec2Metadata
Ohai::Mixin::Ec2Metadata::EC2_ARRAY_VALUES, Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, Ohai::Mixin::Ec2Metadata::EC2_METADATA_URL, Ohai::Mixin::Ec2Metadata::EC2_USERDATA_URL
Instance Method Summary collapse
-
#_seconds_to_human(seconds) ⇒ Object
- Author
- Adam Jacob (<[email protected]>) Copyright
-
Copyright © 2008 Opscode, Inc.
- #arpname_to_ifname(iface, arpname) ⇒ Object
-
#create_objects ⇒ Object
Make top-level cloud hashes.
- #encaps_lookup(ifname) ⇒ Object
- #excluded_setting?(setting) ⇒ Boolean
- #find_ip_and_mac(addresses, match = nil) ⇒ Object
- #fix_encoding(str) ⇒ Object
- #flags(flags) ⇒ Object
-
#get_ec2_values ⇒ Object
Fill cloud hash with ec2 values.
- #get_eucalyptus_values ⇒ Object
-
#get_ip_address(name, eth) ⇒ Object
Names rackspace ip address.
- #get_mac_address(addresses) ⇒ Object
-
#get_rackspace_values ⇒ Object
Fill cloud hash with rackspace values.
-
#get_redhatish_platform(contents) ⇒ Object
- Author
- Adam Jacob (<[email protected]>) Copyright
-
Copyright © 2008 Opscode, Inc.
- #get_redhatish_version(contents) ⇒ Object
- #has_ec2_mac? ⇒ Boolean
- #has_euca_mac? ⇒ Boolean
-
#has_rackspace_kernel? ⇒ Boolean
Checks for matching rackspace kernel name.
-
#has_rackspace_mac? ⇒ Boolean
Checks for matching rackspace arp mac.
- #locate_interface(ifaces, ifname, mac) ⇒ Object
- #looks_like_ec2? ⇒ Boolean
- #looks_like_euca? ⇒ Boolean
-
#looks_like_rackspace? ⇒ Boolean
Identifies the rackspace cloud.
- #machine_lookup(sys_type) ⇒ Object
- #network_contains_address(address_to_match, network_ip, network_opts) ⇒ Object
-
#on_ec2? ⇒ Boolean
Is current cloud ec2?.
-
#on_eucalyptus? ⇒ Boolean
Is current cloud eucalyptus?.
-
#on_rackspace? ⇒ Boolean
Is current cloud rackspace?.
- #os_lookup(sys_type) ⇒ Object
- #parse_media(media_string) ⇒ Object
- #run_ruby(command) ⇒ Object
- #scope_lookup(scope) ⇒ Object
Methods included from Ohai::Mixin::Ec2Metadata
can_metadata_connect?, fetch_metadata, fetch_userdata, http_client
Instance Method Details
#_seconds_to_human(seconds) ⇒ Object
- Author
-
Adam Jacob (<[email protected]>)
- Copyright
-
Copyright © 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.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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 |
#arpname_to_ifname(iface, arpname) ⇒ Object
67 68 69 70 71 72 73 |
# 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 |
#create_objects ⇒ Object
Make top-level cloud hashes
25 26 27 28 29 |
# 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 |
#encaps_lookup(ifname) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ohai/plugins/linux/network.rb', line 22 def 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") return "VJSLIP" if encap.eql?("VJ Serial Line IP") return "IPIP" if encap.eql?("IPIP Tunnel") return "6to4" if encap.eql?("IPv6-in-IPv4") return "Ethernet" if encap.eql?("ether") encap end |
#excluded_setting?(setting) ⇒ Boolean
80 81 82 |
# File 'lib/ohai/plugins/darwin/network.rb', line 80 def excluded_setting?(setting) setting.match('_sw_cksum') end |
#find_ip_and_mac(addresses, match = nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# 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 |
#fix_encoding(str) ⇒ Object
5 6 7 8 |
# 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 |
#flags(flags) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# 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 |
#get_ec2_values ⇒ Object
Fill cloud hash with ec2 values
45 46 47 48 49 50 51 52 53 |
# 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 |
#get_eucalyptus_values ⇒ Object
104 105 106 107 108 109 110 111 112 |
# 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 |
#get_ip_address(name, eth) ⇒ Object
Names rackspace ip address
Parameters
- name<Symbol>
-
Use :public_ip or :private_ip
- eth<Symbol>
-
Interface name of public or private ip
59 60 61 62 63 |
# 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 |
#get_mac_address(addresses) ⇒ Object
30 31 32 33 34 35 36 37 |
# 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 |
#get_rackspace_values ⇒ Object
Fill cloud hash with rackspace values
75 76 77 78 79 80 81 82 83 |
# 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 |
#get_redhatish_platform(contents) ⇒ Object
- Author
-
Adam Jacob (<[email protected]>)
- Copyright
-
Copyright © 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.
19 20 21 |
# File 'lib/ohai/plugins/linux/platform.rb', line 19 def get_redhatish_platform(contents) contents[/^Red Hat/i] ? "redhat" : contents[/(\w+)/i, 1].downcase end |
#get_redhatish_version(contents) ⇒ Object
23 24 25 |
# File 'lib/ohai/plugins/linux/platform.rb', line 23 def get_redhatish_version(contents) contents[/Rawhide/i] ? contents[/((\d+) \(Rawhide\))/i, 1].downcase : contents[/release ([\d\.]+)/, 1] end |
#has_ec2_mac? ⇒ Boolean
30 31 32 33 34 35 36 37 38 39 40 41 |
# 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 |
#has_euca_mac? ⇒ Boolean
39 40 41 42 43 44 45 46 47 48 |
# 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 |
#has_rackspace_kernel? ⇒ Boolean
Checks for matching rackspace kernel name
Return
- true
-
If kernel name matches
- false
-
Otherwise
27 28 29 |
# File 'lib/ohai/plugins/rackspace.rb', line 27 def has_rackspace_kernel? kernel[:release].split('-').last.eql?("rscloud") end |
#has_rackspace_mac? ⇒ Boolean
Checks for matching rackspace arp mac
Return
- true
-
If mac address matches
- false
-
Otherwise
36 37 38 39 40 41 42 43 |
# 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 |
#locate_interface(ifaces, ifname, mac) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# 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 |
#looks_like_ec2? ⇒ Boolean
43 44 45 46 47 |
# 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? && (EC2_METADATA_ADDR,80) end |
#looks_like_euca? ⇒ Boolean
50 51 52 53 54 |
# 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? && (EC2_METADATA_ADDR,80) end |
#looks_like_rackspace? ⇒ Boolean
Identifies the rackspace cloud
Return
- true
-
If the rackspace cloud can be identified
- false
-
Otherwise
50 51 52 |
# File 'lib/ohai/plugins/rackspace.rb', line 50 def looks_like_rackspace? hint?('rackspace') || has_rackspace_mac? || has_rackspace_kernel? end |
#machine_lookup(sys_type) ⇒ Object
23 24 25 26 27 |
# 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 |
#network_contains_address(address_to_match, network_ip, network_opts) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# 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 |
#on_ec2? ⇒ Boolean
Is current cloud ec2?
Return
- true
-
If ec2 Hash is defined
- false
-
Otherwise
40 41 42 |
# File 'lib/ohai/plugins/cloud.rb', line 40 def on_ec2? ec2 != nil end |
#on_eucalyptus? ⇒ Boolean
Is current cloud eucalyptus?
Return
- true
-
If eucalyptus Hash is defined
- false
-
Otherwise
100 101 102 |
# File 'lib/ohai/plugins/cloud.rb', line 100 def on_eucalyptus? eucalyptus != nil end |
#on_rackspace? ⇒ Boolean
Is current cloud rackspace?
Return
- true
-
If rackspace Hash is defined
- false
-
Otherwise
70 71 72 |
# File 'lib/ohai/plugins/cloud.rb', line 70 def on_rackspace? rackspace != nil end |
#os_lookup(sys_type) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# 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 |
#parse_media(media_string) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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 |
#run_ruby(command) ⇒ Object
24 25 26 27 28 |
# File 'lib/ohai/plugins/ruby.rb', line 24 def run_ruby(command) cmd = "ruby -e \"require 'rbconfig'; #{command}\"" status, stdout, stderr = run_command(:no_status_check => true, :command => cmd) stdout.strip end |
#scope_lookup(scope) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/ohai/plugins/darwin/network.rb', line 73 def scope_lookup(scope) return "Node" if scope.eql?("::1") return "Link" if scope.match(/^fe80\:/) return "Site" if scope.match(/^fec0\:/) "Global" end |