Sha256: 37ee152a2f6006987c1806a345cf24a5055cb92802c516fe609ac8e3d096d981

Contents?: true

Size: 820 Bytes

Versions: 24

Compression:

Stored size: 820 Bytes

Contents

module ForemanDiscovery
  class SubnetSuggestion
    attr_accessor :ip, :kind

    def self.for(ip:, kind:)
      new(ip: ip, kind: kind).()
    end

    def initialize(ip:, kind:)
      self.ip = ip
      self.kind = kind
    end

    def call
      return unless ip

      begin
        subnet = Subnet.unscoped.subnet_for(ip)
      rescue Exception => e
        Rails.logger.error "Error while detecting subnet for IP #{ip}"
        Foreman::Logging.exception "Unable to detect subnet", e
        subnet = nil
      end

      if subnet
        Rails.logger.info "Detected #{kind} subnet: #{subnet} with taxonomy #{subnet.organizations.collect(&:name)}/#{subnet.locations.collect(&:name)}"
      else
        Rails.logger.info "#{kind} subnet could not be detected for #{ip}"
      end
      subnet
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
foreman_discovery-25.0.0 app/services/foreman_discovery/subnet_suggestion.rb
foreman_discovery-24.0.2 app/services/foreman_discovery/subnet_suggestion.rb
foreman_discovery-23.0.2 app/services/foreman_discovery/subnet_suggestion.rb
foreman_discovery-24.0.1 app/services/foreman_discovery/subnet_suggestion.rb
foreman_discovery-24.0.0 app/services/foreman_discovery/subnet_suggestion.rb
foreman_discovery-23.0.1 app/services/foreman_discovery/subnet_suggestion.rb
foreman_discovery-23.0.0 app/services/foreman_discovery/subnet_suggestion.rb
foreman_discovery-22.0.4 app/services/foreman_discovery/subnet_suggestion.rb
foreman_discovery-21.0.5 app/services/foreman_discovery/subnet_suggestion.rb
foreman_discovery-22.0.2 app/services/foreman_discovery/subnet_suggestion.rb
foreman_discovery-21.0.4 app/services/foreman_discovery/subnet_suggestion.rb
foreman_discovery-21.0.3 app/services/foreman_discovery/subnet_suggestion.rb
foreman_discovery-21.0.2 app/services/foreman_discovery/subnet_suggestion.rb
foreman_discovery-19.0.5 app/services/foreman_discovery/subnet_suggestion.rb
foreman_discovery-19.0.4 app/services/foreman_discovery/subnet_suggestion.rb
foreman_discovery-21.0.1 app/services/foreman_discovery/subnet_suggestion.rb
foreman_discovery-19.0.3 app/services/foreman_discovery/subnet_suggestion.rb
foreman_discovery-21.0.0 app/services/foreman_discovery/subnet_suggestion.rb
foreman_discovery-19.0.2 app/services/foreman_discovery/subnet_suggestion.rb
foreman_discovery-20.0.1 app/services/foreman_discovery/subnet_suggestion.rb