Module: Ohai::Mixin::OCIMetadata
- Defined in:
- lib/ohai/mixin/oci_metadata.rb
Constant Summary collapse
- OCI_METADATA_ADDR =
"169.254.169.254"- OCI_METADATA_URL =
"/opc/v2"- CHASSIS_ASSET_TAG_FILE =
"/sys/devices/virtual/dmi/id/chassis_asset_tag"
Instance Method Summary collapse
-
#chassis_asset_tag ⇒ Object
Get the chassis asset tag from DMI information On Linux: reads from sysfs On Windows: queries WMI Win32_SystemEnclosure.
-
#fetch_metadata(metadata = "instance") ⇒ Object
Fetch metadata from api.
-
#get_chassis_asset_tag_linux ⇒ Object
Read chassis asset tag from Linux sysfs.
-
#get_chassis_asset_tag_windows ⇒ Object
Read chassis asset tag from Windows WMI.
-
#http_get(uri) ⇒ Object
fetch the meta content with a timeout and the required header.
Instance Method Details
#chassis_asset_tag ⇒ Object
Get the chassis asset tag from DMI information On Linux: reads from sysfs On Windows: queries WMI Win32_SystemEnclosure
34 35 36 37 38 39 40 |
# File 'lib/ohai/mixin/oci_metadata.rb', line 34 def chassis_asset_tag if RUBY_PLATFORM =~ /mswin|mingw|windows/ get_chassis_asset_tag_windows else get_chassis_asset_tag_linux end end |
#fetch_metadata(metadata = "instance") ⇒ Object
Fetch metadata from api
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ohai/mixin/oci_metadata.rb', line 78 def ( = "instance") response = http_get("#{OCI_METADATA_URL}/#{}") if response.code == "200" json_data = parse_json(response.body) if json_data.nil? logger.warn("Mixin OciMetadata: Metadata response is NOT valid JSON") end json_data else logger.debug("Mixin OciMetadata: Received response code #{response.code} requesting #{}") nil end end |
#get_chassis_asset_tag_linux ⇒ Object
Read chassis asset tag from Linux sysfs
43 44 45 46 47 48 49 50 |
# File 'lib/ohai/mixin/oci_metadata.rb', line 43 def get_chassis_asset_tag_linux return unless ::File.exist?(CHASSIS_ASSET_TAG_FILE) ::File.read(CHASSIS_ASSET_TAG_FILE).strip rescue => e logger.debug("Mixin OciMetadata: Failed to read chassis asset tag from #{CHASSIS_ASSET_TAG_FILE}: #{e}") nil end |
#get_chassis_asset_tag_windows ⇒ Object
Read chassis asset tag from Windows WMI
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ohai/mixin/oci_metadata.rb', line 53 def get_chassis_asset_tag_windows require "wmi-lite/wmi" unless defined?(WmiLite::Wmi) wmi = WmiLite::Wmi.new enclosure = wmi.first_of("Win32_SystemEnclosure") enclosure&.[]("SMBIOSAssetTag") rescue => e logger.debug("Mixin OciMetadata: Failed to read chassis asset tag from WMI: #{e}") nil end |
#http_get(uri) ⇒ Object
fetch the meta content with a timeout and the required header
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ohai/mixin/oci_metadata.rb', line 65 def http_get(uri) conn = Net::HTTP.start(OCI_METADATA_ADDR) conn.read_timeout = 6 conn.get( uri, { "Authorization" => "Bearer Oracle", "User-Agent" => "chef-ohai/#{Ohai::VERSION}", } ) end |