class CloudAttrs
Class to help enforce the interface exposed to node (OHAI-542)
cloud - (String
) the cloud provider the VM is running on.
cloud - (String
) a fully qualified hostname cloud - (String
) a hostname resolvable on the internal (private) network
cloud - (Array) a list of all publicly accessible IPv4 addresses cloud - (Array) a list of all private IPv4 addresses cloud - (String
) the first public IPv4 address detected cloud - (String
) the first private IPv4 address detected
cloud - (Array) a list of all publicly accessible IPv6 addresses cloud - (Array) a list of all private IPv6 addresses cloud - (String
) the first public IPv6 address detected cloud - (String
) the first private IPv6 address detected
Attributes
local_hostname[W]
provider[W]
public_hostname[W]
Public Class Methods
new()
click to toggle source
# File lib/ohai/plugins/cloud.rb, line 52 def initialize @cloud = Mash.new end
Public Instance Methods
add_ipv4_addr(ip, accessibility)
click to toggle source
# File lib/ohai/plugins/cloud.rb, line 56 def add_ipv4_addr(ip, accessibility) return if ip.nil? # just skip if ip is nil ipaddr = validate_ip_addr(ip, :ipv4) case accessibility when :public @cloud[:public_ipv4_addrs] ||= [] @cloud[:public_ipv4_addrs] << ipaddr.to_s when :private @cloud[:local_ipv4_addrs] ||= [] @cloud[:local_ipv4_addrs] << ipaddr.to_s else raise "ERROR: invalid accessibility param of '#{accessibility}'. must be :public or :private." end end
add_ipv6_addr(ip, accessibility)
click to toggle source
# File lib/ohai/plugins/cloud.rb, line 73 def add_ipv6_addr(ip, accessibility) return if ip.nil? # just skip if ip is nil ipaddr = validate_ip_addr(ip, :ipv6) raise "ERROR: invalid ipv6 address of '#{ip}' detected. " unless ipaddr.ipv6? case accessibility when :public @cloud[:public_ipv6_addrs] ||= [] @cloud[:public_ipv6_addrs] << ipaddr.to_s when :private @cloud[:local_ipv6_addrs] ||= [] @cloud[:local_ipv6_addrs] << ipaddr.to_s else raise "ERROR: invalid accessibility param of '#{accessibility}'. must be :public or :private." end end
cloud_mash()
click to toggle source
# File lib/ohai/plugins/cloud.rb, line 92 def cloud_mash @cloud[:provider] = @provider if @provider @cloud[:public_hostname] = @public_hostname if @public_hostname @cloud[:local_hostname] = @local_hostname if @local_hostname @cloud[:public_ipv4] = @cloud[:public_ipv4_addrs][0] if @cloud[:public_ipv4_addrs] @cloud[:local_ipv4] = @cloud[:local_ipv4_addrs][0] if @cloud[:local_ipv4_addrs] @cloud[:public_ipv6] = @cloud[:public_ipv6_addrs][0] if @cloud[:public_ipv6_addrs] @cloud[:local_ipv6] = @cloud[:local_ipv6_addrs][0] if @cloud[:local_ipv6_addrs] # if empty, return nil @cloud.empty? ? nil : @cloud end
Private Instance Methods
validate_ip_addr(ip, address_family = :ipv4)
click to toggle source
# File lib/ohai/plugins/cloud.rb, line 110 def validate_ip_addr(ip, address_family = :ipv4) ipaddr = "" begin ipaddr = IPAddr.new(ip) raise ArgumentError, "not valid #{address_family} address" unless address_family == :ipv4 ? ipaddr.ipv4? : ipaddr.ipv6? rescue ArgumentError => e raise "ERROR: the ohai 'cloud' plugin failed with an IP address of '#{ip}' : #{e.message}" end ipaddr end