Sha256: a42d16875ece6411aef8c981b0f1d110c182bd21da3e67ef15da9d3d2ededd41

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

module PuppetFactParserExtensions
  extend ActiveSupport::Concern

  included do
    alias_method_chain :primary_interface, :discovery_fact
    alias_method_chain :ip, :discovery_fact
  end

  # we prefer discovery_bootif fact to choose right primary interface (interface used to boot the image)
  def primary_interface_with_discovery_fact
    mac = facts[discovery_mac_fact_name]
    interfaces.each do |int, values|
      return int.to_s if (values[:macaddress] == mac)
    end
    primary_interface_without_discovery_fact # fallback if we didn't find interface with such macaddress
  end

  # search for IP of interface with primary interface macaddress (ipaddress fact does not have to be interface used for boot)
  def ip_with_discovery_fact
    facts[:interfaces].split(',').each do |interface|
      return facts["ipaddress_#{interface}"] if facts["macaddress_#{interface}"] == facts[discovery_mac_fact_name]
    end
    ip_without_discovery_fact # fallback if IP was not found
  end

  private

  def discovery_mac_fact_name
    Setting[:discovery_fact] || 'macaddress'
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
foreman_discovery-1.4.0.rc3 app/lib/puppet_fact_parser_extensions.rb
foreman_discovery-1.4.0.rc2 app/lib/puppet_fact_parser_extensions.rb