Sha256: ea20bb1646e298b00445e30efec8c02b85c4ce875ab9923b30778087d55a7ceb
Contents?: true
Size: 1.84 KB
Versions: 7
Compression:
Stored size: 1.84 KB
Contents
module Cloud66 module Utils class VitalSigns def self.system_info # system info return parse_data(`facter`) end def self.address_info # address information hash = parse_data(`facter ipaddress ipaddress_eth0 ipaddress6 ipaddress6_eth0`) result = {} # AWS special case if $config.is_aws reported_ip = `/usr/bin/curl -s http://169.254.169.254/latest/meta-data/public-ipv4` result[:ext_ipv4] = reported_ip if reported_ip =~ /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ else # set general external ip address result[:ext_ipv4] = hash['ipaddress'] end result[:int_ipv4] = hash['ipaddress_eth0'] if hash.has_key?('ipaddress_eth0') result[:ext_ipv6] = hash['ipaddress6'] if hash.has_key?('ipaddress6') result[:int_ipv6] = hash['ipaddress6_eth0'] if hash.has_key?('ipaddress6_eth0') # don't have any ip address info raise 'no address information' if result.empty? || !result.has_key?(:ext_ipv4) # return ip address info return result end def self.is_aws? # 6 seconds to find out if this is a AWS image or not! instance = `/usr/bin/curl --connect-timeout 6 -s http://169.254.169.254/latest/meta-data/instance-id` rescue nil return !instance.nil? && !instance.empty? end private # parse the data, not using YAML due to YAML parsing issues and JSON output not always working def self.parse_data(data) hash = {} data.lines.each do |line| split = line.split('=>') key = split[0] if split.size == 2 value = split[1] unless value.nil? value = value.strip # exclude empty or long results (like ssh keys) if !value.empty? && value.size < 100 key = key.strip hash[key] = value end end end end return hash end end end end
Version data entries
7 entries across 7 versions & 1 rubygems