Class: ForemanDiscovery::SubnetSuggestion
- Inherits:
-
Object
- Object
- ForemanDiscovery::SubnetSuggestion
- Defined in:
- app/services/foreman_discovery/subnet_suggestion.rb
Instance Attribute Summary collapse
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#kind ⇒ Object
Returns the value of attribute kind.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(ip:, kind:) ⇒ SubnetSuggestion
constructor
A new instance of SubnetSuggestion.
Constructor Details
#initialize(ip:, kind:) ⇒ SubnetSuggestion
Returns a new instance of SubnetSuggestion.
9 10 11 12 |
# File 'app/services/foreman_discovery/subnet_suggestion.rb', line 9 def initialize(ip:, kind:) self.ip = ip self.kind = kind end |
Instance Attribute Details
#ip ⇒ Object
Returns the value of attribute ip.
3 4 5 |
# File 'app/services/foreman_discovery/subnet_suggestion.rb', line 3 def ip @ip end |
#kind ⇒ Object
Returns the value of attribute kind.
3 4 5 |
# File 'app/services/foreman_discovery/subnet_suggestion.rb', line 3 def kind @kind end |
Class Method Details
.for(ip:, kind:) ⇒ Object
5 6 7 |
# File 'app/services/foreman_discovery/subnet_suggestion.rb', line 5 def self.for(ip:, kind:) new(ip: ip, kind: kind).() end |
Instance Method Details
#call ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/services/foreman_discovery/subnet_suggestion.rb', line 14 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 |