Sha256: c09b65d7a90bbda840df5659f8004f07e9dfd3dac362b4b503dd734d568c42f1

Contents?: true

Size: 1.92 KB

Versions: 21

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true
#
# Author:: Jonathan Amiez (<jonathan.amiez@gmail.com>)
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Ohai.plugin(:Scaleway) do
  require_relative "../mixin/scaleway_metadata"
  require_relative "../mixin/http_helper"

  include Ohai::Mixin::ScalewayMetadata
  include Ohai::Mixin::HttpHelper

  provides "scaleway"

  # looks for `scaleway` keyword in kernel command line
  # @return [Boolean] do we have the keyword or not?
  def has_scaleway_cmdline?
    if file_exist?("/proc/cmdline") && /scaleway/.match?(file_read("/proc/cmdline"))
      logger.trace("Plugin Scaleway: has_scaleway_cmdline? == true")
      return true
    end
    logger.trace("Plugin Scaleway: has_scaleway_cmdline? == false")
    false
  end

  # a single check that combines all the various detection methods for Scaleway
  # @return [Boolean] Does the system appear to be on Scaleway
  def looks_like_scaleway?
    return true if hint?("scaleway")
    return true if has_scaleway_cmdline? && can_socket_connect?(Ohai::Mixin::ScalewayMetadata::SCALEWAY_METADATA_ADDR, 80)

    false
  end

  collect_data(:linux) do
    if looks_like_scaleway?
      logger.trace("Plugin Scaleway: looks_like_scaleway? == true")
      scaleway Mash.new
      fetch_metadata.each do |k, v|
        scaleway[k] = v
      end
    else
      logger.trace("Plugin Scaleway: No hints present for and doesn't look like scaleway")
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
ohai-17.9.4 lib/ohai/plugins/scaleway.rb
ohai-17.9.1 lib/ohai/plugins/scaleway.rb
ohai-16.17.2 lib/ohai/plugins/scaleway.rb
ohai-18.0.14 lib/ohai/plugins/scaleway.rb
ohai-17.9.0 lib/ohai/plugins/scaleway.rb
ohai-17.7.12 lib/ohai/plugins/scaleway.rb
ohai-16.17.0 lib/ohai/plugins/scaleway.rb
ohai-17.7.8 lib/ohai/plugins/scaleway.rb
ohai-17.7.5 lib/ohai/plugins/scaleway.rb
ohai-17.6.0 lib/ohai/plugins/scaleway.rb
ohai-17.5.2 lib/ohai/plugins/scaleway.rb
ohai-17.3.1 lib/ohai/plugins/scaleway.rb
ohai-17.1.0 lib/ohai/plugins/scaleway.rb
ohai-17.0.42 lib/ohai/plugins/scaleway.rb
ohai-16.13.0 lib/ohai/plugins/scaleway.rb
ohai-16.12.3 lib/ohai/plugins/scaleway.rb
ohai-16.10.7 lib/ohai/plugins/scaleway.rb
ohai-16.10.6 lib/ohai/plugins/scaleway.rb
ohai-16.10.4 lib/ohai/plugins/scaleway.rb
ohai-16.8.1 lib/ohai/plugins/scaleway.rb