summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOhad Levy <ohad.levy@infineon.com>2010-01-18 10:42:43 +0800
committerPaul Nasrat <pnasrat@googlemail.com>2010-03-08 22:36:01 +0000
commitdca615c98b864d75e2ac5899d98d04a2bd979eba (patch)
tree115c4ac2454d5843a59331380ff37f0f8dac7867
parent86447c884a47948a4ef6757ff7e7d2e0faf93ff5 (diff)
downloadfacter-dca615c98b864d75e2ac5899d98d04a2bd979eba.tar.gz
facter-dca615c98b864d75e2ac5899d98d04a2bd979eba.tar.xz
facter-dca615c98b864d75e2ac5899d98d04a2bd979eba.zip
fixes #2573, #2085, #1291 - fixes domain and fqdn facts resolution
This patch removes the relationship between the domain fact and LDAP/NIS domains. domain fact relates to DNS domain - this will avoid the confusion caused by the LDAP/NIS domain (which might be different to the DNS domain name). Additionally, if hostname is already in long form, it won't try to build the fqdn fact from hostname and domain.
-rw-r--r--lib/facter/domain.rb8
-rw-r--r--lib/facter/fqdn.rb4
-rw-r--r--lib/facter/hostname.rb7
3 files changed, 12 insertions, 7 deletions
diff --git a/lib/facter/domain.rb b/lib/facter/domain.rb
index b1bba4d..5dfead0 100644
--- a/lib/facter/domain.rb
+++ b/lib/facter/domain.rb
@@ -4,14 +4,14 @@ Facter.add(:domain) do
# steps is important
Facter.value(:hostname)
- next $domain if defined? $domain and ! $domain.nil?
+ # try to fetch the domain from hostname if long hostname is used.
+ if defined? $fqdn and $fqdn =~ /^([\w-]+)\.(.+)$/
+ next $2
+ end
domain = Facter::Util::Resolution.exec('dnsdomainname')
next domain if domain =~ /.+\..+/
- domain = Facter::Util::Resolution.exec('domainname')
- next domain if domain =~ /.+\..+/
-
if FileTest.exists?("/etc/resolv.conf")
domain = nil
search = nil
diff --git a/lib/facter/fqdn.rb b/lib/facter/fqdn.rb
index 5ebc5f5..6271995 100644
--- a/lib/facter/fqdn.rb
+++ b/lib/facter/fqdn.rb
@@ -1,5 +1,9 @@
Facter.add(:fqdn) do
setcode do
+ # try to fetch the fqdn from hostname if long hostname is used.
+ Facter.value(:hostname)
+ next $fqdn if defined? $fqdn and ! $fqdn.nil?
+
host = Facter.value(:hostname)
domain = Facter.value(:domain)
if host and domain
diff --git a/lib/facter/hostname.rb b/lib/facter/hostname.rb
index 188efa4..c3ca968 100644
--- a/lib/facter/hostname.rb
+++ b/lib/facter/hostname.rb
@@ -1,12 +1,13 @@
Facter.add(:hostname, :ldapname => "cn") do
setcode do
+ require 'socket'
hostname = nil
- name = Facter::Util::Resolution.exec('hostname') or nil
+ name = Socket.gethostbyname(Socket.gethostname).first
if name
if name =~ /^([\w-]+)\.(.+)$/
hostname = $1
- # the Domain class uses this
- $domain = $2
+ # the FQDN/Domain facts use this
+ $fqdn = name
else
hostname = name
end