summaryrefslogtreecommitdiff
path: root/lib/ohai
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ohai')
-rw-r--r--lib/ohai/plugins/aix/hostname.rb21
-rw-r--r--lib/ohai/plugins/darwin/hostname.rb28
-rw-r--r--lib/ohai/plugins/freebsd/hostname.rb28
-rw-r--r--lib/ohai/plugins/hostname.rb86
-rw-r--r--lib/ohai/plugins/hpux/hostname.rb21
-rw-r--r--lib/ohai/plugins/linux/hostname.rb32
-rw-r--r--lib/ohai/plugins/netbsd/hostname.rb28
-rw-r--r--lib/ohai/plugins/openbsd/hostname.rb28
-rw-r--r--lib/ohai/plugins/sigar/hostname.rb32
-rw-r--r--lib/ohai/plugins/solaris2/hostname.rb45
-rw-r--r--lib/ohai/plugins/windows/hostname.rb39
11 files changed, 81 insertions, 307 deletions
diff --git a/lib/ohai/plugins/aix/hostname.rb b/lib/ohai/plugins/aix/hostname.rb
deleted file mode 100644
index e9b966ef..00000000
--- a/lib/ohai/plugins/aix/hostname.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-#
-# Author:: Doug MacEachern <dougm@vmware.com>
-# Copyright:: Copyright (c) 2010 VMware, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-Ohai.plugin do
- depends "sigar::hostname"
-end
diff --git a/lib/ohai/plugins/darwin/hostname.rb b/lib/ohai/plugins/darwin/hostname.rb
deleted file mode 100644
index 32726182..00000000
--- a/lib/ohai/plugins/darwin/hostname.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-Ohai.plugin do
- provides "fqdn", "hostname"
-
- collect_data do
- so = shell_out("hostname -s")
- hostname so.stdout.split($/)[0]
- so = shell_out("hostname")
- fqdn so.stdout.split($/)[0]
- end
-end
diff --git a/lib/ohai/plugins/freebsd/hostname.rb b/lib/ohai/plugins/freebsd/hostname.rb
deleted file mode 100644
index ba0a8bb7..00000000
--- a/lib/ohai/plugins/freebsd/hostname.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-# Author:: Bryan McLellan (btm@loftninjas.org)
-# Copyright:: Copyright (c) 2009 Bryan McLellan
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-Ohai.plugin do
- provides "hostname", "fqdn"
-
- collect_data do
- so = shell_out("hostname -s")
- hostname so.stdout.split($/)[0]
- so = shell_out("hostname -f")
- fqdn so.stdout.split($/)[0]
- end
-end
diff --git a/lib/ohai/plugins/hostname.rb b/lib/ohai/plugins/hostname.rb
index 0527ccac..9016ebf1 100644
--- a/lib/ohai/plugins/hostname.rb
+++ b/lib/ohai/plugins/hostname.rb
@@ -16,16 +16,92 @@
# limitations under the License.
#
-Ohai.plugin do
- provides "fqdn", "domain"
+Ohai.plugin(:Hostname) do
+ provides "domain", "hostname", "fqdn"
- depends_os "hostname"
+ def from_cmd(cmd)
+ so = shell_out(cmd)
+ so.stdout.split($/)[0]
+ end
- collect_data do
+ def collect_domain
# Domain is everything after the first dot
if fqdn
fqdn =~ /.+?\.(.*)/
- domain $1
+ domain $1
+ end
+ end
+
+ collect_data(:default) do
+ domain collect_domain
+ end
+
+ collect_data(:aix, :hpux, :sigar) do
+ require 'sigar'
+ sigar = Sigar.new
+ hostname sigar.net_info.host_name
+ fqdn sigar.fqdn
+ domain collect_domain
+ end
+
+ collect_data(:darwin, :netbsd, :openbsd) do
+ hostname from_cmd("hostname -s")
+ fqdn from_cmd("hostname")
+ domain collect_domain
+ end
+
+ collect_data(:freebsd) do
+ hostname from_cmd("hostname -s")
+ fqdn from_cmd("hostname -f")
+ domain collect_domain
+ end
+
+ collect_data(:linux) do
+ hostname from_cmd("hostname -s")
+ begin
+ fqdn from_cmd("hostname --fqdn")
+ rescue
+ Ohai::Log.debug("hostname -f returned an error, probably no domain is set")
end
+ domain collect_domain
+ end
+
+ collect_data(:solaris2) do
+ require 'socket'
+
+ hostname from_cmd("hostname")
+ fqdn_lookup = Socket.getaddrinfo(hostname, nil, nil, nil, nil, Socket::AI_CANONNAME).first[2]
+ if fqdn_lookup.split('.').length > 1
+ # we recieved an fqdn
+ fqdn fqdn_lookup
+ else
+ # default to assembling one
+ so = shell_out("hostname")
+ h = so.stdout.split($/)[0]
+ so = shell_out("domainname")
+ d = so.stdout.split($/)[0]
+
+ fqdn("#{h}.#{d}")
+ end
+ domain collect_domain
+ end
+
+ collect_data(:windows) do
+ require 'ruby-wmi'
+ require 'socket'
+
+ host = WMI::Win32_ComputerSystem.find(:first)
+ hostname "#{host.Name}"
+
+ info = Socket.gethostbyname(Socket.gethostname)
+ if info.first =~ /.+?\.(.*)/
+ fqdn info.first
+ else
+ #host is not in dns. optionally use:
+ #C:\WINDOWS\system32\drivers\etc\hosts
+ fqdn Socket.gethostbyaddr(info.last).first
+ end
+ domain collect_domain
end
end
+
diff --git a/lib/ohai/plugins/hpux/hostname.rb b/lib/ohai/plugins/hpux/hostname.rb
deleted file mode 100644
index e9b966ef..00000000
--- a/lib/ohai/plugins/hpux/hostname.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-#
-# Author:: Doug MacEachern <dougm@vmware.com>
-# Copyright:: Copyright (c) 2010 VMware, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-Ohai.plugin do
- depends "sigar::hostname"
-end
diff --git a/lib/ohai/plugins/linux/hostname.rb b/lib/ohai/plugins/linux/hostname.rb
deleted file mode 100644
index c3f2dc21..00000000
--- a/lib/ohai/plugins/linux/hostname.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-Ohai.plugin do
- provides "hostname", "fqdn"
-
- collect_data do
- so = shell_out("hostname -s")
- hostname so.stdout.split($/)[0]
- begin
- so = shell_out("hostname --fqdn")
- fqdn so.stdout.split($/)[0]
- rescue
- Ohai::Log.debug("hostname -f returned an error, probably no domain is set")
- end
- end
-end
diff --git a/lib/ohai/plugins/netbsd/hostname.rb b/lib/ohai/plugins/netbsd/hostname.rb
deleted file mode 100644
index 2a07bd76..00000000
--- a/lib/ohai/plugins/netbsd/hostname.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-# Author:: Bryan McLellan (btm@loftninjas.org)
-# Copyright:: Copyright (c) 2009 Bryan McLellan
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-Ohai.plugin do
- provides "hostname", "fqdn"
-
- collect_data do
- so = shell_out("hostname -s")
- hostname so.stdout.split($/)[0]
- so = shell_out("hostname")
- fqdn so.stdout.split($/)[0]
- end
-end
diff --git a/lib/ohai/plugins/openbsd/hostname.rb b/lib/ohai/plugins/openbsd/hostname.rb
deleted file mode 100644
index 2a07bd76..00000000
--- a/lib/ohai/plugins/openbsd/hostname.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-# Author:: Bryan McLellan (btm@loftninjas.org)
-# Copyright:: Copyright (c) 2009 Bryan McLellan
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-Ohai.plugin do
- provides "hostname", "fqdn"
-
- collect_data do
- so = shell_out("hostname -s")
- hostname so.stdout.split($/)[0]
- so = shell_out("hostname")
- fqdn so.stdout.split($/)[0]
- end
-end
diff --git a/lib/ohai/plugins/sigar/hostname.rb b/lib/ohai/plugins/sigar/hostname.rb
deleted file mode 100644
index e5d3a423..00000000
--- a/lib/ohai/plugins/sigar/hostname.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-#
-# Author:: Doug MacEachern <dougm@vmware.com>
-# Copyright:: Copyright (c) 2010 VMware, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'sigar'
-
-Ohai.plugin do
- provides "hostname", "fqdn"
-
- collect_data do
- sigar = Sigar.new
-
- hostname sigar.net_info.host_name
-
- fqdn sigar.fqdn
- end
-end
-
diff --git a/lib/ohai/plugins/solaris2/hostname.rb b/lib/ohai/plugins/solaris2/hostname.rb
deleted file mode 100644
index 6fea0f87..00000000
--- a/lib/ohai/plugins/solaris2/hostname.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-#
-# Author:: Benjamin Black (<nostromo@gmail.com>)
-# Author:: Daniel DeLeo <dan@kallistec.com>
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# Copyright:: Copyright (c) 2009 Daniel DeLeo
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'socket'
-
-Ohai.plugin do
- provides "hostname", "fqdn"
-
- collect_data do
- so = shell_out("hostname")
- hostname so.stdout.split($/)[0]
-
- fqdn_lookup = Socket.getaddrinfo(hostname, nil, nil, nil, nil, Socket::AI_CANONNAME).first[2]
-
- if fqdn_lookup.split('.').length > 1
- # we recieved an fqdn
- fqdn fqdn_lookup
- else
- # default to assembling one
- so = shell_out("hostname")
- h = so.stdout.split($/)[0]
- so = shell_out("domainname")
- d = so.stdout.split($/)[0]
-
- fqdn("#{h}.#{d}")
- end
- end
-end
diff --git a/lib/ohai/plugins/windows/hostname.rb b/lib/ohai/plugins/windows/hostname.rb
deleted file mode 100644
index 57fdfa0c..00000000
--- a/lib/ohai/plugins/windows/hostname.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-#
-# Author:: James Gartrell (<jgartrel@gmail.com>)
-# Copyright:: Copyright (c) 2009 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'ruby-wmi'
-require 'socket'
-
-Ohai.plugin do
- provides "hostname"
- provides "fqdn"
-
- collect_data do
- host = WMI::Win32_ComputerSystem.find(:first)
- hostname "#{host.Name}"
-
- info = Socket.gethostbyname(Socket.gethostname)
- if info.first =~ /.+?\.(.*)/
- fqdn info.first
- else
- #host is not in dns. optionally use:
- #C:\WINDOWS\system32\drivers\etc\hosts
- fqdn Socket.gethostbyaddr(info.last).first
- end
- end
-end