Module: Ohai::Mixin::SoftlayerMetadata
- Defined in:
- lib/ohai/mixin/softlayer_metadata.rb
Overview
Instance Method Summary collapse
-
#ca_file_location ⇒ String
Softlayer’s metadata api is only available over HTTPS.
-
#fetch_metadata ⇒ Hash
fetch metadata items and build out hash of data.
-
#fetch_metadata_item(item) ⇒ String
fetch a specified item from the Softlayer metadata API.
Instance Method Details
#ca_file_location ⇒ String
Softlayer’s metadata api is only available over HTTPS. Ruby by default does not link to the system’s CA bundle however Chef-omnibus should set SSL_CERT_FILE to point to a valid file. Manually supply and specify a suitable CA bundle here or set the SSL_CERT_FILE file environment variable to a valid value otherwise.
48 49 50 |
# File 'lib/ohai/mixin/softlayer_metadata.rb', line 48 def ca_file_location ::Ohai::Config[:ca_file] end |
#fetch_metadata ⇒ Hash
fetch metadata items and build out hash of data
31 32 33 34 35 36 37 38 39 |
# File 'lib/ohai/mixin/softlayer_metadata.rb', line 31 def { "public_fqdn" => ("getFullyQualifiedDomainName.txt"), "local_ipv4" => ("getPrimaryBackendIpAddress.txt"), "public_ipv4" => ("getPrimaryIpAddress.txt"), "region" => ("getDatacenter.txt"), "instance_id" => ("getId.txt"), } end |
#fetch_metadata_item(item) ⇒ String
fetch a specified item from the Softlayer metadata API
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ohai/mixin/softlayer_metadata.rb', line 56 def (item) full_url = "#{SOFTLAYER_API_QUERY_URL}/#{item}" u = URI(full_url) net = ::Net::HTTP.new(u.hostname, u.port) net.ssl_version = :TLSv1_2 net.use_ssl = true net.ca_file = ca_file_location res = net.get(u.request_uri) if res.code.to_i.between?(200, 299) res.body else logger.error("Mixin Softlayer: Unable to fetch item #{full_url}: status (#{res.code}) body (#{res.body})") nil end rescue => e logger.error("Mixin Softlayer: Unable to fetch softlayer metadata from #{u}: #{e.class}: #{e.}") raise e end |