Class: Cloud66::Utils::VitalSigns
- Inherits:
-
Object
- Object
- Cloud66::Utils::VitalSigns
- Defined in:
- lib/cloud66_agent/utils/vital_signs.rb
Constant Summary collapse
- IP_BLOCK_REGEX =
/\d{,2}|1\d{2}|2[0-4]\d|25[0-5]/- IP_REGEX =
/\A#{IP_BLOCK_REGEX}\.#{IP_BLOCK_REGEX}\.#{IP_BLOCK_REGEX}\.#{IP_BLOCK_REGEX}\z/
Class Method Summary collapse
Class Method Details
.address_info ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cloud66_agent/utils/vital_signs.rb', line 13 def self.address_info 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]?)$/ reported_ip = `/usr/bin/curl -s http://169.254.169.254/latest/meta-data/local-ipv4` result[:int_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]?)$/ # GC special case elsif $config.is_gc external_ip = `/usr/bin/curl -s -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip` result[:ext_ipv4] = external_ip if external_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]?)$/ internal_ip = `/usr/bin/curl -s -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/network-interfaces/0/ip` result[:int_ipv4] = internal_ip if internal_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 interfaces_raw = `facter interfaces`.strip interfaces = interfaces_raw.split(',').select { |interface| interface !~ /^lo/ } # don't have any ip address info unless interfaces.empty? # return all interface information facter_command = "facter #{interfaces.map { |interface| "ipaddress_#{interface} ipaddress6_#{interface}" }.join(' ')}" raw_data = `#{facter_command}`.strip result = parse_data(raw_data) rescue {} end end normalised_hash = {} result.each do |key, value| if value =~ IP_REGEX && value != '127.0.0.1' && value != '127.0.1.1' normalised_hash[key] = value end end return normalised_hash end |
.is_aws? ⇒ Boolean
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cloud66_agent/utils/vital_signs.rb', line 47 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 false if instance.nil? || instance.empty? # now check the external ip to make sure we're not just being routed reported_ip = `/usr/bin/curl -s http://169.254.169.254/latest/meta-data/public-ipv4` rescue nil return false if reported_ip.nil? || reported_ip.empty? return false unless 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]?)$/ # it is aws return true rescue => exc return false end |
.is_gc? ⇒ Boolean
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/cloud66_agent/utils/vital_signs.rb', line 63 def self.is_gc? # 6 seconds to find out if this is a AWS image or not! external_ip = `/usr/bin/curl --connect-timeout 6 -s -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip` rescue nil return false if external_ip.nil? || external_ip.empty? return false unless external_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]?)$/ # it is google cloud return true rescue => exc return false end |
.system_info ⇒ Object
8 9 10 11 |
# File 'lib/cloud66_agent/utils/vital_signs.rb', line 8 def self.system_info # system info return parse_data(`facter`) end |