[PATCH/foreman 1/1] Fixes #1420 - bootserver ip lookup fails when not managing DNS

Signed-off-by: Paul Kelly <paul.ian.kelly@googlemail.com>

··· --- app/models/orchestration.rb | 8 ++++++++ app/models/orchestration/dhcp.rb | 2 +- lib/proxy_api.rb | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/app/models/orchestration.rb b/app/models/orchestration.rb
index 5d4d0b3…8331e41 100644
— a/app/models/orchestration.rb
+++ b/app/models/orchestration.rb
@@ -163,5 +163,13 @@ module Orchestration
end
end

  • Ensure that the bootserver is in IP format and not a hostname

  • We can reuse the DNS subsystem, if we are managing it

  • def bootserver_ip name_or_ip
  •  return name_or_ip if name_or_ip =~ /^\d/
    
  •  return dns_ptr_record.dns_lookup(name_or_ip).ip if dns_ptr_record
    
  •  # Looks like we are managing DHCP but not DNS
    
  •  domain.resolver.getaddress(name_or_ip).to_s
    
  • end
    end
    end
    diff --git a/app/models/orchestration/dhcp.rb b/app/models/orchestration/dhcp.rb
    index ac07ad3…05b822d 100644
    — a/app/models/orchestration/dhcp.rb
    +++ b/app/models/orchestration/dhcp.rb
    @@ -77,7 +77,7 @@ module Orchestration::DHCP
    # trying to guess out tftp next server based on the smart proxy hostname
    bs = URI.parse(subnet.tftp.url).host if respond_to?(:tftp?) and tftp?
    end
  •  return(bs =~/^\d/ ? bs : dns_ptr_record.dns_lookup(bs).ip) unless bs.blank?
    
  •  return(bootserver_ip(bs)) unless bs.blank?
     failure "Unable to determine the host's boot server. The DHCP smart proxy failed to provide this information and this subnet is not provided with TFTP services."
    
    rescue => e
    failure "failed to detect boot server: #{e}"
    diff --git a/lib/proxy_api.rb b/lib/proxy_api.rb
    index 359df94…cd7c91d 100644
    — a/lib/proxy_api.rb
    +++ b/lib/proxy_api.rb
    @@ -249,7 +249,7 @@ module ProxyAPI
    def bootServer
    response = parse get(“serverName”)
    if response and response[“serverName”] and !response[“serverName”].blank?
  •    return(response["serverName"] =~ /^\d/ ? response["serverName"] : dns_ptr_record.dns_lookup(response["serverName"]).ip)
    
  •    return(bootserver_ip response["serverName"] )
     end
     false
    
    rescue RestClient::ResourceNotFound

    1.7.5.4