summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaire McQuin <claire@opscode.com>2013-10-17 12:57:08 -0700
committerClaire McQuin <claire@opscode.com>2013-10-17 12:57:08 -0700
commit7a87dcdb0ee61f66ef70e1ad0d943d774f360b6d (patch)
treeec4927cc332695f1e1adc3015b3e5bfb3658aaca
parent37b5fea4193ceae07f52a6e0ff1ea63cb4e760b1 (diff)
parent513f4bf8886a48d849551a509ef32d72af4c91c6 (diff)
downloadohai-7a87dcdb0ee61f66ef70e1ad0d943d774f360b6d.tar.gz
Merge pull request #208 from opscode/OC-9409
Add platform option to collect_data
-rw-r--r--Gemfile4
-rw-r--r--lib/ohai/common/dmi.rb126
-rw-r--r--lib/ohai/dsl/plugin.rb146
-rw-r--r--lib/ohai/loader.rb12
-rw-r--r--lib/ohai/mixin/os.rb59
-rw-r--r--lib/ohai/os.rb71
-rw-r--r--lib/ohai/plugins/aix/cpu.rb21
-rw-r--r--lib/ohai/plugins/aix/filesystem.rb21
-rw-r--r--lib/ohai/plugins/aix/hostname.rb21
-rw-r--r--lib/ohai/plugins/aix/memory.rb21
-rw-r--r--lib/ohai/plugins/aix/network.rb21
-rw-r--r--lib/ohai/plugins/aix/platform.rb21
-rw-r--r--lib/ohai/plugins/aix/uptime.rb21
-rw-r--r--lib/ohai/plugins/azure.rb2
-rw-r--r--lib/ohai/plugins/c.rb2
-rw-r--r--lib/ohai/plugins/chef.rb14
-rw-r--r--lib/ohai/plugins/cloud.rb2
-rw-r--r--lib/ohai/plugins/command.rb2
-rw-r--r--lib/ohai/plugins/darwin/cpu.rb4
-rw-r--r--lib/ohai/plugins/darwin/filesystem.rb4
-rw-r--r--lib/ohai/plugins/darwin/hostname.rb28
-rw-r--r--lib/ohai/plugins/darwin/kernel.rb41
-rw-r--r--lib/ohai/plugins/darwin/network.rb11
-rw-r--r--lib/ohai/plugins/darwin/platform.rb4
-rw-r--r--lib/ohai/plugins/darwin/ps.rb27
-rw-r--r--lib/ohai/plugins/darwin/system_profiler.rb4
-rw-r--r--lib/ohai/plugins/darwin/uptime.rb33
-rw-r--r--lib/ohai/plugins/dmi.rb11
-rw-r--r--lib/ohai/plugins/dmi_common.rb121
-rw-r--r--lib/ohai/plugins/ec2.rb8
-rw-r--r--lib/ohai/plugins/erlang.rb2
-rw-r--r--lib/ohai/plugins/eucalyptus.rb6
-rw-r--r--lib/ohai/plugins/freebsd/cpu.rb4
-rw-r--r--lib/ohai/plugins/freebsd/filesystem.rb4
-rw-r--r--lib/ohai/plugins/freebsd/hostname.rb28
-rw-r--r--lib/ohai/plugins/freebsd/kernel.rb40
-rw-r--r--lib/ohai/plugins/freebsd/memory.rb6
-rw-r--r--lib/ohai/plugins/freebsd/network.rb7
-rw-r--r--lib/ohai/plugins/freebsd/platform.rb7
-rw-r--r--lib/ohai/plugins/freebsd/ps.rb28
-rw-r--r--lib/ohai/plugins/freebsd/uptime.rb33
-rw-r--r--lib/ohai/plugins/freebsd/virtualization.rb4
-rw-r--r--lib/ohai/plugins/gce.rb7
-rw-r--r--lib/ohai/plugins/groovy.rb2
-rw-r--r--lib/ohai/plugins/hostname.rb96
-rw-r--r--lib/ohai/plugins/hpux/cpu.rb21
-rw-r--r--lib/ohai/plugins/hpux/filesystem.rb21
-rw-r--r--lib/ohai/plugins/hpux/hostname.rb21
-rw-r--r--lib/ohai/plugins/hpux/memory.rb21
-rw-r--r--lib/ohai/plugins/hpux/network.rb21
-rw-r--r--lib/ohai/plugins/hpux/platform.rb21
-rw-r--r--lib/ohai/plugins/hpux/ps.rb27
-rw-r--r--lib/ohai/plugins/hpux/uptime.rb21
-rw-r--r--lib/ohai/plugins/ip_scopes.rb5
-rw-r--r--lib/ohai/plugins/java.rb2
-rw-r--r--lib/ohai/plugins/kernel.rb203
-rw-r--r--lib/ohai/plugins/keys.rb2
-rw-r--r--lib/ohai/plugins/languages.rb2
-rw-r--r--lib/ohai/plugins/linode.rb4
-rw-r--r--lib/ohai/plugins/linux/block_device.rb4
-rw-r--r--lib/ohai/plugins/linux/cpu.rb4
-rw-r--r--lib/ohai/plugins/linux/filesystem.rb4
-rw-r--r--lib/ohai/plugins/linux/hostname.rb32
-rw-r--r--lib/ohai/plugins/linux/kernel.rb36
-rw-r--r--lib/ohai/plugins/linux/lsb.rb4
-rw-r--r--lib/ohai/plugins/linux/memory.rb6
-rw-r--r--lib/ohai/plugins/linux/network.rb9
-rw-r--r--lib/ohai/plugins/linux/platform.rb7
-rw-r--r--lib/ohai/plugins/linux/ps.rb27
-rw-r--r--lib/ohai/plugins/linux/uptime.rb29
-rw-r--r--lib/ohai/plugins/linux/virtualization.rb4
-rw-r--r--lib/ohai/plugins/lua.rb2
-rw-r--r--lib/ohai/plugins/mono.rb2
-rw-r--r--lib/ohai/plugins/netbsd/cpu.rb4
-rw-r--r--lib/ohai/plugins/netbsd/filesystem.rb4
-rw-r--r--lib/ohai/plugins/netbsd/hostname.rb28
-rw-r--r--lib/ohai/plugins/netbsd/kernel.rb39
-rw-r--r--lib/ohai/plugins/netbsd/memory.rb4
-rw-r--r--lib/ohai/plugins/netbsd/network.rb7
-rw-r--r--lib/ohai/plugins/netbsd/platform.rb7
-rw-r--r--lib/ohai/plugins/netbsd/ps.rb28
-rw-r--r--lib/ohai/plugins/netbsd/uptime.rb33
-rw-r--r--lib/ohai/plugins/netbsd/virtualization.rb4
-rw-r--r--lib/ohai/plugins/network.rb6
-rw-r--r--lib/ohai/plugins/network_listeners.rb9
-rw-r--r--lib/ohai/plugins/nodejs.rb2
-rw-r--r--lib/ohai/plugins/ohai.rb16
-rw-r--r--lib/ohai/plugins/ohai_time.rb2
-rw-r--r--lib/ohai/plugins/openbsd/cpu.rb4
-rw-r--r--lib/ohai/plugins/openbsd/filesystem.rb4
-rw-r--r--lib/ohai/plugins/openbsd/hostname.rb28
-rw-r--r--lib/ohai/plugins/openbsd/kernel.rb40
-rw-r--r--lib/ohai/plugins/openbsd/memory.rb6
-rw-r--r--lib/ohai/plugins/openbsd/network.rb7
-rw-r--r--lib/ohai/plugins/openbsd/platform.rb7
-rw-r--r--lib/ohai/plugins/openbsd/ps.rb28
-rw-r--r--lib/ohai/plugins/openbsd/uptime.rb33
-rw-r--r--lib/ohai/plugins/openbsd/virtualization.rb4
-rw-r--r--lib/ohai/plugins/openstack.rb2
-rw-r--r--lib/ohai/plugins/os.rb4
-rw-r--r--lib/ohai/plugins/passwd.rb2
-rw-r--r--lib/ohai/plugins/perl.rb2
-rw-r--r--lib/ohai/plugins/php.rb2
-rw-r--r--lib/ohai/plugins/platform.rb9
-rw-r--r--lib/ohai/plugins/ps.rb (renamed from lib/ohai/plugins/aix/ps.rb)17
-rw-r--r--lib/ohai/plugins/python.rb2
-rw-r--r--lib/ohai/plugins/rackspace.rb5
-rw-r--r--lib/ohai/plugins/root_group.rb2
-rw-r--r--lib/ohai/plugins/ruby.rb2
-rw-r--r--lib/ohai/plugins/sigar/cpu.rb8
-rw-r--r--lib/ohai/plugins/sigar/filesystem.rb11
-rw-r--r--lib/ohai/plugins/sigar/hostname.rb32
-rw-r--r--lib/ohai/plugins/sigar/memory.rb7
-rw-r--r--lib/ohai/plugins/sigar/network.rb103
-rw-r--r--lib/ohai/plugins/sigar/network_route.rb11
-rw-r--r--lib/ohai/plugins/sigar/platform.rb10
-rw-r--r--lib/ohai/plugins/sigar/uptime.rb30
-rw-r--r--lib/ohai/plugins/solaris2/cpu.rb4
-rw-r--r--lib/ohai/plugins/solaris2/dmi.rb4
-rw-r--r--lib/ohai/plugins/solaris2/filesystem.rb4
-rw-r--r--lib/ohai/plugins/solaris2/hostname.rb45
-rw-r--r--lib/ohai/plugins/solaris2/kernel.rb41
-rw-r--r--lib/ohai/plugins/solaris2/memory.rb4
-rw-r--r--lib/ohai/plugins/solaris2/network.rb11
-rw-r--r--lib/ohai/plugins/solaris2/platform.rb8
-rw-r--r--lib/ohai/plugins/solaris2/ps.rb27
-rw-r--r--lib/ohai/plugins/solaris2/uptime.rb38
-rw-r--r--lib/ohai/plugins/solaris2/virtualization.rb4
-rw-r--r--lib/ohai/plugins/solaris2/zpools.rb4
-rw-r--r--lib/ohai/plugins/ssh_host_key.rb2
-rw-r--r--lib/ohai/plugins/uptime.rb99
-rw-r--r--lib/ohai/plugins/virtualization.rb8
-rw-r--r--lib/ohai/plugins/windows/cpu.rb8
-rw-r--r--lib/ohai/plugins/windows/filesystem.rb8
-rw-r--r--lib/ohai/plugins/windows/hostname.rb39
-rw-r--r--lib/ohai/plugins/windows/kernel.rb64
-rw-r--r--lib/ohai/plugins/windows/network.rb11
-rw-r--r--lib/ohai/plugins/windows/platform.rb6
-rw-r--r--lib/ohai/plugins/windows/uptime.rb27
-rw-r--r--lib/ohai/runner.rb14
-rw-r--r--lib/ohai/system.rb10
-rw-r--r--spec/ohai/dsl/plugin_spec.rb337
-rw-r--r--spec/spec_helper.rb34
-rw-r--r--spec/unit/loader_spec.rb145
-rw-r--r--spec/unit/plugins/chef_spec.rb2
-rw-r--r--spec/unit/plugins/cloud_spec.rb2
-rw-r--r--spec/unit/plugins/darwin/cpu_spec.rb2
-rw-r--r--spec/unit/plugins/darwin/hostname_spec.rb6
-rw-r--r--spec/unit/plugins/darwin/kernel_spec.rb6
-rw-r--r--spec/unit/plugins/darwin/network_spec.rb14
-rw-r--r--spec/unit/plugins/darwin/platform_spec.rb5
-rw-r--r--spec/unit/plugins/darwin/system_profiler_spec.rb3
-rw-r--r--spec/unit/plugins/freebsd/hostname_spec.rb6
-rw-r--r--spec/unit/plugins/freebsd/kernel_spec.rb6
-rw-r--r--spec/unit/plugins/freebsd/platform_spec.rb4
-rw-r--r--spec/unit/plugins/freebsd/virtualization_spec.rb3
-rw-r--r--spec/unit/plugins/hostname_spec.rb1
-rw-r--r--spec/unit/plugins/kernel_spec.rb4
-rw-r--r--spec/unit/plugins/linux/cpu_spec.rb2
-rw-r--r--spec/unit/plugins/linux/filesystem_spec.rb2
-rw-r--r--spec/unit/plugins/linux/hostname_spec.rb4
-rw-r--r--spec/unit/plugins/linux/kernel_spec.rb8
-rw-r--r--spec/unit/plugins/linux/lsb_spec.rb2
-rw-r--r--spec/unit/plugins/linux/network_spec.rb8
-rw-r--r--spec/unit/plugins/linux/platform_spec.rb4
-rw-r--r--spec/unit/plugins/linux/uptime_spec.rb4
-rw-r--r--spec/unit/plugins/linux/virtualization_spec.rb2
-rw-r--r--spec/unit/plugins/netbsd/hostname_spec.rb4
-rw-r--r--spec/unit/plugins/netbsd/kernel_spec.rb6
-rw-r--r--spec/unit/plugins/netbsd/platform_spec.rb3
-rw-r--r--spec/unit/plugins/openbsd/hostname_spec.rb6
-rw-r--r--spec/unit/plugins/openbsd/kernel_spec.rb6
-rw-r--r--spec/unit/plugins/openbsd/platform_spec.rb7
-rw-r--r--spec/unit/plugins/os_spec.rb2
-rw-r--r--spec/unit/plugins/platform_spec.rb1
-rw-r--r--spec/unit/plugins/sigar/network_route_spec.rb17
-rw-r--r--spec/unit/plugins/solaris2/cpu_spec.rb2
-rw-r--r--spec/unit/plugins/solaris2/hostname_spec.rb6
-rw-r--r--spec/unit/plugins/solaris2/kernel_spec.rb5
-rw-r--r--spec/unit/plugins/solaris2/memory_spec.rb2
-rw-r--r--spec/unit/plugins/solaris2/network_spec.rb1
-rw-r--r--spec/unit/plugins/solaris2/platform_spec.rb2
-rw-r--r--spec/unit/plugins/solaris2/virtualization_spec.rb2
-rw-r--r--spec/unit/runner_spec.rb168
-rw-r--r--spec/unit/system_spec.rb139
185 files changed, 1561 insertions, 2258 deletions
diff --git a/Gemfile b/Gemfile
index c0751e4a..9b991f32 100644
--- a/Gemfile
+++ b/Gemfile
@@ -11,8 +11,8 @@ group :development do
gem "sigar", :platform => "ruby"
gem 'plist'
- # gem 'pry'
- # gem 'pry-debugger'
+ #gem 'pry'
+ #gem 'pry-debugger'
# gem 'pry-stack_explorer'
end
diff --git a/lib/ohai/common/dmi.rb b/lib/ohai/common/dmi.rb
new file mode 100644
index 00000000..9ad27a2a
--- /dev/null
+++ b/lib/ohai/common/dmi.rb
@@ -0,0 +1,126 @@
+#
+# Author:: Kurt Yoder (ktyopscode@yoderhome.com)
+# Copyright:: Copyright (c) 2010 Kurt Yoder
+# 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.
+#
+
+module Ohai
+ module Common
+ module DMI
+ # List of IDs and what they translate to
+ # from 'man 8 dmidecode'
+ # all-lowercase, all non-alphanumeric converted to '_'
+ # 128-255 are 'oem_data_[id]'
+ # Everything else is 'unknown'
+ IdToDescription = {
+ 0 => 'bios',
+ 1 => 'system',
+ 2 => 'base_board',
+ 3 => 'chassis',
+ 4 => 'processor',
+ 5 => 'memory_controller',
+ 6 => 'memory_module',
+ 7 => 'cache',
+ 8 => 'port_connector',
+ 9 => 'system_slots',
+ 10 => 'on_board_devices',
+ 11 => 'oem_strings',
+ 12 => 'system_configuration_options',
+ 13 => 'bios_language',
+ 14 => 'group_associations',
+ 15 => 'system_event_log',
+ 16 => 'physical_memory_array',
+ 17 => 'memory_device',
+ 18 => '32_bit_memory_error',
+ 19 => 'memory_array_mapped_address',
+ 20 => 'memory_device_mapped_address',
+ 21 => 'built_in_pointing_device',
+ 22 => 'portable_battery',
+ 23 => 'system_reset',
+ 24 => 'hardware_security',
+ 25 => 'system_power_controls',
+ 26 => 'voltage_probe',
+ 27 => 'cooling_device',
+ 28 => 'temperature_probe',
+ 29 => 'electrical_current_probe',
+ 30 => 'out_of_band_remote_access',
+ 31 => 'boot_integrity_services',
+ 32 => 'system_boot',
+ 33 => '64_bit_memory_error',
+ 34 => 'management_device',
+ 35 => 'management_device_component',
+ 36 => 'management_device_threshold_data',
+ 37 => 'memory_channel',
+ 38 => 'ipmi_device',
+ 39 => 'power_supply',
+ 126 => 'disabled_entries',
+ 127 => 'end_of_table_marker',
+ }
+
+ # list of IDs to collect, otherwise we generate pages of hashes about cache chip size and whatnot
+ # See OHAI-260. When we can give the user a choice, this will be a default.
+ IdToCapture = [ 0, 1, 2, 3, 4, 6, 11 ]
+
+ # look up DMI ID
+ def id_lookup(id)
+ begin
+ id = id.to_i
+ if (id >= 128) and (id <= 255)
+ id = "oem_data_#{id}"
+ elsif DMI::IdToDescription.has_key?(id)
+ id = DMI::IdToDescription[id]
+ else
+ Ohai::Log.debug("unrecognized header id; falling back to 'unknown'")
+ id = 'unknown'
+ end
+ rescue
+ Ohai::Log.debug("failed to look up id #{id}, returning unchanged")
+ id
+ end
+ end
+
+ # create simplified convenience access keys for each record type
+ # for single occurrences of one type, copy to top level all fields and values
+ # for multiple occurrences of same type, copy to top level all fields and values that are common to all records
+ def convenience_keys(dmi)
+ dmi.each{ |type, records|
+ in_common = Mash.new
+ next unless records.class.to_s == 'Mash'
+ next unless records.has_key?('all_records')
+ records[:all_records].each{ |record|
+ record.each{ |field, value|
+ next if value.class.to_s == 'Mash'
+ next if field.to_s == 'application_identifier'
+ next if field.to_s == 'size'
+ next if field.to_s == 'record_id'
+ translated = field.downcase.gsub(/[^a-z0-9]/, '_')
+ if in_common.has_key?(translated)
+ in_common[translated] = nil unless in_common[translated] == value
+ else
+ in_common[translated] = value
+ end
+ }
+ }
+ in_common.each{ |field, value|
+ next if value == nil
+ dmi[type][field] = value
+ }
+ }
+ end
+
+ module_function :id_lookup, :convenience_keys
+ end
+ end
+end
diff --git a/lib/ohai/dsl/plugin.rb b/lib/ohai/dsl/plugin.rb
index 16162a94..34178986 100644
--- a/lib/ohai/dsl/plugin.rb
+++ b/lib/ohai/dsl/plugin.rb
@@ -1,6 +1,7 @@
#
+# Author:: Adam Jacob (<adam@opscode.com>)
# Author:: Claire McQuin (<claire@opscode.com>)
-# Copyright:: Copyright (c) 2013 Opscode, Inc.
+# Copyright:: Copyright (c) 2008, 2013 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,17 +18,68 @@
# limitations under the License.
#
-require 'ohai/os'
+require 'ohai/mixin/os'
require 'ohai/mixin/command'
require 'ohai/mixin/seconds_to_human'
module Ohai
- def self.plugin(&block)
- Class.new(DSL::Plugin::VersionVII, &block)
+
+ # for plugin namespacing
+ module NamedPlugin
+ # dealing with ruby 1.8
+ if Module.method(:const_defined?).arity == 1
+ def self.strict_const_defined?(const)
+ const_defined?(const)
+ end
+ else
+ def self.strict_const_defined?(const)
+ const_defined?(const, false)
+ end
+ end
end
- def self.v6plugin(&block)
- Class.new(DSL::Plugin::VersionVI, &block)
+ def self.plugin(name, &block)
+ plugin = nil
+ if NamedPlugin.strict_const_defined?(name)
+ plugin = NamedPlugin.const_get(name)
+ if plugin.version.eql?(:version6)
+ Ohai::Log.warn("Already loaded version 6 plugin #{name}")
+ else
+ plugin.class_eval(&block)
+ end
+ else
+ klass = Class.new(DSL::Plugin::VersionVII, &block)
+ plugin = NamedPlugin.const_set(name, klass)
+ end
+ plugin
+ end
+
+ def self.v6plugin(name_str, &block)
+ plugin = nil
+ name = nameify(name_str)
+ if NamedPlugin.strict_const_defined?(name)
+ # log @ debug-level mimics OHAI-6
+ Ohai::Log.debug("Already loaded plugin #{name}")
+ plugin = NamedPlugin.const_get(name)
+ else
+ klass = Class.new(DSL::Plugin::VersionVI, &block)
+ plugin = NamedPlugin.const_set(name, klass)
+ end
+ plugin
+ end
+
+ def self.nameify(name_str)
+ return name_str if name_str.is_a?(Symbol)
+
+ parts = name_str.split(/[^a-zA-Z0-9]/)
+ name = ""
+ parts.each do |part|
+ next if part.eql?("")
+ name << part.capitalize
+ end
+
+ raise ArgumentError, "Invalid plugin name: #{name_str}" if name.eql?("")
+ name.to_sym
end
# cross platform /dev/null
@@ -47,7 +99,7 @@ module Ohai
module DSL
class Plugin
- include Ohai::OS
+ include Ohai::Mixin::OS
include Ohai::Mixin::Command
include Ohai::Mixin::SecondsToHuman
@@ -75,24 +127,19 @@ module Ohai
# version 7 plugin class
#=====================================================
class VersionVII < Plugin
+ attr_reader :version
+
def initialize(controller, source)
super(controller, source)
+ @version = :version7
end
- def version
- :version7
- end
-
- def dependencies
- self.class.depends_attrs
- end
-
- def provides(*paths)
- Ohai::Log.warn("[UNSUPPORTED OPERATION] \'provides\' is no longer supported in a \'collect_data\' context. Please specify \'provides\' before collecting plugin data. Ignoring command \'provides #{paths.join(", ")}")
+ def name
+ self.class.name.split("Ohai::NamedPlugin::")[1]
end
- def require_plugin(*args)
- Ohai::Log.warn("[UNSUPPORTED OPERATION] \'require_plugin\' is no longer supported. Please use \'depends\' instead.\nIgnoring plugin(s) #{args.join(", ")}")
+ def self.version
+ :version7
end
def self.provides_attrs
@@ -103,6 +150,10 @@ module Ohai
@depends_attrs ||= []
end
+ def self.data_collector
+ @data_collector ||= Mash.new
+ end
+
def self.provides(*attrs)
attrs.each do |attr|
provides_attrs << attr
@@ -115,14 +166,39 @@ module Ohai
end
end
- def self.depends_os(*attrs)
- attrs.each do |attr|
- depends_attrs << "#{Ohai::OS.collect_os}/#{attr}"
+ def self.collect_data(platform = :default, *other_platforms, &block)
+ [platform, other_platforms].flatten.each do |plat|
+ if data_collector.has_key?(plat)
+ Ohai::Log.warn("Already defined collect_data on platform #{plat}")
+ else
+ data_collector[plat] = block
+ end
end
end
- def self.collect_data(&block)
- define_method(:run_plugin, &block)
+ def dependencies
+ self.class.depends_attrs
+ end
+
+ def run_plugin
+ collector = self.class.data_collector
+ platform = collect_os
+
+ if collector.has_key?(platform)
+ self.instance_eval(&collector[platform])
+ elsif collector.has_key?(:default)
+ self.instance_eval(&collector[:default])
+ else
+ Ohai::Log.debug("No data to collect for plugin #{self.name}. Continuing...")
+ end
+ end
+
+ def provides(*paths)
+ Ohai::Log.warn("[UNSUPPORTED OPERATION] \'provides\' is no longer supported in a \'collect_data\' context. Please specify \'provides\' before collecting plugin data. Ignoring command \'provides #{paths.join(", ")}")
+ end
+
+ def require_plugin(*args)
+ Ohai::Log.warn("[UNSUPPORTED OPERATION] \'require_plugin\' is no longer supported. Please use \'depends\' instead.\nIgnoring plugin(s) #{args.join(", ")}")
end
end
@@ -130,14 +206,25 @@ module Ohai
# version 6 plugin class
#=====================================================
class VersionVI < Plugin
+ attr_reader :version
+
def initialize(controller, source)
super(controller, source)
+ @version = :version6
+ end
+
+ def name
+ self.class.name.split("Ohai::NamedPlugin::")[1]
end
- def version
+ def self.version
:version6
end
+ def self.collect_contents(contents)
+ define_method(:run_plugin) { self.instance_eval(contents) }
+ end
+
def provides(*paths)
paths.each do |path|
parts = path.split("/")
@@ -149,8 +236,8 @@ module Ohai
a = a[part]
end
end
- a[:providers] ||= []
- a[:providers] << self
+ a[:_providers] ||= []
+ a[:_providers] << self
end
end
@@ -158,9 +245,6 @@ module Ohai
@controller.require_plugin(*args)
end
- def self.collect_contents(contents)
- define_method(:run_plugin) { self.instance_eval(contents) }
- end
end
#=====================================================
@@ -247,7 +331,7 @@ module Ohai
begin
self.run
rescue => e
- Ohai::Log.error("Plugin #{self.class.name} threw #{e.inspect}")
+ Ohai::Log.error("Plugin #{self.name} threw #{e.inspect}")
e.backtrace.each { |line| Ohai::Log.debug( line )}
end
end
diff --git a/lib/ohai/loader.rb b/lib/ohai/loader.rb
index 249b04fe..c1ec7941 100644
--- a/lib/ohai/loader.rb
+++ b/lib/ohai/loader.rb
@@ -28,7 +28,9 @@ module Ohai
@attributes = controller.attributes
end
- def load_plugin(plugin_path)
+ # @note: plugin_name is used only by version 6 plugins and is the
+ # unique part of the file name from Ohai::Config[:plugin_path]
+ def load_plugin(plugin_path, plugin_name=nil)
plugin = nil
contents = ""
@@ -54,8 +56,8 @@ module Ohai
return plugin if plugin.nil?
collect_provides(plugin)
else
- Ohai::Log.warn("[DEPRECATION] Plugin at #{plugin_path} is a version 6 plugin. Version 6 plugins will not be supported in future releases of Ohai. Please upgrage your plugin to version 7 plugin syntax. For more information visit here: XXX")
- klass = Ohai.v6plugin { collect_contents(contents) }
+ Ohai::Log.warn("[DEPRECATION] Plugin at #{plugin_path} is a version 6 plugin. Version 6 plugins will not be supported in future releases of Ohai. Please upgrage your plugin to version 7 plugin syntax. For more information visit here: docs.opscode.com/ohai_custom.html")
+ klass = Ohai.v6plugin(plugin_name) { collect_contents(contents) }
plugin = klass.new(@controller, plugin_path)
end
@@ -76,8 +78,8 @@ module Ohai
end
end
- a[:providers] ||= []
- a[:providers] << plugin
+ a[:_providers] ||= []
+ a[:_providers] << plugin
end
end
diff --git a/lib/ohai/mixin/os.rb b/lib/ohai/mixin/os.rb
new file mode 100644
index 00000000..d42b1943
--- /dev/null
+++ b/lib/ohai/mixin/os.rb
@@ -0,0 +1,59 @@
+#
+# 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.
+#
+
+require 'rbconfig'
+
+module Ohai
+ module Mixin
+ module OS
+
+ def collect_os
+ case ::RbConfig::CONFIG['host_os']
+ when /aix(.+)$/
+ return "aix"
+ when /darwin(.+)$/
+ return "darwin"
+ when /hpux(.+)$/
+ return "hpux"
+ when /linux/
+ return "linux"
+ when /freebsd(.+)$/
+ return "freebsd"
+ when /openbsd(.+)$/
+ return "openbsd"
+ when /netbsd(.*)$/
+ return "netbsd"
+ when /solaris2/
+ return "solaris2"
+ when /mswin|mingw32|windows/
+ # After long discussion in IRC the "powers that be" have come to a consensus
+ # that no Windows platform exists that was not based on the
+ # Windows_NT kernel, so we herby decree that "windows" will refer to all
+ # platforms built upon the Windows_NT kernel and have access to win32 or win64
+ # subsystems.
+ return "windows"
+ else
+ return ::RbConfig::CONFIG['host_os']
+ end
+ end
+
+ module_function :collect_os
+ end
+ end
+end
diff --git a/lib/ohai/os.rb b/lib/ohai/os.rb
deleted file mode 100644
index 8daad297..00000000
--- a/lib/ohai/os.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-#
-#
-#
-
-require 'rbconfig'
-
-module Ohai
- module OS
-
- def self.collect_os
- case ::RbConfig::CONFIG['host_os']
- when /aix(.+)$/
- return "aix"
- when /darwin(.+)$/
- return "darwin"
- when /hpux(.+)$/
- return "hpux"
- when /linux/
- return "linux"
- when /freebsd(.+)$/
- return "freebsd"
- when /openbsd(.+)$/
- return "openbsd"
- when /netbsd(.*)$/
- return "netbsd"
- when /solaris2/
- return "solaris2"
- when /mswin|mingw32|windows/
- # After long discussion in IRC the "powers that be" have come to a consensus
- # that no Windows platform exists that was not based on the
- # Windows_NT kernel, so we herby decree that "windows" will refer to all
- # platforms built upon the Windows_NT kernel and have access to win32 or win64
- # subsystems.
- return "windows"
- else
- return ::RbConfig::CONFIG['host_os']
- end
- end
-
- def collect_os
- case ::RbConfig::CONFIG['host_os']
- when /aix(.+)$/
- return "aix"
- when /darwin(.+)$/
- return "darwin"
- when /hpux(.+)$/
- return "hpux"
- when /linux/
- return "linux"
- when /freebsd(.+)$/
- return "freebsd"
- when /openbsd(.+)$/
- return "openbsd"
- when /netbsd(.*)$/
- return "netbsd"
- when /solaris2/
- return "solaris2"
- when /mswin|mingw32|windows/
- # After long discussion in IRC the "powers that be" have come to a consensus
- # that no Windows platform exists that was not based on the
- # Windows_NT kernel, so we herby decree that "windows" will refer to all
- # platforms built upon the Windows_NT kernel and have access to win32 or win64
- # subsystems.
- return "windows"
- else
- return ::RbConfig::CONFIG['host_os']
- end
- end
-
- end
-end
diff --git a/lib/ohai/plugins/aix/cpu.rb b/lib/ohai/plugins/aix/cpu.rb
deleted file mode 100644
index 990b5ec1..00000000
--- a/lib/ohai/plugins/aix/cpu.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::cpu"
-end
diff --git a/lib/ohai/plugins/aix/filesystem.rb b/lib/ohai/plugins/aix/filesystem.rb
deleted file mode 100644
index fb0aaddc..00000000
--- a/lib/ohai/plugins/aix/filesystem.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::filesystem"
-end
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/aix/memory.rb b/lib/ohai/plugins/aix/memory.rb
deleted file mode 100644
index e711fe25..00000000
--- a/lib/ohai/plugins/aix/memory.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::memory"
-end
diff --git a/lib/ohai/plugins/aix/network.rb b/lib/ohai/plugins/aix/network.rb
deleted file mode 100644
index 807b4a4a..00000000
--- a/lib/ohai/plugins/aix/network.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::network"
-end
diff --git a/lib/ohai/plugins/aix/platform.rb b/lib/ohai/plugins/aix/platform.rb
deleted file mode 100644
index 9f142810..00000000
--- a/lib/ohai/plugins/aix/platform.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::platform"
-end
diff --git a/lib/ohai/plugins/aix/uptime.rb b/lib/ohai/plugins/aix/uptime.rb
deleted file mode 100644
index 324ced96..00000000
--- a/lib/ohai/plugins/aix/uptime.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::uptime"
-end
diff --git a/lib/ohai/plugins/azure.rb b/lib/ohai/plugins/azure.rb
index be97b030..27454f48 100644
--- a/lib/ohai/plugins/azure.rb
+++ b/lib/ohai/plugins/azure.rb
@@ -1,5 +1,5 @@
-Ohai.plugin do
+Ohai.plugin(:Azure) do
provides "azure"
collect_data do
diff --git a/lib/ohai/plugins/c.rb b/lib/ohai/plugins/c.rb
index 9eb5d36e..36bb13db 100644
--- a/lib/ohai/plugins/c.rb
+++ b/lib/ohai/plugins/c.rb
@@ -18,7 +18,7 @@
require 'rbconfig'
-Ohai.plugin do
+Ohai.plugin(:C) do
provides "languages/c"
depends "languages"
diff --git a/lib/ohai/plugins/chef.rb b/lib/ohai/plugins/chef.rb
index bbe16b46..fd9b7889 100644
--- a/lib/ohai/plugins/chef.rb
+++ b/lib/ohai/plugins/chef.rb
@@ -16,15 +16,15 @@
# limitations under the License.
#
-require 'chef/version'
-
-Ohai.plugin do
+Ohai.plugin(:Chef) do
provides "chef_packages/chef"
collect_data do
- self[:chef_packages] = Mash.new unless self[:chef_packages]
- self[:chef_packages][:chef] = Mash.new
- self[:chef_packages][:chef][:version] = Chef::VERSION
- self[:chef_packages][:chef][:chef_root] = Chef::CHEF_ROOT
+ require 'chef/version'
+
+ chef_packages Mash.new unless chef_packages
+ chef_packages[:chef] = Mash.new
+ chef_packages[:chef][:version] = Chef::VERSION
+ chef_packages[:chef][:chef_root] = Chef::CHEF_ROOT
end
end
diff --git a/lib/ohai/plugins/cloud.rb b/lib/ohai/plugins/cloud.rb
index 76913871..e8019074 100644
--- a/lib/ohai/plugins/cloud.rb
+++ b/lib/ohai/plugins/cloud.rb
@@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-Ohai.plugin do
+Ohai.plugin(:Cloud) do
provides "cloud"
depends "ec2"
diff --git a/lib/ohai/plugins/command.rb b/lib/ohai/plugins/command.rb
index 7c49ab3c..930846a5 100644
--- a/lib/ohai/plugins/command.rb
+++ b/lib/ohai/plugins/command.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Command) do
provides "command"
collect_data do
diff --git a/lib/ohai/plugins/darwin/cpu.rb b/lib/ohai/plugins/darwin/cpu.rb
index 6f1dc035..f43554b9 100644
--- a/lib/ohai/plugins/darwin/cpu.rb
+++ b/lib/ohai/plugins/darwin/cpu.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:CPU) do
provides "cpu"
- collect_data do
+ collect_data(:darwin) do
cpu Mash.new
so = shell_out("sysctl -n hw.physicalcpu")
cpu[:real] = so.stdout.to_i
diff --git a/lib/ohai/plugins/darwin/filesystem.rb b/lib/ohai/plugins/darwin/filesystem.rb
index 905df94d..83c8a6cf 100644
--- a/lib/ohai/plugins/darwin/filesystem.rb
+++ b/lib/ohai/plugins/darwin/filesystem.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Filesystem) do
provides "filesystem"
- collect_data do
+ collect_data(:darwin) do
fs = Mash.new
block_size = 0
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/darwin/kernel.rb b/lib/ohai/plugins/darwin/kernel.rb
deleted file mode 100644
index 51e2e4ef..00000000
--- a/lib/ohai/plugins/darwin/kernel.rb
+++ /dev/null
@@ -1,41 +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 "kernel/os", "kernel/machine", "kernel/modules"
- depends "kernel/name"
-
- collect_data do
- kernel[:os] = kernel[:name]
-
- so = shell_out("sysctl -n hw.optional.x86_64")
- if so.stdout.split($/)[0].to_i == 1
- kernel[:machine] = 'x86_64'
- end
-
- kext = Mash.new
- so = shell_out("kextstat -k -l")
- so.stdout.lines do |line|
- if line =~ /(\d+)\s+(\d+)\s+0x[0-9a-f]+\s+0x([0-9a-f]+)\s+0x[0-9a-f]+\s+([a-zA-Z0-9\.]+) \(([0-9\.]+)\)/
- kext[$4] = { :version => $5, :size => $3.hex, :index => $1, :refcount => $2 }
- end
- end
-
- kernel[:modules] = kext
- end
-end
diff --git a/lib/ohai/plugins/darwin/network.rb b/lib/ohai/plugins/darwin/network.rb
index cf209a97..4ed63eb7 100644
--- a/lib/ohai/plugins/darwin/network.rb
+++ b/lib/ohai/plugins/darwin/network.rb
@@ -16,10 +16,9 @@
# limitations under the License.
#
-require 'scanf'
-
-Ohai.plugin do
- provides "network", "counters/network"
+Ohai.plugin(:Network) do
+ provides "network", "network/interfaces"
+ provides "counters/network", "counters/network/interfaces"
def parse_media(media_string)
media = Hash.new
@@ -84,7 +83,9 @@ Ohai.plugin do
nil
end
- collect_data do
+ collect_data(:darwin) do
+ require 'scanf'
+
network Mash.new unless network
network[:interfaces] = Mash.new unless network[:interfaces]
counters Mash.new unless counters
diff --git a/lib/ohai/plugins/darwin/platform.rb b/lib/ohai/plugins/darwin/platform.rb
index a96cc0a9..fc26544c 100644
--- a/lib/ohai/plugins/darwin/platform.rb
+++ b/lib/ohai/plugins/darwin/platform.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Platform) do
provides "platform", "platform_version", "platform_build", "platform_family"
- collect_data do
+ collect_data(:darwin) do
so = shell_out("#{ Ohai.abs_path( "/usr/bin/sw_vers" )}")
so.stdout.lines do |line|
case line
diff --git a/lib/ohai/plugins/darwin/ps.rb b/lib/ohai/plugins/darwin/ps.rb
deleted file mode 100644
index 013c1eb0..00000000
--- a/lib/ohai/plugins/darwin/ps.rb
+++ /dev/null
@@ -1,27 +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 "command/ps"
-
- depends 'command'
-
- collect_data do
- command[:ps] = 'ps -ef'
- end
-end
diff --git a/lib/ohai/plugins/darwin/system_profiler.rb b/lib/ohai/plugins/darwin/system_profiler.rb
index 5c364beb..e3756d3f 100644
--- a/lib/ohai/plugins/darwin/system_profiler.rb
+++ b/lib/ohai/plugins/darwin/system_profiler.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:SystemProfile) do
provides "system_profile"
- collect_data do
+ collect_data(:darwin) do
begin
require 'plist'
diff --git a/lib/ohai/plugins/darwin/uptime.rb b/lib/ohai/plugins/darwin/uptime.rb
deleted file mode 100644
index 4d966cd5..00000000
--- a/lib/ohai/plugins/darwin/uptime.rb
+++ /dev/null
@@ -1,33 +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 "uptime", "uptime_seconds"
-
- # kern.boottime: { sec = 1232765114, usec = 823118 } Fri Jan 23 18:45:14 2009
-
- collect_data do
- so = shell_out("#{ Ohai.abs_path( "/usr/sbin/sysctl" )} kern.boottime")
- so.stdout.lines do |line|
- if line =~ /kern.boottime:\D+(\d+)/
- uptime_seconds Time.new.to_i - $1.to_i
- uptime seconds_to_human(uptime_seconds)
- end
- end
- end
-end
diff --git a/lib/ohai/plugins/dmi.rb b/lib/ohai/plugins/dmi.rb
index 48bcb5e1..e63c7b92 100644
--- a/lib/ohai/plugins/dmi.rb
+++ b/lib/ohai/plugins/dmi.rb
@@ -16,14 +16,13 @@
# limitations under the License.
#
-require "ohai/plugins/dmi_common"
-
-Ohai.plugin do
+Ohai.plugin(:DMI) do
provides "dmi"
# dmidecode does not return data without access to /dev/mem (or its equivalent)
collect_data do
+ require 'ohai/common/dmi'
dmi Mash.new
# all output lines should fall within one of these patterns
@@ -75,9 +74,9 @@ Ohai.plugin do
elsif handle = handle_line.match(line)
# Don't overcapture for now (OHAI-260)
- next unless DMI::IdToCapture.include?(handle[2].to_i)
+ next unless Ohai::Common::DMI::IdToCapture.include?(handle[2].to_i)
- dmi_record = {:type => DMI.id_lookup(handle[2])}
+ dmi_record = {:type => Ohai::Common::DMI.id_lookup(handle[2])}
dmi[dmi_record[:type]] = Mash.new unless dmi.has_key?(dmi_record[:type])
dmi[dmi_record[:type]][:all_records] = [] unless dmi[dmi_record[:type]].has_key?(:all_records)
@@ -121,6 +120,6 @@ Ohai.plugin do
end
end
- DMI.convenience_keys(dmi)
+ Ohai::Common::DMI.convenience_keys(dmi)
end
end
diff --git a/lib/ohai/plugins/dmi_common.rb b/lib/ohai/plugins/dmi_common.rb
deleted file mode 100644
index 8e49ac0e..00000000
--- a/lib/ohai/plugins/dmi_common.rb
+++ /dev/null
@@ -1,121 +0,0 @@
-#
-# Author:: Kurt Yoder (ktyopscode@yoderhome.com)
-# Copyright:: Copyright (c) 2010 Kurt Yoder
-# 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.
-#
-
-module DMI
- # List of IDs and what they translate to
- # from 'man 8 dmidecode'
- # all-lowercase, all non-alphanumeric converted to '_'
- # 128-255 are 'oem_data_[id]'
- # Everything else is 'unknown'
- IdToDescription = {
- 0 => 'bios',
- 1 => 'system',
- 2 => 'base_board',
- 3 => 'chassis',
- 4 => 'processor',
- 5 => 'memory_controller',
- 6 => 'memory_module',
- 7 => 'cache',
- 8 => 'port_connector',
- 9 => 'system_slots',
- 10 => 'on_board_devices',
- 11 => 'oem_strings',
- 12 => 'system_configuration_options',
- 13 => 'bios_language',
- 14 => 'group_associations',
- 15 => 'system_event_log',
- 16 => 'physical_memory_array',
- 17 => 'memory_device',
- 18 => '32_bit_memory_error',
- 19 => 'memory_array_mapped_address',
- 20 => 'memory_device_mapped_address',
- 21 => 'built_in_pointing_device',
- 22 => 'portable_battery',
- 23 => 'system_reset',
- 24 => 'hardware_security',
- 25 => 'system_power_controls',
- 26 => 'voltage_probe',
- 27 => 'cooling_device',
- 28 => 'temperature_probe',
- 29 => 'electrical_current_probe',
- 30 => 'out_of_band_remote_access',
- 31 => 'boot_integrity_services',
- 32 => 'system_boot',
- 33 => '64_bit_memory_error',
- 34 => 'management_device',
- 35 => 'management_device_component',
- 36 => 'management_device_threshold_data',
- 37 => 'memory_channel',
- 38 => 'ipmi_device',
- 39 => 'power_supply',
- 126 => 'disabled_entries',
- 127 => 'end_of_table_marker',
- }
-
- # list of IDs to collect, otherwise we generate pages of hashes about cache chip size and whatnot
- # See OHAI-260. When we can give the user a choice, this will be a default.
- IdToCapture = [ 0, 1, 2, 3, 4, 6, 11 ]
-
- # look up DMI ID
- def DMI.id_lookup(id)
- begin
- id = id.to_i
- if (id >= 128) and (id <= 255)
- id = "oem_data_#{id}"
- elsif DMI::IdToDescription.has_key?(id)
- id = DMI::IdToDescription[id]
- else
- Ohai::Log.debug("unrecognized header id; falling back to 'unknown'")
- id = 'unknown'
- end
- rescue
- Ohai::Log.debug("failed to look up id #{id}, returning unchanged")
- id
- end
- end
-
- # create simplified convenience access keys for each record type
- # for single occurrences of one type, copy to top level all fields and values
- # for multiple occurrences of same type, copy to top level all fields and values that are common to all records
- def DMI.convenience_keys(dmi)
- dmi.each{ |type, records|
- in_common = Mash.new
- next unless records.class.to_s == 'Mash'
- next unless records.has_key?('all_records')
- records[:all_records].each{ |record|
- record.each{ |field, value|
- next if value.class.to_s == 'Mash'
- next if field.to_s == 'application_identifier'
- next if field.to_s == 'size'
- next if field.to_s == 'record_id'
- translated = field.downcase.gsub(/[^a-z0-9]/, '_')
- if in_common.has_key?(translated)
- in_common[translated] = nil unless in_common[translated] == value
- else
- in_common[translated] = value
- end
- }
- }
- in_common.each{ |field, value|
- next if value == nil
- dmi[type][field] = value
- }
- }
- end
-
-end
diff --git a/lib/ohai/plugins/ec2.rb b/lib/ohai/plugins/ec2.rb
index 2df62ac7..e7ab945d 100644
--- a/lib/ohai/plugins/ec2.rb
+++ b/lib/ohai/plugins/ec2.rb
@@ -19,14 +19,12 @@
require 'ohai/mixin/ec2_metadata'
-Ohai.plugin do
+Ohai.plugin(:EC2) do
include Ohai::Mixin::Ec2Metadata
-
+
provides "ec2"
- depends "fqdn", "domain"
- depends "kernel"
- depends "network", "counters/network"
+ depends "network/interfaces"
def has_ec2_mac?
network[:interfaces].values.each do |iface|
diff --git a/lib/ohai/plugins/erlang.rb b/lib/ohai/plugins/erlang.rb
index e398fc61..ebea9da7 100644
--- a/lib/ohai/plugins/erlang.rb
+++ b/lib/ohai/plugins/erlang.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Erlang) do
provides "languages/erlang"
depends "languages"
diff --git a/lib/ohai/plugins/eucalyptus.rb b/lib/ohai/plugins/eucalyptus.rb
index 2d84cb21..c5fed2f0 100644
--- a/lib/ohai/plugins/eucalyptus.rb
+++ b/lib/ohai/plugins/eucalyptus.rb
@@ -19,14 +19,12 @@
require 'ohai/mixin/ec2_metadata'
-Ohai.plugin do
+Ohai.plugin(:Eucalyptus) do
include Ohai::Mixin::Ec2Metadata
provides "eucalyptus"
- depends "fqdn", "domain"
- depends "kernel"
- depends "network"
+ depends "network/interfaces"
def get_mac_address(addresses)
detected_addresses = addresses.detect { |address, keypair| keypair == {"family"=>"lladdr"} }
diff --git a/lib/ohai/plugins/freebsd/cpu.rb b/lib/ohai/plugins/freebsd/cpu.rb
index 7512c042..1a9c97cf 100644
--- a/lib/ohai/plugins/freebsd/cpu.rb
+++ b/lib/ohai/plugins/freebsd/cpu.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:CPU) do
provides "cpu"
- collect_data do
+ collect_data(:freebsd) do
# all dmesg output for smp I can find only provides info about a single processor
# identical processors is probably a hardware requirement so we'll duplicate data for each cpu
# old examples: http://www.bnv-bamberg.de/home/ba3294/smp/rbuild/index.htm
diff --git a/lib/ohai/plugins/freebsd/filesystem.rb b/lib/ohai/plugins/freebsd/filesystem.rb
index 7131cdad..b0037512 100644
--- a/lib/ohai/plugins/freebsd/filesystem.rb
+++ b/lib/ohai/plugins/freebsd/filesystem.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Filesystem) do
provides "filesystem"
- collect_data do
+ collect_data(:freebsd) do
fs = Mash.new
# Grab filesystem data from df
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/freebsd/kernel.rb b/lib/ohai/plugins/freebsd/kernel.rb
deleted file mode 100644
index e5a5a314..00000000
--- a/lib/ohai/plugins/freebsd/kernel.rb
+++ /dev/null
@@ -1,40 +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 "kernel"
-
- collect_data do
- kernel[:os] = kernel[:name]
- so = shell_out("uname -i")
- kernel[:ident] = so.stdout.split($/)[0]
- so = shell_out("sysctl kern.securelevel")
- kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel: (.+)$/ }
-
- kld = Mash.new
- so = shell_out("#{ Ohai.abs_path( "/sbin/kldstat" )}")
- so.stdout.lines do |line|
- # 1 7 0xc0400000 97f830 kernel
- if line =~ /(\d+)\s+(\d+)\s+([0-9a-fx]+)\s+([0-9a-fx]+)\s+([a-zA-Z0-9\_]+)/
- kld[$5] = { :size => $4, :refcount => $2 }
- end
- end
-
- kernel[:modules] = kld
- end
-end
diff --git a/lib/ohai/plugins/freebsd/memory.rb b/lib/ohai/plugins/freebsd/memory.rb
index 969c89f2..842f9689 100644
--- a/lib/ohai/plugins/freebsd/memory.rb
+++ b/lib/ohai/plugins/freebsd/memory.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
- provides "memory"
+Ohai.plugin(:Memory) do
+ provides "memory", "memory/swap"
- collect_data do
+ collect_data(:freebsd) do
memory Mash.new
memory[:swap] = Mash.new
diff --git a/lib/ohai/plugins/freebsd/network.rb b/lib/ohai/plugins/freebsd/network.rb
index 2286e033..6f5eed5b 100644
--- a/lib/ohai/plugins/freebsd/network.rb
+++ b/lib/ohai/plugins/freebsd/network.rb
@@ -16,9 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
- provides "network", "counters/network"
-
+Ohai.plugin(:Network) do
+ provides "network", "network/interfaces"
+ provides "counters/network", "counters/network/interfaces"
+
collect_data do
network Mash.new unless network
network[:interfaces] = Mash.new unless network[:interfaces]
diff --git a/lib/ohai/plugins/freebsd/platform.rb b/lib/ohai/plugins/freebsd/platform.rb
index 0bfaee77..bef7b73e 100644
--- a/lib/ohai/plugins/freebsd/platform.rb
+++ b/lib/ohai/plugins/freebsd/platform.rb
@@ -16,13 +16,14 @@
# limitations under the License.
#
-Ohai.plugin do
- provides "platform", "platform_version"
+Ohai.plugin(:Platform) do
+ provides "platform", "platform_version", "platform_family"
- collect_data do
+ collect_data(:freebsd) do
so = shell_out("uname -s")
platform so.stdout.split($/)[0].downcase
so = shell_out("uname -r")
platform_version so.stdout.split($/)[0]
+ platform_family "freebsd"
end
end
diff --git a/lib/ohai/plugins/freebsd/ps.rb b/lib/ohai/plugins/freebsd/ps.rb
deleted file mode 100644
index 8bde6414..00000000
--- a/lib/ohai/plugins/freebsd/ps.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 "command/ps"
-
- depends 'command'
-
- collect_data do
- # ps -e requires procfs
- command[:ps] = 'ps -ax'
- end
-end
diff --git a/lib/ohai/plugins/freebsd/uptime.rb b/lib/ohai/plugins/freebsd/uptime.rb
deleted file mode 100644
index db05656f..00000000
--- a/lib/ohai/plugins/freebsd/uptime.rb
+++ /dev/null
@@ -1,33 +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 "uptime", "uptime_seconds"
-
- # kern.boottime: { sec = 1232765114, usec = 823118 } Fri Jan 23 18:45:14 2009
-
- collect_data do
- so = shell_out("#{ Ohai.abs_path( "/sbin/sysctl" )} kern.boottime")
- so.stdout.lines do |line|
- if line =~ /kern.boottime:\D+(\d+)/
- uptime_seconds Time.new.to_i - $1.to_i
- uptime seconds_to_human(uptime_seconds)
- end
- end
- end
-end
diff --git a/lib/ohai/plugins/freebsd/virtualization.rb b/lib/ohai/plugins/freebsd/virtualization.rb
index 3a7ae79c..aedcb694 100644
--- a/lib/ohai/plugins/freebsd/virtualization.rb
+++ b/lib/ohai/plugins/freebsd/virtualization.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Virtualization) do
provides "virtualization"
- collect_data do
+ collect_data(:freebsd) do
virtualization Mash.new
so = shell_out("sysctl -n security.jail.jailed")
diff --git a/lib/ohai/plugins/gce.rb b/lib/ohai/plugins/gce.rb
index 75930ec3..af412110 100644
--- a/lib/ohai/plugins/gce.rb
+++ b/lib/ohai/plugins/gce.rb
@@ -16,13 +16,12 @@
require 'ohai/mixin/gce_metadata'
-Ohai.plugin do
+Ohai.plugin(:GCE) do
include Ohai::Mixin::GCEMetadata
+ GOOGLE_SYSFS_DMI = '/sys/firmware/dmi/entries/1-0/raw'
provides "gce"
-
- GOOGLE_SYSFS_DMI = '/sys/firmware/dmi/entries/1-0/raw'
-
+
#https://developers.google.com/compute/docs/instances#dmi
def has_google_dmi?
::File.read(GOOGLE_SYSFS_DMI).include?('Google')
diff --git a/lib/ohai/plugins/groovy.rb b/lib/ohai/plugins/groovy.rb
index de45e0e9..044a6e33 100644
--- a/lib/ohai/plugins/groovy.rb
+++ b/lib/ohai/plugins/groovy.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Groovy) do
provides "languages/groovy"
depends "languages"
diff --git a/lib/ohai/plugins/hostname.rb b/lib/ohai/plugins/hostname.rb
index 0527ccac..779af3ec 100644
--- a/lib/ohai/plugins/hostname.rb
+++ b/lib/ohai/plugins/hostname.rb
@@ -1,6 +1,14 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
+# Author:: Benjamin Black (<nostromo@gmail.com>)
+# Author:: Bryan McLellan (<btm@loftninjas.org>)
+# Author:: Daniel DeLeo (<dan@kallistec.com>)
+# Author:: Doug MacEachern (<dougm@vmware.com>)
+# Author:: James Gartrell (<jgartrel@gmail.com>)
+# Copyright:: Copyright (c) 2008, 2009 Opscode, Inc.
+# Copyright:: Copyright (c) 2009 Bryan McLellan
+# Copyright:: Copyright (c) 2009 Daniel DeLeo
+# Copyright:: Copyright (c) 2010 VMware, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,16 +24,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/cpu.rb b/lib/ohai/plugins/hpux/cpu.rb
deleted file mode 100644
index 990b5ec1..00000000
--- a/lib/ohai/plugins/hpux/cpu.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::cpu"
-end
diff --git a/lib/ohai/plugins/hpux/filesystem.rb b/lib/ohai/plugins/hpux/filesystem.rb
deleted file mode 100644
index fb0aaddc..00000000
--- a/lib/ohai/plugins/hpux/filesystem.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::filesystem"
-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/hpux/memory.rb b/lib/ohai/plugins/hpux/memory.rb
deleted file mode 100644
index e711fe25..00000000
--- a/lib/ohai/plugins/hpux/memory.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::memory"
-end
diff --git a/lib/ohai/plugins/hpux/network.rb b/lib/ohai/plugins/hpux/network.rb
deleted file mode 100644
index 807b4a4a..00000000
--- a/lib/ohai/plugins/hpux/network.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::network"
-end
diff --git a/lib/ohai/plugins/hpux/platform.rb b/lib/ohai/plugins/hpux/platform.rb
deleted file mode 100644
index 9f142810..00000000
--- a/lib/ohai/plugins/hpux/platform.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::platform"
-end
diff --git a/lib/ohai/plugins/hpux/ps.rb b/lib/ohai/plugins/hpux/ps.rb
deleted file mode 100644
index 51e4e44f..00000000
--- a/lib/ohai/plugins/hpux/ps.rb
+++ /dev/null
@@ -1,27 +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 "command/ps"
-
- depends 'command'
-
- collect_data do
- command[:ps] = 'ps -ef'
- end
-end
diff --git a/lib/ohai/plugins/hpux/uptime.rb b/lib/ohai/plugins/hpux/uptime.rb
deleted file mode 100644
index 324ced96..00000000
--- a/lib/ohai/plugins/hpux/uptime.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::uptime"
-end
diff --git a/lib/ohai/plugins/ip_scopes.rb b/lib/ohai/plugins/ip_scopes.rb
index 62ab6cd0..261bea5b 100644
--- a/lib/ohai/plugins/ip_scopes.rb
+++ b/lib/ohai/plugins/ip_scopes.rb
@@ -15,11 +15,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-Ohai.plugin do
+Ohai.plugin(:IpScopes) do
provides "network_ip_scope", "privateaddress"
- depends "domain", "fqdn"
- depends "network", "counters/network"
+ depends "network/interfaces"
collect_data do
begin
diff --git a/lib/ohai/plugins/java.rb b/lib/ohai/plugins/java.rb
index 6a620a80..11a5a643 100644
--- a/lib/ohai/plugins/java.rb
+++ b/lib/ohai/plugins/java.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Java) do
provides "languages/java"
depends "languages"
diff --git a/lib/ohai/plugins/kernel.rb b/lib/ohai/plugins/kernel.rb
index 17ae07aa..66af66c8 100644
--- a/lib/ohai/plugins/kernel.rb
+++ b/lib/ohai/plugins/kernel.rb
@@ -1,40 +1,203 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
+# Author:: Benjamin Black (<nostromo@gmail.com>)
+# Author:: Bryan McLellan (<btm@loftninjas.org>)
+# Author:: Claire McQuin (<claire@opscode.com>)
+# Author:: James Gartrell (<jgartrel@gmail.com>)
+# Copyright:: Copyright (c) 2008, 2009, 2013 Opscode, Inc.
+# 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.
+# 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 "kernel"
- provides "kernel/name", "kernel/release", "kernel/version", "kernel/machine", "kernel/modules"
+Ohai.plugin(:Kernel) do
+ provides "kernel", "kernel/modules"
- depends "languages/ruby"
-
- collect_data do
+ # common initial kernel attribute values
+ def init_kernel
kernel Mash.new
- case languages[:ruby][:host_os]
- when /mswin|mingw32|windows/
- require_plugin "windows::kernel"
- require_plugin "windows::kernel_devices"
- else
- [["uname -s", :name], ["uname -r", :release],
- ["uname -v", :version], ["uname -m", :machine]].each do |command, node|
- so = shell_out(command)
- kernel[node] = so.stdout.split($/)[0]
+ [["uname -s", :name], ["uname -r", :release],
+ ["uname -v", :version], ["uname -m", :machine]].each do |cmd, property|
+ so = shell_out(cmd)
+ kernel[property] = so.stdout.split($/)[0]
+ end
+ kernel
+ end
+
+ # common *bsd code for collecting modules data
+ def bsd_modules(path)
+ modules = Mash.new
+ so = shell_out("#{Ohai.abs_path(path)}")
+ so.stdout.lines do |line|
+ # 1 7 0xc0400000 97f830 kernel
+ if line =~ /(\d+)\s+(\d+)\s+([0-9a-fx]+)\s+([0-9a-fx]+)\s+([a-zA-Z0-9\_]+)/
+ modules[$5] = { :size => $4, :refcount => $2 }
+ end
+ end
+ modules
+ end
+
+ # windows
+ def machine_lookup(sys_type)
+ return "i386" if sys_type.eql?("X86-based PC")
+ return "x86_64" if sys_type.eql?("x64-based PC")
+ sys_type
+ end
+
+ # windows
+ def os_lookup(sys_type)
+ return "Unknown" if sys_type.to_s.eql?("0")
+ return "Other" if sys_type.to_s.eql?("1")
+ return "MSDOS" if sys_type.to_s.eql?("14")
+ return "WIN3x" if sys_type.to_s.eql?("15")
+ return "WIN95" if sys_type.to_s.eql?("16")
+ return "WIN98" if sys_type.to_s.eql?("17")
+ return "WINNT" if sys_type.to_s.eql?("18")
+ return "WINCE" if sys_type.to_s.eql?("19")
+ return nil
+ end
+
+ collect_data(:default) do
+ kernel init_kernel
+ end
+
+ collect_data(:darwin) do
+ kernel init_kernel
+ kernel[:os] = kernel[:name]
+
+ so = shell_out("sysctl -n hw.optional.x86_64")
+ if so.stdout.split($/)[0].to_i == 1
+ kernel[:machine] = 'x86_64'
+ end
+
+ modules = Mash.new
+ so = shell_out("kextstat -k -l")
+ so.stdout.lines do |line|
+ if line =~ /(\d+)\s+(\d+)\s+0x[0-9a-f]+\s+0x([0-9a-f]+)\s+0x[0-9a-f]+\s+([a-zA-Z0-9\.]+) \(([0-9\.]+)\)/
+ kext[$4] = { :version => $5, :size => $3.hex, :index => $1, :refcount => $2 }
+ end
+ end
+
+ kernel[:modules] = modules
+ end
+
+ collect_data(:freebsd) do
+ kernel init_kernel
+ kernel[:os] = kernel[:name]
+
+ so = shell_out("uname -i")
+ kernel[:ident] = so.stdout.split($/)[0]
+ so = shell_out("sysctl kern.securelevel")
+ kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel: (.+)$/ }
+
+ kernel[:modules] = bsd_modules("/sbin/kldstat")
+ end
+
+ collect_data(:linux) do
+ kernel init_kernel
+
+ so = shell_out("uname -o")
+ kernel[:os] = so.stdout.split($/)[0]
+
+ modules = Mash.new
+ so = shell_out("env lsmod")
+ so.stdout.lines do |line|
+ if line =~ /([a-zA-Z0-9\_]+)\s+(\d+)\s+(\d+)/
+ modules[$1] = { :size => $2, :refcount => $3 }
end
- kernel[:modules] = Mash.new
end
+
+ kernel[:modules] = modules
+ end
+
+ collect_data(:netbsd, :openbsd) do
+ kernel init_kernel
+ kernel[:os] = kernel[:name]
+
+ so = shell_out("sysctl kern.securelevel")
+ kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel:\ (.+)$/ }
+
+ kernel[:modules] = bsd_modules("/usr/bin/modstat")
+ end
+
+ collect_data(:solaris2) do
+ kernel init_kernel
+
+ so = shell_out("uname -s")
+ kernel[:os] = so.stdout.split($/)[0]
+
+ modules = Mash.new
+
+ so = shell_out("modinfo")
+ # EXAMPLE:
+ # Id Loadaddr Size Info Rev Module Name
+ # 6 1180000 4623 1 1 specfs (filesystem for specfs)
+ module_description = /[\s]*([\d]+)[\s]+([a-f\d]+)[\s]+([a-f\d]+)[\s]+(?:[\-\d]+)[\s]+(?:[\d]+)[\s]+([\S]+)[\s]+\((.+)\)$/
+ so.stdout.lines do |line|
+ if mod = module_description.match(line)
+ modules[mod[4]] = { :id => mod[1].to_i, :loadaddr => mod[2], :size => mod[3].to_i(16), :description => mod[5]}
+ end
+ end
+
+ kernel[:modules] = modules
+ end
+
+ collect_data(:windows) do
+ require 'ruby-wmi'
+ WIN32OLE.codepage = WIN32OLE::CP_UTF8
+
+ kernel = Mash.new
+
+ host = WMI::Win32_OperatingSystem.find(:first)
+ kernel[:os_info] = Mash.new
+ host.properties_.each do |p|
+ kernel[:os_info][p.name.wmi_underscore.to_sym] = host.send(p.name)
+ end
+
+ kernel[:name] = "#{kernel[:os_info][:caption]}"
+ kernel[:release] = "#{kernel[:os_info][:version]}"
+ kernel[:version] = "#{kernel[:os_info][:version]}
+ ##{kernel[:os_info][:csd_version]} Build
+ ###{kernel[:os_info][:build_number]}"
+ kernel[:os] = os_lookup(kernel[:os_info][:os_type]) || languages[:ruby][:host_os]
+
+ host = WMI::Win32_ComputerSystem.find(:first)
+ kernel[:cs_info] = Mash.new
+ host.properties_.each do |p|
+ kernel[:cs_info][p.name.wmi_underscore.to_sym] = host.send(p.name)
+ end
+
+ kernel[:machine] = machine_lookup("#{kernel[:cs_info][:system_type]}")
+
+ kext = Mash.new
+ pnp_drivers = Mash.new
+
+ drivers = WMI::Win32_PnPSignedDriver.find(:all)
+ drivers.each do |driver|
+ pnp_drivers[driver.DeviceID] = Mash.new
+ driver.properties_.each do |p|
+ pnp_drivers[driver.DeviceID][p.name.wmi_underscore.to_sym] = driver.send(p.name)
+ end
+ if driver.DeviceName
+ kext[driver.DeviceName] = pnp_drivers[driver.DeviceID]
+ kext[driver.DeviceName][:version] = pnp_drivers[driver.DeviceID][:driver_version]
+ kext[driver.DeviceName][:date] = pnp_drivers[driver.DeviceID][:driver_date] ? pnp_drivers[driver.DeviceID][:driver_date].to_s[0..7] : nil
+ end
+ end
+
+ kernel[:pnp_drivers] = pnp_drivers
+ kernel[:modules] = kext
end
end
diff --git a/lib/ohai/plugins/keys.rb b/lib/ohai/plugins/keys.rb
index 6de9286d..d786f4fd 100644
--- a/lib/ohai/plugins/keys.rb
+++ b/lib/ohai/plugins/keys.rb
@@ -17,7 +17,7 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Keys) do
provides "keys"
collect_data do
diff --git a/lib/ohai/plugins/languages.rb b/lib/ohai/plugins/languages.rb
index e7e1eda2..678c8a24 100644
--- a/lib/ohai/plugins/languages.rb
+++ b/lib/ohai/plugins/languages.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Languages) do
provides "languages"
collect_data do
diff --git a/lib/ohai/plugins/linode.rb b/lib/ohai/plugins/linode.rb
index b21bf097..fb0fea19 100644
--- a/lib/ohai/plugins/linode.rb
+++ b/lib/ohai/plugins/linode.rb
@@ -14,11 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-Ohai.plugin do
+Ohai.plugin(:Linode) do
provides "linode"
depends "kernel"
- depends "network", "counters/network"
+ depends "network/interfaces"
# Checks for matching linode kernel name
#
diff --git a/lib/ohai/plugins/linux/block_device.rb b/lib/ohai/plugins/linux/block_device.rb
index ff8890aa..e8854e68 100644
--- a/lib/ohai/plugins/linux/block_device.rb
+++ b/lib/ohai/plugins/linux/block_device.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:BlockDevice) do
provides "block_device"
- collect_data do
+ collect_data(:linux) do
if File.exists?("/sys/block")
block = Mash.new
Dir["/sys/block/*"].each do |block_device_dir|
diff --git a/lib/ohai/plugins/linux/cpu.rb b/lib/ohai/plugins/linux/cpu.rb
index 5bc189bc..aeee390a 100644
--- a/lib/ohai/plugins/linux/cpu.rb
+++ b/lib/ohai/plugins/linux/cpu.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:CPU) do
provides "cpu"
- collect_data do
+ collect_data(:linux) do
cpuinfo = Mash.new
real_cpu = Mash.new
cpu_number = 0
diff --git a/lib/ohai/plugins/linux/filesystem.rb b/lib/ohai/plugins/linux/filesystem.rb
index 41939c06..6a10d75c 100644
--- a/lib/ohai/plugins/linux/filesystem.rb
+++ b/lib/ohai/plugins/linux/filesystem.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Filesystem) do
provides "filesystem"
- collect_data do
+ collect_data(:linux) do
fs = Mash.new
# Grab filesystem data from df
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/linux/kernel.rb b/lib/ohai/plugins/linux/kernel.rb
deleted file mode 100644
index c2dd3e45..00000000
--- a/lib/ohai/plugins/linux/kernel.rb
+++ /dev/null
@@ -1,36 +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 "kernel"
-
- collect_data do
- so = shell_out("uname -o")
- kernel[:os] = so.stdout.split(/\r?\n/)[0]
-
- kext = Mash.new
- so = shell_out("env lsmod")
- so.stdout.lines do |line|
- if line =~ /([a-zA-Z0-9\_]+)\s+(\d+)\s+(\d+)/
- kext[$1] = { :size => $2, :refcount => $3 }
- end
- end
-
- kernel[:modules] = kext
- end
-end
diff --git a/lib/ohai/plugins/linux/lsb.rb b/lib/ohai/plugins/linux/lsb.rb
index a982fce4..7bd16b63 100644
--- a/lib/ohai/plugins/linux/lsb.rb
+++ b/lib/ohai/plugins/linux/lsb.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:LSB) do
provides "lsb"
- collect_data do
+ collect_data(:linux) do
lsb Mash.new
if File.exists?("/etc/lsb-release")
diff --git a/lib/ohai/plugins/linux/memory.rb b/lib/ohai/plugins/linux/memory.rb
index d41fc783..e5c76801 100644
--- a/lib/ohai/plugins/linux/memory.rb
+++ b/lib/ohai/plugins/linux/memory.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
- provides "memory"
+Ohai.plugin(:Memory) do
+ provides "memory", "memory/swap"
- collect_data do
+ collect_data(:linux) do
memory Mash.new
memory[:swap] = Mash.new
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
index ad701b5d..c25e4986 100644
--- a/lib/ohai/plugins/linux/network.rb
+++ b/lib/ohai/plugins/linux/network.rb
@@ -16,10 +16,9 @@
# limitations under the License.
#
-require 'ipaddr'
-
-Ohai.plugin do
- provides "network", "counters/network"
+Ohai.plugin(:Network) do
+ provides "network", "network/interfaces"
+ provides "counters/network", "counters/network/interfaces"
provides "ipaddress", "ip6address", "macaddress"
def encaps_lookup(encap)
@@ -34,6 +33,8 @@ Ohai.plugin do
end
collect_data do
+ require 'ipaddr'
+
iface = Mash.new
net_counters = Mash.new
diff --git a/lib/ohai/plugins/linux/platform.rb b/lib/ohai/plugins/linux/platform.rb
index 85450560..8d77a491 100644
--- a/lib/ohai/plugins/linux/platform.rb
+++ b/lib/ohai/plugins/linux/platform.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Platform) do
provides "platform", "platform_version", "platform_family"
- depends 'linux::lsb'
+ depends "lsb"
def get_redhatish_platform(contents)
contents[/^Red Hat/i] ? "redhat" : contents[/(\w+)/i, 1].downcase
@@ -29,7 +29,7 @@ Ohai.plugin do
contents[/Rawhide/i] ? contents[/((\d+) \(Rawhide\))/i, 1].downcase : contents[/release ([\d\.]+)/, 1]
end
- collect_data do
+ collect_data(:linux) do
# platform [ and platform_version ? ] should be lower case to avoid dealing with RedHat/Redhat/redhat matching
if File.exists?("/etc/oracle-release")
contents = File.read("/etc/oracle-release").chomp
@@ -99,7 +99,6 @@ Ohai.plugin do
platform_version lsb[:release]
end
-
case platform
when /debian/, /ubuntu/, /linuxmint/, /raspbian/, /gcel/
platform_family "debian"
diff --git a/lib/ohai/plugins/linux/ps.rb b/lib/ohai/plugins/linux/ps.rb
deleted file mode 100644
index 013c1eb0..00000000
--- a/lib/ohai/plugins/linux/ps.rb
+++ /dev/null
@@ -1,27 +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 "command/ps"
-
- depends 'command'
-
- collect_data do
- command[:ps] = 'ps -ef'
- end
-end
diff --git a/lib/ohai/plugins/linux/uptime.rb b/lib/ohai/plugins/linux/uptime.rb
deleted file mode 100644
index d2ecdb1e..00000000
--- a/lib/ohai/plugins/linux/uptime.rb
+++ /dev/null
@@ -1,29 +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 "uptime", "idletime", "uptime_seconds", "idletime_seconds"
-
- collect_data do
- uptime, idletime = File.open("/proc/uptime").gets.split(" ")
- uptime_seconds uptime.to_i
- uptime seconds_to_human(uptime.to_i)
- idletime_seconds idletime.to_i
- idletime seconds_to_human(idletime.to_i)
- end
-end
diff --git a/lib/ohai/plugins/linux/virtualization.rb b/lib/ohai/plugins/linux/virtualization.rb
index 6a88aa5a..95b57ef4 100644
--- a/lib/ohai/plugins/linux/virtualization.rb
+++ b/lib/ohai/plugins/linux/virtualization.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Virtualization) do
provides "virtualization"
- collect_data do
+ collect_data(:linux) do
virtualization Mash.new
# if it is possible to detect paravirt vs hardware virt, it should be put in
diff --git a/lib/ohai/plugins/lua.rb b/lib/ohai/plugins/lua.rb
index fb7a4325..0b1a269d 100644
--- a/lib/ohai/plugins/lua.rb
+++ b/lib/ohai/plugins/lua.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Lua) do
provides "languages/lua"
depends "languages"
diff --git a/lib/ohai/plugins/mono.rb b/lib/ohai/plugins/mono.rb
index b51bd7e0..8a458bf1 100644
--- a/lib/ohai/plugins/mono.rb
+++ b/lib/ohai/plugins/mono.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Mono) do
provides "languages/mono"
depends "languages"
diff --git a/lib/ohai/plugins/netbsd/cpu.rb b/lib/ohai/plugins/netbsd/cpu.rb
index fbced143..1b0a2667 100644
--- a/lib/ohai/plugins/netbsd/cpu.rb
+++ b/lib/ohai/plugins/netbsd/cpu.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:CPU) do
provides 'cpu'
- collect_data do
+ collect_data(:netbsd) do
cpuinfo = Mash.new
# NetBSD provides some cpu information via sysctl, and a little via dmesg.boot
diff --git a/lib/ohai/plugins/netbsd/filesystem.rb b/lib/ohai/plugins/netbsd/filesystem.rb
index 225b8ef4..89a715b6 100644
--- a/lib/ohai/plugins/netbsd/filesystem.rb
+++ b/lib/ohai/plugins/netbsd/filesystem.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Filesystem) do
provides "filesystem"
- collect_data do
+ collect_data(:netbsd) do
fs = Mash.new
# Grab filesystem data from df
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/netbsd/kernel.rb b/lib/ohai/plugins/netbsd/kernel.rb
deleted file mode 100644
index 4da3c229..00000000
--- a/lib/ohai/plugins/netbsd/kernel.rb
+++ /dev/null
@@ -1,39 +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 "kernel"
-
- collect_data do
- kernel[:os] = kernel[:name]
- so = shell_out("sysctl kern.securelevel")
-
- # regex modified based on sample data in the test
- kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel:\ (.+)$/ }
- mod = Mash.new
- so = shell_out("#{ Ohai.abs_path( "/usr/bin/modstat" )}")
- so.stdout.lines do |line|
- # 1 7 0xc0400000 97f830 kernel
- if line =~ /(\d+)\s+(\d+)\s+([0-9a-fx]+)\s+([0-9a-fx]+)\s+([a-zA-Z0-9\_]+)/
- mod[$5] = { :size => $4, :refcount => $2 }
- end
- end
-
- kernel[:modules] = mod unless mod.empty?
- end
-end
diff --git a/lib/ohai/plugins/netbsd/memory.rb b/lib/ohai/plugins/netbsd/memory.rb
index 1326b983..02ddcf5c 100644
--- a/lib/ohai/plugins/netbsd/memory.rb
+++ b/lib/ohai/plugins/netbsd/memory.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Memory) do
provides "memory"
- collect_data do
+ collect_data(:netbsd) do
memory Mash.new
memory[:swap] = Mash.new
diff --git a/lib/ohai/plugins/netbsd/network.rb b/lib/ohai/plugins/netbsd/network.rb
index e418995f..8f0cff56 100644
--- a/lib/ohai/plugins/netbsd/network.rb
+++ b/lib/ohai/plugins/netbsd/network.rb
@@ -16,10 +16,11 @@
# limitations under the License.
#
-Ohai.plugin do
- provides "network", "counters/network"
+Ohai.plugin(:Network) do
+ provides "network", "network/interfaces"
+ provides "counters/network", "counters/network/interfaces"
- collect_data do
+ collect_data(:netbsd) do
network Mash.new unless network
network[:interfaces] = Mash.new unless network[:interfaces]
counters Mash.new unless counters
diff --git a/lib/ohai/plugins/netbsd/platform.rb b/lib/ohai/plugins/netbsd/platform.rb
index 0bfaee77..9293787b 100644
--- a/lib/ohai/plugins/netbsd/platform.rb
+++ b/lib/ohai/plugins/netbsd/platform.rb
@@ -16,13 +16,14 @@
# limitations under the License.
#
-Ohai.plugin do
- provides "platform", "platform_version"
+Ohai.plugin(:Platform) do
+ provides "platform", "platform_version", "platform_family"
- collect_data do
+ collect_data(:netbsd) do
so = shell_out("uname -s")
platform so.stdout.split($/)[0].downcase
so = shell_out("uname -r")
platform_version so.stdout.split($/)[0]
+ platform_family "netbsd"
end
end
diff --git a/lib/ohai/plugins/netbsd/ps.rb b/lib/ohai/plugins/netbsd/ps.rb
deleted file mode 100644
index d0f0fe0b..00000000
--- a/lib/ohai/plugins/netbsd/ps.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 "command/ps"
-
- depends 'command'
-
- collect_data do
- # ps -e requires procfs
- command[:ps] = 'ps -ax'
- end
-end
diff --git a/lib/ohai/plugins/netbsd/uptime.rb b/lib/ohai/plugins/netbsd/uptime.rb
deleted file mode 100644
index db05656f..00000000
--- a/lib/ohai/plugins/netbsd/uptime.rb
+++ /dev/null
@@ -1,33 +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 "uptime", "uptime_seconds"
-
- # kern.boottime: { sec = 1232765114, usec = 823118 } Fri Jan 23 18:45:14 2009
-
- collect_data do
- so = shell_out("#{ Ohai.abs_path( "/sbin/sysctl" )} kern.boottime")
- so.stdout.lines do |line|
- if line =~ /kern.boottime:\D+(\d+)/
- uptime_seconds Time.new.to_i - $1.to_i
- uptime seconds_to_human(uptime_seconds)
- end
- end
- end
-end
diff --git a/lib/ohai/plugins/netbsd/virtualization.rb b/lib/ohai/plugins/netbsd/virtualization.rb
index d9534e94..d2fabf25 100644
--- a/lib/ohai/plugins/netbsd/virtualization.rb
+++ b/lib/ohai/plugins/netbsd/virtualization.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Virtualization) do
provides "virtualization"
- collect_data do
+ collect_data(:netbsd) do
virtualization Mash.new
# KVM Host support for FreeBSD is in development
diff --git a/lib/ohai/plugins/network.rb b/lib/ohai/plugins/network.rb
index 3a679103..b32c6fa4 100644
--- a/lib/ohai/plugins/network.rb
+++ b/lib/ohai/plugins/network.rb
@@ -18,12 +18,10 @@
require 'ipaddress'
-Ohai.plugin do
- provides "network", "counters/network"
+Ohai.plugin(:NetworkAddresses) do
provides "ipaddress", "ip6address", "macaddress"
- depends "hostname"
- depends_os "network"
+ depends "network/interfaces"
FAMILIES = {
"inet" => "default",
diff --git a/lib/ohai/plugins/network_listeners.rb b/lib/ohai/plugins/network_listeners.rb
index 6f97399f..fcfcf0ba 100644
--- a/lib/ohai/plugins/network_listeners.rb
+++ b/lib/ohai/plugins/network_listeners.rb
@@ -16,16 +16,15 @@
# limitations under the License.
#
-require 'sigar'
-
-Ohai.plugin do
+Ohai.plugin(:NetworkListeners) do
provides "network/listeners"
depends "network", "counters/network"
- flags = Sigar::NETCONN_TCP|Sigar::NETCONN_SERVER
+ collect_data(:aix, :hpux, :sigar) do
+ require 'sigar'
+ flags = Sigar::NETCONN_TCP|Sigar::NETCONN_SERVER
- collect_data do
network Mash.new unless network
listeners = Mash.new
diff --git a/lib/ohai/plugins/nodejs.rb b/lib/ohai/plugins/nodejs.rb
index 42c8ae44..1ceef91e 100644
--- a/lib/ohai/plugins/nodejs.rb
+++ b/lib/ohai/plugins/nodejs.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Nodejs) do
provides "languages/nodejs"
depends "languages"
diff --git a/lib/ohai/plugins/ohai.rb b/lib/ohai/plugins/ohai.rb
index 97092ab5..ca01e21e 100644
--- a/lib/ohai/plugins/ohai.rb
+++ b/lib/ohai/plugins/ohai.rb
@@ -16,15 +16,15 @@
# limitations under the License.
#
-require "ohai"
-
-Ohai.plugin do
- provides "ohai"
+Ohai.plugin(:Ohai) do
+ provides "chef_packages/ohai"
collect_data do
- self[:chef_packages] = Mash.new unless self[:chef_packages]
- self[:chef_packages][:ohai] = Mash.new
- self[:chef_packages][:ohai][:version] = Ohai::VERSION
- self[:chef_packages][:ohai][:ohai_root] = Ohai::OHAI_ROOT
+ require 'ohai'
+
+ chef_packages Mash.new unless chef_packages
+ chef_packages[:ohai] = Mash.new
+ chef_packages[:ohai][:version] = Ohai::VERSION
+ chef_packages[:ohai][:ohai_root] = Ohai::OHAI_ROOT
end
end
diff --git a/lib/ohai/plugins/ohai_time.rb b/lib/ohai/plugins/ohai_time.rb
index 6afb6860..9867ec7f 100644
--- a/lib/ohai/plugins/ohai_time.rb
+++ b/lib/ohai/plugins/ohai_time.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:OhaiTime) do
provides "ohai_time"
collect_data do
diff --git a/lib/ohai/plugins/openbsd/cpu.rb b/lib/ohai/plugins/openbsd/cpu.rb
index ed69db61..91af3fe6 100644
--- a/lib/ohai/plugins/openbsd/cpu.rb
+++ b/lib/ohai/plugins/openbsd/cpu.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:CPU) do
provides 'cpu'
- collect_data do
+ collect_data(:openbsd) do
cpuinfo = Mash.new
# OpenBSD provides most cpu information via sysctl, the only thing we need to
diff --git a/lib/ohai/plugins/openbsd/filesystem.rb b/lib/ohai/plugins/openbsd/filesystem.rb
index 225b8ef4..aa33f9b2 100644
--- a/lib/ohai/plugins/openbsd/filesystem.rb
+++ b/lib/ohai/plugins/openbsd/filesystem.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Filesystem) do
provides "filesystem"
- collect_data do
+ collect_data(:openbsd) do
fs = Mash.new
# Grab filesystem data from df
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/openbsd/kernel.rb b/lib/ohai/plugins/openbsd/kernel.rb
deleted file mode 100644
index bc41f620..00000000
--- a/lib/ohai/plugins/openbsd/kernel.rb
+++ /dev/null
@@ -1,40 +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 "kernel"
-
- collect_data do
- kernel[:os] = kernel[:name]
- so = shell_out("sysctl kern.securelevel")
-
- #modified regex to fit sample data
- kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel:\ (.+)$/ }
-
- mod = Mash.new
- so = shell_out("#{ Ohai.abs_path( "/usr/bin/modstat" )}")
- so.stdout.lines do |line|
- # 1 7 0xc0400000 97f830 kernel
- if line =~ /(\d+)\s+(\d+)\s+([0-9a-fx]+)\s+([0-9a-fx]+)\s+([a-zA-Z0-9\_]+)/
- mod[$5] = { :size => $4, :refcount => $2 }
- end
- end
-
- kernel[:modules] = mod unless mod.empty?
- end
-end
diff --git a/lib/ohai/plugins/openbsd/memory.rb b/lib/ohai/plugins/openbsd/memory.rb
index 8951da08..3ad60fbc 100644
--- a/lib/ohai/plugins/openbsd/memory.rb
+++ b/lib/ohai/plugins/openbsd/memory.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
- provides "memory"
+Ohai.plugin(:Memory) do
+ provides "memory", "memory/swap"
- collect_data do
+ collect_data(:openbsd) do
memory Mash.new
memory[:swap] = Mash.new
diff --git a/lib/ohai/plugins/openbsd/network.rb b/lib/ohai/plugins/openbsd/network.rb
index d802f338..a19c4f1e 100644
--- a/lib/ohai/plugins/openbsd/network.rb
+++ b/lib/ohai/plugins/openbsd/network.rb
@@ -16,10 +16,11 @@
# limitations under the License.
#
-Ohai.plugin do
- provides "network", "counters/network"
+Ohai.plugin(:Network) do
+ provides "network", "network/interfaces"
+ provides "counters/network", "counters/network/interfaces"
- collect_data do
+ collect_data(:openbsd) do
network Mash.new unless network
network[:interfaces] = Mash.new unless network[:interfaces]
counters Mash.new unless counters
diff --git a/lib/ohai/plugins/openbsd/platform.rb b/lib/ohai/plugins/openbsd/platform.rb
index 0bfaee77..a99cf7a5 100644
--- a/lib/ohai/plugins/openbsd/platform.rb
+++ b/lib/ohai/plugins/openbsd/platform.rb
@@ -16,13 +16,14 @@
# limitations under the License.
#
-Ohai.plugin do
- provides "platform", "platform_version"
+Ohai.plugin(:Platform) do
+ provides "platform", "platform_version", "platform_family"
- collect_data do
+ collect_data(:openbsd) do
so = shell_out("uname -s")
platform so.stdout.split($/)[0].downcase
so = shell_out("uname -r")
platform_version so.stdout.split($/)[0]
+ platform_family "openbsd"
end
end
diff --git a/lib/ohai/plugins/openbsd/ps.rb b/lib/ohai/plugins/openbsd/ps.rb
deleted file mode 100644
index 8bde6414..00000000
--- a/lib/ohai/plugins/openbsd/ps.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 "command/ps"
-
- depends 'command'
-
- collect_data do
- # ps -e requires procfs
- command[:ps] = 'ps -ax'
- end
-end
diff --git a/lib/ohai/plugins/openbsd/uptime.rb b/lib/ohai/plugins/openbsd/uptime.rb
deleted file mode 100644
index 48f71908..00000000
--- a/lib/ohai/plugins/openbsd/uptime.rb
+++ /dev/null
@@ -1,33 +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 "uptime", "uptime_seconds"
-
- # kern.boottime=Tue Nov 1 14:45:52 2011
-
- collect_data do
- so = shell_out("#{ Ohai.abs_path( "/sbin/sysctl" )} kern.boottime")
- so.stdout.lines do |line|
- if line =~ /kern.boottime=(.+)/
- uptime_seconds Time.new.to_i - Time.parse($1).to_i
- uptime seconds_to_human(uptime_seconds)
- end
- end
- end
-end
diff --git a/lib/ohai/plugins/openbsd/virtualization.rb b/lib/ohai/plugins/openbsd/virtualization.rb
index 142fa648..45715887 100644
--- a/lib/ohai/plugins/openbsd/virtualization.rb
+++ b/lib/ohai/plugins/openbsd/virtualization.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Virtualization) do
provides "virtualization"
- collect_data do
+ collect_data(:openbsd) do
virtualization Mash.new
# KVM Host support for FreeBSD is in development
diff --git a/lib/ohai/plugins/openstack.rb b/lib/ohai/plugins/openstack.rb
index 10c23433..afe14a1a 100644
--- a/lib/ohai/plugins/openstack.rb
+++ b/lib/ohai/plugins/openstack.rb
@@ -18,7 +18,7 @@
require 'ohai/mixin/ec2_metadata'
extend Ohai::Mixin::Ec2Metadata
-Ohai.plugin do
+Ohai.plugin(:Openstack) do
provides "openstack"
# does it matter that it's not hitting latest?
diff --git a/lib/ohai/plugins/os.rb b/lib/ohai/plugins/os.rb
index 860475ee..2a9e7d5b 100644
--- a/lib/ohai/plugins/os.rb
+++ b/lib/ohai/plugins/os.rb
@@ -16,9 +16,9 @@
# limitations under the License.
#
-require 'ohai/os'
+require 'ohai/mixin/os'
-Ohai.plugin do
+Ohai.plugin(:OS) do
provides "os", "os_version"
depends 'kernel'
diff --git a/lib/ohai/plugins/passwd.rb b/lib/ohai/plugins/passwd.rb
index fd7d0500..397b15c6 100644
--- a/lib/ohai/plugins/passwd.rb
+++ b/lib/ohai/plugins/passwd.rb
@@ -1,7 +1,7 @@
require 'etc'
-Ohai.plugin do
+Ohai.plugin(:Passwd) do
provides 'etc', 'current_user'
def fix_encoding(str)
diff --git a/lib/ohai/plugins/perl.rb b/lib/ohai/plugins/perl.rb
index 3b4b3282..30bd6e1a 100644
--- a/lib/ohai/plugins/perl.rb
+++ b/lib/ohai/plugins/perl.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Perl) do
provides "languages/perl"
depends "languages"
diff --git a/lib/ohai/plugins/php.rb b/lib/ohai/plugins/php.rb
index 3cdb3543..7489b52f 100644
--- a/lib/ohai/plugins/php.rb
+++ b/lib/ohai/plugins/php.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:PHP) do
provides "languages/php"
depends "languages"
diff --git a/lib/ohai/plugins/platform.rb b/lib/ohai/plugins/platform.rb
index 5d5a935e..07d8246e 100644
--- a/lib/ohai/plugins/platform.rb
+++ b/lib/ohai/plugins/platform.rb
@@ -16,16 +16,13 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Platform) do
provides "platform", "platform_version", "platform_family"
+ depends "os", "os_version"
- depends_os "platform"
-
- collect_data do
+ collect_data(:default) do
platform os unless attribute?("platform")
-
platform_version os_version unless attribute?("platform_version")
-
platform_family platform unless attribute?("platform_family")
end
end
diff --git a/lib/ohai/plugins/aix/ps.rb b/lib/ohai/plugins/ps.rb
index 51e4e44f..ac0ee07d 100644
--- a/lib/ohai/plugins/aix/ps.rb
+++ b/lib/ohai/plugins/ps.rb
@@ -1,6 +1,8 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
+# Author:: Bryan McLellan (<btm@loftninjas.org>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
+# Copyright:: Copyright (c) 2009 Bryan McLellan
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -11,17 +13,22 @@
#
# 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.
+# 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
+Ohai.plugin(:PS) do
provides "command/ps"
+ depends "command"
- depends 'command'
-
- collect_data do
+ collect_data(:aix, :darwin, :hpux, :linux, :solaris2) do
command[:ps] = 'ps -ef'
end
+
+ collect_data(:freebsd, :netbsd, :openbsd) do
+ # ps -e requires procfs
+ command[:ps] = 'ps -ax'
+ end
end
diff --git a/lib/ohai/plugins/python.rb b/lib/ohai/plugins/python.rb
index b551a661..683042ba 100644
--- a/lib/ohai/plugins/python.rb
+++ b/lib/ohai/plugins/python.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Python) do
provides "languages/python"
depends "languages"
diff --git a/lib/ohai/plugins/rackspace.rb b/lib/ohai/plugins/rackspace.rb
index 8f113611..b96ebdf9 100644
--- a/lib/ohai/plugins/rackspace.rb
+++ b/lib/ohai/plugins/rackspace.rb
@@ -14,11 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-Ohai.plugin do
+Ohai.plugin(:Rackspace) do
provides "rackspace"
- depends "kernel"
- depends "network", "counters/network"
+ depends "kernel", "network/interfaces"
# Checks for matching rackspace kernel name
#
diff --git a/lib/ohai/plugins/root_group.rb b/lib/ohai/plugins/root_group.rb
index 212e4e05..1e5145e9 100644
--- a/lib/ohai/plugins/root_group.rb
+++ b/lib/ohai/plugins/root_group.rb
@@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-Ohai.plugin do
+Ohai.plugin(:RootGroup) do
provides 'root_group'
collect_data do
diff --git a/lib/ohai/plugins/ruby.rb b/lib/ohai/plugins/ruby.rb
index 13c94bcb..bbb08397 100644
--- a/lib/ohai/plugins/ruby.rb
+++ b/lib/ohai/plugins/ruby.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Ruby) do
provides "languages/ruby"
depends "languages"
diff --git a/lib/ohai/plugins/sigar/cpu.rb b/lib/ohai/plugins/sigar/cpu.rb
index 66d09609..c61da5a0 100644
--- a/lib/ohai/plugins/sigar/cpu.rb
+++ b/lib/ohai/plugins/sigar/cpu.rb
@@ -16,12 +16,12 @@
# limitations under the License.
#
-require "sigar"
-
-Ohai.plugin do
+Ohai.plugin(:CPU) do
provides "cpu"
- collect_data do
+ collect_data(:aix, :hpux, :sigar) do
+ require 'sigar'
+
sigar = Sigar.new
cpuinfo = Mash.new
diff --git a/lib/ohai/plugins/sigar/filesystem.rb b/lib/ohai/plugins/sigar/filesystem.rb
index 603b4892..e243c4ce 100644
--- a/lib/ohai/plugins/sigar/filesystem.rb
+++ b/lib/ohai/plugins/sigar/filesystem.rb
@@ -16,16 +16,15 @@
# limitations under the License.
#
-require "sigar"
-
-Ohai.plugin do
+Ohai.plugin(:Filesystem) do
provides "filesystem"
- collect_data do
- fs = Mash.new
-
+ collect_data(:aix, :hpux, :sigar) do
+ require "sigar"
sigar = Sigar.new
+ fs = Mash.new
+
sigar.file_system_list.each do |fsys|
filesystem = fsys.dev_name
fs[filesystem] = Mash.new
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/sigar/memory.rb b/lib/ohai/plugins/sigar/memory.rb
index 95daef24..7390cac5 100644
--- a/lib/ohai/plugins/sigar/memory.rb
+++ b/lib/ohai/plugins/sigar/memory.rb
@@ -16,12 +16,11 @@
# limitations under the License.
#
-require "sigar"
-
-Ohai.plugin do
+Ohai.plugin(:Memory) do
provides "memory"
- collect_data do
+ collect_data(:aix, :hpux, :sigar) do
+ require "sigar"
sigar = Sigar.new
memory Mash.new
diff --git a/lib/ohai/plugins/sigar/network.rb b/lib/ohai/plugins/sigar/network.rb
index b683986c..a6029ac3 100644
--- a/lib/ohai/plugins/sigar/network.rb
+++ b/lib/ohai/plugins/sigar/network.rb
@@ -18,10 +18,9 @@
#http://github.com/mdkent/ohai/commit/92f51aa18b6add9682510a87dcf94835ea72b04d
-require "sigar"
-
-Ohai.plugin do
- provides "network", "counters/network"
+Ohai.plugin(:Network) do
+ provides "network", "network/interfaces"
+ provides "counters/network", "counters/network/interfaces"
def encaps_lookup(encap)
return "Loopback" if encap.eql?("Local Loopback")
@@ -33,31 +32,21 @@ Ohai.plugin do
encap
end
- collect_data do
- sigar = Sigar.new
- network Mash.new unless network
- network[:interfaces] = Mash.new unless network[:interfaces]
- counters Mash.new unless counters
- counters[:network] = Mash.new unless counters[:network]
-
- ninfo = sigar.net_info
-
- network[:default_interface] = ninfo.default_gateway_interface
-
- network[:default_gateway] = ninfo.default_gateway
-
+ def fetch_interfaces(sigar)
iface = Mash.new
-
net_counters = Mash.new
sigar.net_interface_list.each do |cint|
iface[cint] = Mash.new
+
if cint =~ /^(\w+)(\d+.*)/
iface[cint][:type] = $1
iface[cint][:number] = $2
end
+
ifconfig = sigar.net_interface_config(cint)
iface[cint][:encapsulation] = encaps_lookup(ifconfig.type)
+
iface[cint][:addresses] = Mash.new
# Backwards compat: loopback has no hwaddr
if (ifconfig.flags & Sigar::IFF_LOOPBACK) == 0
@@ -72,14 +61,17 @@ Ohai.plugin do
end
iface[cint][:addresses][ifconfig.address]["netmask"] = ifconfig.netmask
end
- iface[cint][:flags] = Sigar.net_interface_flags_to_s(ifconfig.flags).split(' ')
- iface[cint][:mtu] = ifconfig.mtu.to_s
- iface[cint][:queuelen] = ifconfig.tx_queue_len.to_s
+
if ifconfig.prefix6_length != 0
iface[cint][:addresses][ifconfig.address6] = { "family" => "inet6" }
iface[cint][:addresses][ifconfig.address6]["prefixlen"] = ifconfig.prefix6_length.to_s
iface[cint][:addresses][ifconfig.address6]["scope"] = Sigar.net_scope_to_s(ifconfig.scope6)
end
+
+ iface[cint][:flags] = Sigar.net_interface_flags_to_s(ifconfig.flags).split(' ')
+ iface[cint][:mtu] = ifconfig.mtu.to_s
+ iface[cint][:queuelen] = ifconfig.tx_queue_len.to_s
+
net_counters[cint] = Mash.new unless net_counters[cint]
if (!cint.include?(":"))
ifstat = sigar.net_interface_stat(cint)
@@ -103,8 +95,75 @@ Ohai.plugin do
#64-bit AIX for example requires 64-bit caller
end
- counters[:network][:interfaces] = net_counters
+ [iface, net_counters]
+ end
+ # sigar-only, from network_route plugin
+ def flags(flags)
+ f = ""
+ if (flags & Sigar::RTF_UP) != 0
+ f += "U"
+ end
+ if (flags & Sigar::RTF_GATEWAY) != 0
+ f += "G"
+ end
+ if (flags & Sigar::RTF_HOST) != 0
+ f += "H"
+ end
+ f
+ end
+
+ # From sigar: include/sigar.h sigar_net_route_t
+ SIGAR_ROUTE_METHODS = [:destination, :gateway, :mask, :flags, :refcnt, :use, :metric, :mtu, :window, :irtt, :ifname]
+
+ collect_data(:aix, :hpux) do
+ require "sigar"
+ sigar = Sigar.new
+
+ network Mash.new unless network
+ network[:interfaces] = Mash.new unless network[:interfaces]
+ counters Mash.new unless counters
+ counters[:network] = Mash.new unless counters[:network]
+
+ ninfo = sigar.net_info
+ network[:default_interface] = ninfo.default_gateway_interface
+ network[:default_gateway] = ninfo.default_gateway
+
+ iface, net_counters = fetch_interfaces(sigar)
+ counters[:network][:interfaces] = net_counters
network["interfaces"] = iface
end
+
+ collect_data(:sigar) do
+ require "sigar"
+ sigar = Sigar.new
+
+ network Mash.new unless network
+ network[:interfaces] = Mash.new unless network[:interfaces]
+ counters Mash.new unless counters
+ counters[:network] = Mash.new unless counters[:network]
+
+ ninfo = sigar.net_info
+ network[:default_interface] = ninfo.default_gateway_interface
+ network[:default_gateway] = ninfo.default_gateway
+
+ iface, net_counters = fetch_interfaces(sigar)
+ counters[:network][:interfaces] = net_counters
+ network[:interfaces] = iface
+
+ sigar.net_route_list.each do |route|
+ next unless network[:interfaces][route.ifname] # this
+ # should never happen
+ network[:interfaces][route.ifname][:route] = Mash.new unless network[:interfaces][route.ifname][:route]
+ route_data={}
+ SIGAR_ROUTE_METHODS.each do |m|
+ if(m == :flags)
+ route_data[m]=flags(route.send(m))
+ else
+ route_data[m]=route.send(m)
+ end
+ end
+ network[:interfaces][route.ifname][:route][route.destination] = route_data
+ end
+ end
end
diff --git a/lib/ohai/plugins/sigar/network_route.rb b/lib/ohai/plugins/sigar/network_route.rb
index 022112db..d06352aa 100644
--- a/lib/ohai/plugins/sigar/network_route.rb
+++ b/lib/ohai/plugins/sigar/network_route.rb
@@ -19,8 +19,6 @@
require "sigar"
Ohai.plugin do
- depends "network"
-
provides "network"
def flags(flags)
@@ -40,12 +38,9 @@ Ohai.plugin do
# From sigar: include/sigar.h sigar_net_route_t
SIGAR_ROUTE_METHODS = [:destination, :gateway, :mask, :flags, :refcnt, :use, :metric, :mtu, :window, :irtt, :ifname]
- collect_data do
- sigar=Sigar.new
- network Mash.new unless network
- network[:interfaces] = Mash.new unless network[:interfaces]
- counters Mash.new unless counters
- counters[:network] = Mash.new unless counters[:network]
+ collect_data(:sigar) do
+ require "sigar"
+ sigar = Sigar.new
sigar.net_route_list.each do |route|
next unless network[:interfaces][route.ifname] # this should never happen
diff --git a/lib/ohai/plugins/sigar/platform.rb b/lib/ohai/plugins/sigar/platform.rb
index cbdf283e..c90a4115 100644
--- a/lib/ohai/plugins/sigar/platform.rb
+++ b/lib/ohai/plugins/sigar/platform.rb
@@ -16,15 +16,15 @@
# limitations under the License.
#
-require "sigar"
+Ohai.plugin(:Platform) do
+ provides "platform", "platform_version", "platform_family"
-Ohai.plugin do
- provides "platform", "platform_version"
-
- collect_data do
+ collect_data(:aix, :hpux, :sigar) do
+ require "sigar"
sys = Sigar.new.sys_info
platform sys.name.downcase
platform_version sys.version
+ platform_family platform
end
end
diff --git a/lib/ohai/plugins/sigar/uptime.rb b/lib/ohai/plugins/sigar/uptime.rb
deleted file mode 100644
index d1beca2c..00000000
--- a/lib/ohai/plugins/sigar/uptime.rb
+++ /dev/null
@@ -1,30 +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 "uptime", "uptime_seconds"
-
- collect_data do
- sigar = Sigar.new
- uptime = sigar.uptime.uptime
- uptime_seconds uptime.to_i * 1000
- uptime seconds_to_human(uptime.to_i)
- end
-end
diff --git a/lib/ohai/plugins/solaris2/cpu.rb b/lib/ohai/plugins/solaris2/cpu.rb
index a2340580..9900cd48 100644
--- a/lib/ohai/plugins/solaris2/cpu.rb
+++ b/lib/ohai/plugins/solaris2/cpu.rb
@@ -14,10 +14,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:CPU) do
provides "cpu"
- collect_data do
+ collect_data(:solaris2) do
cpu Mash.new
cpu[:total] = shell_out("psrinfo | wc -l").stdout.to_i
cpu[:real] = shell_out("psrinfo -p").stdout.to_i
diff --git a/lib/ohai/plugins/solaris2/dmi.rb b/lib/ohai/plugins/solaris2/dmi.rb
index c3010771..8308bc78 100644
--- a/lib/ohai/plugins/solaris2/dmi.rb
+++ b/lib/ohai/plugins/solaris2/dmi.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:DMI) do
depends "dmi"
- collect_data do
+ collect_data(:solaris2) do
# if we already have a "dmi" with keys (presumably from dmidecode), don't try smbios
# note that a single key just means dmidecode exited with its version
if (dmi.class.to_s == 'Mash') and (dmi.keys.length > 1)
diff --git a/lib/ohai/plugins/solaris2/filesystem.rb b/lib/ohai/plugins/solaris2/filesystem.rb
index 0d73ff4b..2bf5e505 100644
--- a/lib/ohai/plugins/solaris2/filesystem.rb
+++ b/lib/ohai/plugins/solaris2/filesystem.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Filesystem) do
provides "filesystem"
- collect_data do
+ collect_data(:solaris2) do
fs = Mash.new
# Grab filesystem data from df
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/solaris2/kernel.rb b/lib/ohai/plugins/solaris2/kernel.rb
deleted file mode 100644
index 9e14f458..00000000
--- a/lib/ohai/plugins/solaris2/kernel.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-#
-# Author:: Benjamin Black (<nostromo@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.
-#
-
-Ohai.plugin do
- provides "kernel/os"
-
- collect_data do
- so = shell_out("uname -s")
- kernel[:os] = so.stdout.split($/)[0]
-
- modules = Mash.new
-
- so = shell_out("modinfo")
- # EXAMPLE:
- # Id Loadaddr Size Info Rev Module Name
- # 6 1180000 4623 1 1 specfs (filesystem for specfs)
- module_description = /[\s]*([\d]+)[\s]+([a-f\d]+)[\s]+([a-f\d]+)[\s]+(?:[\-\d]+)[\s]+(?:[\d]+)[\s]+([\S]+)[\s]+\((.+)\)$/
- so.stdout.lines do |line|
- if mod = module_description.match(line)
- modules[mod[4]] = { :id => mod[1].to_i, :loadaddr => mod[2], :size => mod[3].to_i(16), :description => mod[5]}
- end
- end
-
- kernel[:modules] = modules
- end
-end
diff --git a/lib/ohai/plugins/solaris2/memory.rb b/lib/ohai/plugins/solaris2/memory.rb
index d43c0e06..0b8ec0c7 100644
--- a/lib/ohai/plugins/solaris2/memory.rb
+++ b/lib/ohai/plugins/solaris2/memory.rb
@@ -14,10 +14,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Memory) do
provides "memory"
- collect_data do
+ collect_data(:solaris2) do
memory Mash.new
memory[:total] = shell_out("prtconf -m").stdout.to_i
end
diff --git a/lib/ohai/plugins/solaris2/network.rb b/lib/ohai/plugins/solaris2/network.rb
index 2cf3907d..6a69b4a6 100644
--- a/lib/ohai/plugins/solaris2/network.rb
+++ b/lib/ohai/plugins/solaris2/network.rb
@@ -53,10 +53,9 @@
# srcof qfe1
# inet6 fe80::203:baff:fe17:4444/128
-require 'scanf'
-
-Ohai.plugin do
- provides "network"
+Ohai.plugin(:Network) do
+ provides "network", "network/interfaces"
+ provides "counters/network", "counters/network/interfaces"
def encaps_lookup(ifname)
return "Ethernet" if ifname.eql?("e1000g")
@@ -74,7 +73,9 @@ Ohai.plugin do
nil
end
- collect_data do
+ collect_data(:solaris2) do
+ require 'scanf'
+
iface = Mash.new
network Mash.new unless network
network[:interfaces] = Mash.new unless network[:interfaces]
diff --git a/lib/ohai/plugins/solaris2/platform.rb b/lib/ohai/plugins/solaris2/platform.rb
index a9172fcd..ea10e7a8 100644
--- a/lib/ohai/plugins/solaris2/platform.rb
+++ b/lib/ohai/plugins/solaris2/platform.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
- provides "platform", "platform_version", "platform_build"
+Ohai.plugin(:Platform) do
+ provides "platform", "platform_version", "platform_build", "platform_family"
- collect_data do
+ collect_data(:solaris2) do
if File.exists?("/sbin/uname")
uname_exec = "/sbin/uname"
else
@@ -59,5 +59,7 @@ Ohai.plugin do
end
end
end
+
+ platform_family platform
end
end
diff --git a/lib/ohai/plugins/solaris2/ps.rb b/lib/ohai/plugins/solaris2/ps.rb
deleted file mode 100644
index 51e4e44f..00000000
--- a/lib/ohai/plugins/solaris2/ps.rb
+++ /dev/null
@@ -1,27 +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 "command/ps"
-
- depends 'command'
-
- collect_data do
- command[:ps] = 'ps -ef'
- end
-end
diff --git a/lib/ohai/plugins/solaris2/uptime.rb b/lib/ohai/plugins/solaris2/uptime.rb
deleted file mode 100644
index e44632b9..00000000
--- a/lib/ohai/plugins/solaris2/uptime.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-#
-# Author:: Kurt Yoder (<ktyopscode@yoderhome.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.
-#
-require 'date'
-# It would be far better if we could include sys/uptime from sys-uptime RubyGem
-# It would also be good if we could pull idle time; how do we do this on Solaris?
-
-Ohai.plugin do
- provides "uptime", "uptime_seconds"
-
- collect_data do
- # Example output:
- # $ who -b
- # . system boot Jul 9 17:51
- so = shell_out("who -b")
- so.stdout.lines do |line|
- if line =~ /.* boot (.+)/
- uptime_seconds Time.now.to_i - DateTime.parse($1).strftime('%s').to_i
- uptime seconds_to_human(uptime_seconds)
- break
- end
- end
- end
-end
diff --git a/lib/ohai/plugins/solaris2/virtualization.rb b/lib/ohai/plugins/solaris2/virtualization.rb
index ec38fd64..af3ea7c1 100644
--- a/lib/ohai/plugins/solaris2/virtualization.rb
+++ b/lib/ohai/plugins/solaris2/virtualization.rb
@@ -18,10 +18,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Virtualization) do
provides "virtualization"
- collect_data do
+ collect_data(:solaris2) do
virtualization Mash.new
# Detect KVM/QEMU from cpuinfo, report as KVM
diff --git a/lib/ohai/plugins/solaris2/zpools.rb b/lib/ohai/plugins/solaris2/zpools.rb
index e6f6e469..f0867cd5 100644
--- a/lib/ohai/plugins/solaris2/zpools.rb
+++ b/lib/ohai/plugins/solaris2/zpools.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:Zpools) do
provides "zpools"
- collect_data do
+ collect_data(:solaris2) do
pools = Mash.new
# Grab ZFS zpools overall health and attributes
diff --git a/lib/ohai/plugins/ssh_host_key.rb b/lib/ohai/plugins/ssh_host_key.rb
index e23ab523..82d89308 100644
--- a/lib/ohai/plugins/ssh_host_key.rb
+++ b/lib/ohai/plugins/ssh_host_key.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
-Ohai.plugin do
+Ohai.plugin(:SSHHostKey) do
provides "keys/ssh"
depends "keys"
diff --git a/lib/ohai/plugins/uptime.rb b/lib/ohai/plugins/uptime.rb
index c5f9c58f..a29a0680 100644
--- a/lib/ohai/plugins/uptime.rb
+++ b/lib/ohai/plugins/uptime.rb
@@ -1,19 +1,110 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
+# Author:: Bryan McLellan (<btm@loftninjas.org>)
+# Author:: Claire McQuin (<claire@opscode.com>)
+# Author:: Doug MacEachern (<dougm@vmware.com>)
+# Author:: Kurt Yoder (<ktyopscode@yoderhome.com>)
+# Author:: Paul Mooring (<paul@opscode.com>)
+# Copyright:: Copyright (c) 2008, 2012, 2013 Opscode, Inc.
+# Copyright:: Copyright (c) 2009 Bryan McLellan
+# 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.
+# 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 'ohai/mixin/seconds_to_human'
+
+Ohai.plugin(:Uptime) do
+ provides "uptime", "uptime_seconds"
+ provides "idletime", "idletime_seconds" # linux only
+
+ def collect_uptime(path)
+ # kern.boottime: { sec = 1232765114, usec = 823118 } Fri Jan 23 18:45:14 2009
+ so = shell_out("#{Ohai.abs_path(path)} kern.boottime")
+ so.stdout.lines do |line|
+ if line =~ /kern.boottime:\D+(\d+)/
+ usec = Time.new.to_i - $1.to_i
+ return [usec, seconds_to_human(usec)]
+ end
+ end
+ return [nil, nil]
+ end
+
+ collect_data(:aix, :hpux, :sigar) do
+ require 'sigar'
+
+ sigar = Sigar.new
+ uptime = sigar.uptime.uptime
+ uptime_seconds uptime.to_i * 1000
+ uptime seconds_to_human(uptime.to_i)
+ end
+
+ collect_data(:darwin) do
+ data = collect_uptime("/usr/sbin/sysctl")
+ uptime_seconds data.first
+ uptime data.last
+ end
+
+ collect_data(:freebsd, :netbsd) do
+ data = collect_uptime("/sbin/sysctl")
+ uptime_seconds data.first
+ uptime data.last
+ end
+
+ collect_data(:linux) do
+ uptime, idletime = File.open("/proc/uptime").gets.split(" ")
+ uptime_seconds uptime.to_i
+ uptime seconds_to_human(uptime.to_i)
+ idletime_seconds idletime.to_i
+ idletime seconds_to_human(idletime.to_i)
+ end
+
+ collect_data(:openbsd) do
+ # kern.boottime=Tue Nov 1 14:45:52 2011
+ so = shell_out("#{ Ohai.abs_path( "/sbin/sysctl" )}
+ #kern.boottime")
+ so.stdout.lines do |line|
+ if line =~ /kern.boottime=(.+)/
+ uptime_seconds Time.new.to_i - Time.parse($1).to_i
+ uptime seconds_to_human(uptime_seconds)
+ end
+ end
+ end
+
+ collect_data(:solaris2) do
+ require 'date'
+
+ # Example output:
+ # $ who -b
+ # . system boot Jul 9 17:51
+ so = shell_out("who -b")
+ so.stdout.lines do |line|
+ if line =~ /.* boot (.+)/
+ uptime_seconds Time.now.to_i - DateTime.parse($1).strftime('%s').to_i
+ uptime seconds_to_human(uptime_seconds)
+ break
+ end
+ end
+ end
+
+ collect_data(:windows) do
+ require 'ruby-wmi'
+
+ uptime_seconds ::WMI::Win32_PerfFormattedData_PerfOS_System.find(:first).SystemUpTime.to_i
+ uptime seconds_to_human(uptime_seconds)
+ end
+
+end
diff --git a/lib/ohai/plugins/virtualization.rb b/lib/ohai/plugins/virtualization.rb
index 4c9a0d91..310bdeeb 100644
--- a/lib/ohai/plugins/virtualization.rb
+++ b/lib/ohai/plugins/virtualization.rb
@@ -16,10 +16,12 @@
# limitations under the License.
#
-Ohai.plugin do
- provides "virtualization"
+Ohai.plugin(:VirtualizationInfo) do
+ %w{ uri capabilities nodeinfo domains networks storage }.each do |info|
+ provides "virtualization/#{info}"
+ end
- depends_os "virtualization"
+ depends "virtualization"
collect_data do
unless virtualization.nil? || !(virtualization[:role].eql?("host"))
diff --git a/lib/ohai/plugins/windows/cpu.rb b/lib/ohai/plugins/windows/cpu.rb
index 4ffa9328..5c52a4d7 100644
--- a/lib/ohai/plugins/windows/cpu.rb
+++ b/lib/ohai/plugins/windows/cpu.rb
@@ -16,12 +16,12 @@
# limitations under the License.
#
-require 'ruby-wmi'
-
-Ohai.plugin do
+Ohai.plugin(:CPU) do
provides "cpu"
- collect_data do
+ collect_data(:windows) do
+ require 'ruby-wmi'
+
cpuinfo = Mash.new
cpu_number = 0
index = 0
diff --git a/lib/ohai/plugins/windows/filesystem.rb b/lib/ohai/plugins/windows/filesystem.rb
index 7aec0c1e..9a7e7dea 100644
--- a/lib/ohai/plugins/windows/filesystem.rb
+++ b/lib/ohai/plugins/windows/filesystem.rb
@@ -16,12 +16,12 @@
# limitations under the License.
#
-require 'ruby-wmi'
-
-Ohai.plugin do
+Ohai.plugin(:Filesystem) do
provides "filesystem"
- collect_data do
+ collect_data(:windows) do
+ require 'ruby-wmi'
+
fs = Mash.new
ld_info = Mash.new
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
diff --git a/lib/ohai/plugins/windows/kernel.rb b/lib/ohai/plugins/windows/kernel.rb
deleted file mode 100644
index a5c73167..00000000
--- a/lib/ohai/plugins/windows/kernel.rb
+++ /dev/null
@@ -1,64 +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'
-
-Ohai.plugin do
- provides "kernel"
-
- WIN32OLE.codepage = WIN32OLE::CP_UTF8
-
- def machine_lookup(sys_type)
- return "i386" if sys_type.eql?("X86-based PC")
- return "x86_64" if sys_type.eql?("x64-based PC")
- sys_type
- end
-
- def os_lookup(sys_type)
- return "Unknown" if sys_type.to_s.eql?("0")
- return "Other" if sys_type.to_s.eql?("1")
- return "MSDOS" if sys_type.to_s.eql?("14")
- return "WIN3x" if sys_type.to_s.eql?("15")
- return "WIN95" if sys_type.to_s.eql?("16")
- return "WIN98" if sys_type.to_s.eql?("17")
- return "WINNT" if sys_type.to_s.eql?("18")
- return "WINCE" if sys_type.to_s.eql?("19")
- return nil
- end
-
- collect_data do
- host = WMI::Win32_OperatingSystem.find(:first)
- kernel[:os_info] = Mash.new
- host.properties_.each do |p|
- kernel[:os_info][p.name.wmi_underscore.to_sym] = host.send(p.name)
- end
-
- kernel[:name] = "#{kernel[:os_info][:caption]}"
- kernel[:release] = "#{kernel[:os_info][:version]}"
- kernel[:version] = "#{kernel[:os_info][:version]} #{kernel[:os_info][:csd_version]} Build #{kernel[:os_info][:build_number]}"
- kernel[:os] = os_lookup(kernel[:os_info][:os_type]) || languages[:ruby][:host_os]
-
- host = WMI::Win32_ComputerSystem.find(:first)
- kernel[:cs_info] = Mash.new
- host.properties_.each do |p|
- kernel[:cs_info][p.name.wmi_underscore.to_sym] = host.send(p.name)
- end
-
- kernel[:machine] = machine_lookup("#{kernel[:cs_info][:system_type]}")
- end
-end
diff --git a/lib/ohai/plugins/windows/network.rb b/lib/ohai/plugins/windows/network.rb
index 0720672a..d1454805 100644
--- a/lib/ohai/plugins/windows/network.rb
+++ b/lib/ohai/plugins/windows/network.rb
@@ -16,17 +16,18 @@
# limitations under the License.
#
-require 'ruby-wmi'
-
-Ohai.plugin do
- provides "network"
+Ohai.plugin(:Network) do
+ provides "network", "network/interfaces"
+ provides "counters/network", "counters/network/interfaces"
def encaps_lookup(encap)
return "Ethernet" if encap.eql?("Ethernet 802.3")
encap
end
- collect_data do
+ collect_data(:windows) do
+ require 'ruby-wmi'
+
iface = Mash.new
iface_config = Mash.new
iface_instance = Mash.new
diff --git a/lib/ohai/plugins/windows/platform.rb b/lib/ohai/plugins/windows/platform.rb
index 690daa9b..2d2951c1 100644
--- a/lib/ohai/plugins/windows/platform.rb
+++ b/lib/ohai/plugins/windows/platform.rb
@@ -22,10 +22,10 @@
# platforms built upon the Windows_NT kernel and have access to win32 or win64
# subsystems.
-Ohai.plugin do
- provides "platform"
+Ohai.plugin(:Platform) do
+ provides "platform", "platform_version", "platform_family"
- collect_data do
+ collect_data (:windows)do
platform os
platform_version kernel['release']
platform_family "windows"
diff --git a/lib/ohai/plugins/windows/uptime.rb b/lib/ohai/plugins/windows/uptime.rb
deleted file mode 100644
index 59d79529..00000000
--- a/lib/ohai/plugins/windows/uptime.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-#
-# Author:: Paul Mooring (paul@opscode.com)
-# Copyright:: Copyright (c) 2012 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'
-
-Ohai.plugin do
- provides "uptime", "uptime_seconds"
-
- collect_data do
- uptime_seconds ::WMI::Win32_PerfFormattedData_PerfOS_System.find(:first).SystemUpTime.to_i
- uptime seconds_to_human(uptime_seconds)
- end
-end
diff --git a/lib/ohai/runner.rb b/lib/ohai/runner.rb
index 73e0ddce..15334e75 100644
--- a/lib/ohai/runner.rb
+++ b/lib/ohai/runner.rb
@@ -45,7 +45,7 @@ module Ohai
next if p.has_run? unless force
if visited.include?(p)
- raise DependencyCycleError, "Dependency cycle detected. Please refer to the following plugin files: #{cycle_sources(visited, p).join(", ") }"
+ raise DependencyCycleError, "Dependency cycle detected. Please refer to the following plugins: #{get_cycle(visited, p).join(", ") }"
end
dependency_providers = fetch_providers(p.dependencies)
@@ -66,11 +66,11 @@ module Ohai
attrs = @attributes
parts = attribute.split('/')
parts.each do |part|
- next if part == Ohai::OS.collect_os
+ next if part == Ohai::Mixin::OS.collect_os
raise NoAttributeError, "Cannot find plugin providing attribute \'#{attribute}\'" unless attrs[part]
attrs = attrs[part]
end
- providers << attrs[:providers]
+ providers << attrs[:_providers]
providers.flatten!
end
providers.uniq!
@@ -80,11 +80,11 @@ module Ohai
# given a list of plugins and the first plugin in the cycle,
# returns the list of plugin source files responsible for the
# cycle. does not include plugins that aren't a part of the cycle
- def cycle_sources(plugins, cycle_start)
+ def get_cycle(plugins, cycle_start)
cycle = plugins.drop_while { |plugin| !plugin.eql?(cycle_start) }
- sources = []
- cycle.each { |plugin| sources << plugin.source }
- sources
+ names = []
+ cycle.each { |plugin| names << plugin.name }
+ names
end
end
diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb
index 13279c12..37d7a87d 100644
--- a/lib/ohai/system.rb
+++ b/lib/ohai/system.rb
@@ -19,11 +19,11 @@
require 'ohai/loader'
require 'ohai/log'
require 'ohai/mash'
-require 'ohai/os'
require 'ohai/runner'
require 'ohai/dsl/plugin'
require 'ohai/mixin/from_file'
require 'ohai/mixin/command'
+require 'ohai/mixin/os'
require 'ohai/mixin/string'
require 'mixlib/shellout'
@@ -55,14 +55,14 @@ module Ohai
Ohai::Config[:plugin_path].each do |path|
[
Dir[File.join(path, '*')],
- Dir[File.join(path, Ohai::OS.collect_os, '**', '*')]
+ Dir[File.join(path, Ohai::Mixin::OS.collect_os, '**', '*')]
].flatten.each do |file|
file_regex = Regexp.new("#{File.expand_path(path)}#{File::SEPARATOR}(.+).rb$")
md = file_regex.match(file)
if md
plugin_name = md[1].gsub(File::SEPARATOR, "::")
unless @v6_dependency_solver.has_key?(plugin_name)
- plugin = @loader.load_plugin(file)
+ plugin = @loader.load_plugin(file, plugin_name)
@v6_dependency_solver[plugin_name] = plugin unless plugin.nil?
else
Ohai::Log.debug("Already loaded plugin at #{file}")
@@ -103,7 +103,7 @@ module Ohai
plugins = []
if providers.is_a?(Mash)
providers.keys.each do |provider|
- if provider.eql?("providers")
+ if provider.eql?("_providers")
plugins << providers[provider]
else
plugins << collect_providers(providers[provider])
@@ -178,7 +178,7 @@ module Ohai
Ohai::Config[:plugin_path].each do |path|
check_path = File.expand_path(File.join(path, filename))
if File.exist?(check_path)
- plugin = @loader.load_plugin(check_path)
+ plugin = @loader.load_plugin(check_path, plugin_name)
@v6_dependency_solver[plugin_name] = plugin
break
else
diff --git a/spec/ohai/dsl/plugin_spec.rb b/spec/ohai/dsl/plugin_spec.rb
index 91cf6019..4bdda824 100644
--- a/spec/ohai/dsl/plugin_spec.rb
+++ b/spec/ohai/dsl/plugin_spec.rb
@@ -1,42 +1,35 @@
#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Author:: Daniel DeLeo (<dan@opscode.com>)
-# Author:: Claire McQuin (<claire@opscode.com>)
-# Copyright:: Copyright (c) 2008, 2012, 2013 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 File.expand_path("../../../spec_helper", __FILE__)
+require File.expand_path("../../../spec_helper.rb", __FILE__)
shared_examples "Ohai::DSL::Plugin" do
- it "should save the plugin source file" do
- @plugin.source.should eql(source)
- end
+ context "#initialize" do
+ it "should save the plugin source file" do
+ plugin.source.should eql(source)
+ end
- it "should set has_run? to false" do
- @plugin.has_run?.should be_false
+ it "should set has_run? to false" do
+ plugin.has_run?.should be_false
+ end
+
+ it "should set the correct plugin version" do
+ plugin.version.should eql(version)
+ end
end
- it "should set has_run? to true after running the plugin" do
- @plugin.stub(:run_plugin).and_return(true)
- @plugin.run
- @plugin.has_run?.should be_true
+ context "#run" do
+ it "should set has_run? to true" do
+ plugin.stub(:run_plugin).and_return(true)
+ plugin.run
+ plugin.has_run?.should be_true
+ end
end
context "when accessing data via method_missing" do
- it "should take a missing method and store the method name as a key, with its arguments as values" do
+ it "should take a missing method and store the method name as a key, with its arguments as value\
+s" do
plugin.guns_n_roses("chinese democracy")
plugin.data["guns_n_roses"].should eql("chinese democracy")
end
@@ -84,176 +77,218 @@ shared_examples "Ohai::DSL::Plugin" do
end
describe Ohai::DSL::Plugin::VersionVII do
- describe "when loaded" do
- describe "#self.provides_attrs" do
- before(:all) do
- @provides_one = Ohai.plugin { provides("thing") }
- @provides_list = Ohai.plugin { provides("thing", "something", "otherthing") }
- @provides_many = Ohai.plugin { provides("list", "something"); provides("somethingelse") }
- end
+ before(:each) do
+ @name = :Test
+ end
- it "should collect a single attribute" do
- @provides_one.provides_attrs.should eql(["thing"])
- end
+ it "should log a warning when a version 6 plugin with the same name exists" do
+ name_str = @name.to_s.downcase
+ Ohai.v6plugin(name_str) { }
+ Ohai::Log.should_receive(:warn).with(/Already loaded version 6 plugin #{@name}/)
+ Ohai.plugin(@name) { }
+ end
- it "should collect a list of attributes" do
- @provides_list.provides_attrs.should eql(["thing", "something", "otherthing"])
- end
+ describe "#version" do
+ it "should save the plugin version as :version7" do
+ plugin = Ohai.plugin(@name) { }
+ plugin.version.should eql(:version7)
+ end
+ end
- it "should collect from multiple provides statements" do
- @provides_many.provides_attrs.should eql(["list", "something", "somethingelse"])
- end
+ describe "#provides" do
+ it "should collect a single attribute" do
+ plugin = Ohai.plugin(@name) { provides("one") }
+ plugin.provides_attrs.should eql(["one"])
end
- describe "#self.depends_attrs" do
- before(:all) do
- @depends_none = Ohai.plugin { }
- @depends_one = Ohai.plugin { depends("other") }
- @depends_list = Ohai.plugin { depends("on", "list") }
- @depends_many = Ohai.plugin { depends("on", "list"); depends("single") }
- end
+ it "should collect a list of attributes" do
+ plugin = Ohai.plugin(@name) { provides("one", "two", "three") }
+ plugin.provides_attrs.should eql(["one", "two", "three"])
+ end
- it "should return an empty array if no dependencies" do
- @depends_none.depends_attrs.should be_empty
- end
+ it "should collect from multiple provides statements" do
+ plugin = Ohai.plugin(@name) {
+ provides("one")
+ provides("two", "three")
+ provides("four")
+ }
+ plugin.provides_attrs.should eql(["one", "two", "three", "four"])
+ end
- it "should collect a single dependency" do
- @depends_one.depends_attrs.should eql(["other"])
- end
+ it "should collect attributes across multiple plugin files" do
+ plugin = Ohai.plugin(@name) { provides("one") }
+ plugin = Ohai.plugin(@name) { provides("two", "three") }
+ plugin.provides_attrs.should eql(["one", "two", "three"])
+ end
+ end
- it "should collect a list of dependencies" do
- @depends_list.depends_attrs.should eql(["on", "list"])
- end
+ describe "#depends" do
+ it "should collect a single dependency" do
+ plugin = Ohai.plugin(@name) { depends("one") }
+ plugin.depends_attrs.should eql(["one"])
+ end
- it "should collect from multiple depends statements" do
- @depends_many.depends_attrs.should eql(["on", "list", "single"])
- end
+ it "should collect a list of dependencies" do
+ plugin = Ohai.plugin(@name) { depends("one", "two", "three") }
+ plugin.depends_attrs.should eql(["one", "two", "three"])
end
- describe "#self.depends_os" do
- before(:all) do
- Ohai::OS.stub(:collect_os).and_return("ubuntu")
- @depends_os = Ohai.plugin { depends_os("specific") }
- end
+ it "should collect from multiple depends statements" do
+ plugin = Ohai.plugin(@name) {
+ depends("one")
+ depends("two", "three")
+ depends("four")
+ }
+ plugin.depends_attrs.should eql(["one", "two", "three", "four"])
+ end
- it "should append the OS to the attribute" do
- @depends_os.depends_attrs.should eql(["ubuntu/specific"])
- end
+ it "should collect dependencies across multiple plugin files" do
+ plugin = Ohai.plugin(@name) { depends("one") }
+ plugin = Ohai.plugin(@name) { depends("two", "three") }
+ plugin.depends_attrs.should eql(["one", "two", "three"])
end
+ end
- describe "#self.collect_data" do
- before(:all) do
- @no_collect_data = Ohai.plugin { }
- @collect_data = Ohai.plugin { provides "math"; collect_data { math("is awesome") } }
- end
+ describe "#collect_data" do
+ it "should save as :default if no platform is given" do
+ plugin = Ohai.plugin(@name) { collect_data { } }
+ plugin.data_collector.should have_key(:default)
+ end
- it "should not define run_plugin if no collect data block exists" do
- @no_collect_data.method_defined?(:run_plugin).should be_false
- end
+ it "should save a single given platform" do
+ plugin = Ohai.plugin(@name) { collect_data(:ubuntu) { } }
+ plugin.data_collector.should have_key(:ubuntu)
+ end
- it "should define run_plugin if a collect data block exists" do
- @collect_data.method_defined?(:run_plugin).should be_true
+ it "should save a list of platforms" do
+ plugin = Ohai.plugin(@name) { collect_data(:freebsd, :netbsd, :openbsd) { } }
+ [:freebsd, :netbsd, :openbsd].each do |platform|
+ plugin.data_collector.should have_key(platform)
end
end
- it "should raise a NoMethodError when encountering \'require_plugin\'" do
- bad_plugin_string = <<EOF
-Ohai.plugin do
- require_plugin "other"
-end
-EOF
- expect { eval(bad_plugin_string, TOPLEVEL_BINDING) }.to raise_error(NoMethodError)
+ it "should save multiple collect_data blocks" do
+ plugin = Ohai.plugin(@name) {
+ collect_data { }
+ collect_data(:windows) { }
+ collect_data(:darwin) { }
+ }
+ [:darwin, :default, :windows].each do |platform|
+ plugin.data_collector.should have_key(platform)
+ end
end
- it "should log a deprecation warning when calling require_plugin from collect_data" do
- klass = Ohai.plugin { provides("bad"); collect_data { require_plugin("other") } }
- plugin = klass.new(Ohai::System.new, "/tmp/plugins/bad_plugin.rb")
- Ohai::Log.should_receive(:warn).with(/[UNSUPPORTED OPERATION]+\'require_plugin\'/)
- plugin.run
+ it "should save platforms across multiple plugins" do
+ plugin = Ohai.plugin(@name) { collect_data { } }
+ plugin = Ohai.plugin(@name) { collect_data(:aix, :sigar) { } }
+ [:aix, :default, :sigar].each do |platform|
+ plugin.data_collector.should have_key(platform)
+ end
end
- end
- describe "when initialized" do
- before(:each) do
- @ohai = Ohai::System.new
- @source = "/tmp/plugins/simple.rb"
- @plugin = Ohai::DSL::Plugin::VersionVII.new(@ohai, @source)
+ it "should log a warning if a platform has already been defined in the same plugin" do
+ Ohai::Log.should_receive(:warn).with(/Already defined collect_data on platform default/)
+ Ohai.plugin(@name) {
+ collect_data { }
+ collect_data { }
+ }
end
- it "should be a :version7 plugin" do
- @plugin.version.should eql(:version7)
+ it "should log a warning if a platform has already been defined in another plugin file" do
+ Ohai.plugin(@name) { collect_data { } }
+ Ohai::Log.should_receive(:warn).with(/Already defined collect_data on platform default/)
+ Ohai.plugin(@name) { collect_data { } }
end
-
- it "should log a deprecation warning when calling require_plugin from collect_data" do
- bad_plugin_string = <<EOF
-Ohai.plugin do
- provides "bad"
- collect_data do
- require_plugin "other"
end
-end
-EOF
- klass = eval(bad_plugin_string, TOPLEVEL_BINDING)
- plugin = klass.new(@ohai, "/tmp/plugins/bad_plugin.rb")
- Ohai::Log.should_receive(:warn).with(/[UNSUPPORTED OPERATION]+\'require_plugin\'/)
- plugin.run
- end
- it "should log a deprecation warning when calling provides from collect_data" do
- bad_plugin_string = <<EOF
-Ohai.plugin do
- collect_data do
- provides "bad"
- end
-end
-EOF
- klass = eval(bad_plugin_string, TOPLEVEL_BINDING)
- plugin = klass.new(@ohai, "/tmp/plugins/bad_plugin.rb")
- Ohai::Log.should_receive(:warn).with(/[UNSUPPORTED OPERATION]+\'provides\'/)
- plugin.run
+ describe "#provides (deprecated)" do
+ it "should log a warning" do
+ plugin = Ohai::DSL::Plugin::VersionVII.new(Ohai::System.new, "")
+ Ohai::Log.should_receive(:warn).with(/[UNSUPPORTED OPERATION]/)
+ plugin.provides("attribute")
end
+ end
- it_behaves_like "Ohai::DSL::Plugin" do
- let(:ohai) { @ohai }
- let(:source) { @source }
- let(:plugin) { @plugin }
+ describe "#require_plugin (deprecated)" do
+ it "should log a warning" do
+ plugin = Ohai::DSL::Plugin::VersionVII.new(Ohai::System.new, "")
+ Ohai::Log.should_receive(:warn).with(/[UNSUPPORTED OPERATION]/)
+ plugin.require_plugin("plugin")
end
end
+
+ it_behaves_like "Ohai::DSL::Plugin" do
+ let (:ohai) { Ohai::System.new }
+ let (:source) { "path/plugin.rb" }
+ let (:plugin) { Ohai::DSL::Plugin::VersionVII.new(ohai, source) }
+ let (:version) { :version7 }
+ end
end
describe Ohai::DSL::Plugin::VersionVI do
- describe "when loaded" do
- before(:all) do
- @contents = <<EOF
-provides "thing"
-depends "otherthing"
+ before(:each) do
+ @name = "test"
+ @name_sym = :Test
+ end
-thing "gets set"
-end
-EOF
- end
+ it "should log to debug if a plugin with the same name has been defined" do
+ Ohai.plugin(@name_sym) { }
+ Ohai::Log.should_receive(:debug).with(/Already loaded plugin #{@name_sym}/)
+ Ohai.v6plugin(@name) { }
+ end
- it "should define run_plugin with contents string" do
- klass = Ohai.v6plugin { collect_contents(@contents) }
- klass.method_defined?(:run_plugin).should be_true
+ describe "#version" do
+ it "should save the plugin version as :version6" do
+ plugin = Ohai.v6plugin(@name) { }
+ plugin.version.should eql(:version6)
end
end
- describe "when initialized" do
+ describe "#provides" do
before(:each) do
@ohai = Ohai::System.new
- @source = "/tmp/plugins/simple.rb"
- @plugin = Ohai::DSL::Plugin::VersionVI.new(@ohai, @source)
end
- it "should be a :version6 plugin" do
- @plugin.version.should eql(:version6)
+ it "should collect a single attribute" do
+ plugin = Ohai::DSL::Plugin::VersionVI.new(@ohai, "")
+ plugin.provides("attribute")
+
+ @ohai.attributes.should have_key(:attribute)
end
- it_behaves_like "Ohai::DSL::Plugin" do
- let(:ohai) { @ohai }
- let(:source) { @source }
- let(:plugin) { @plugin }
+ it "should collect a list of attributes" do
+ plugin = Ohai::DSL::Plugin::VersionVI.new(@ohai, "")
+ plugin.provides("attr1", "attr2", "attr3")
+
+ [:attr1, :attr2, :attr3].each do |attr|
+ @ohai.attributes.should have_key(attr)
+ end
end
+
+ it "should collect subattributes of an attribute" do
+ plugin = Ohai::DSL::Plugin::VersionVI.new(@ohai, "")
+ plugin.provides("attr/subattr")
+
+ @ohai.attributes.should have_key(:attr)
+ @ohai.attributes[:attr].should have_key(:subattr)
+ end
+
+ it "should collect all unique providers for an attribute" do
+ plugins = []
+ 3.times do
+ p = Ohai::DSL::Plugin::VersionVI.new(@ohai, "")
+ p.provides("attribute")
+ plugins << p
+ end
+
+ @ohai.attributes[:attribute][:_providers].should eql(plugins)
+ end
+ end
+
+ it_behaves_like "Ohai::DSL::Plugin" do
+ let (:ohai) { Ohai::System.new }
+ let (:source) { "path/plugin.rb" }
+ let (:plugin) { Ohai::DSL::Plugin::VersionVI.new(ohai, source) }
+ let (:version) { :version6 }
end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 89017881..580ca9af 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -14,7 +14,39 @@ Ohai::Config[:log_level] = :error
PLUGIN_PATH = File.expand_path("../../lib/ohai/plugins", __FILE__)
SPEC_PLUGIN_PATH = File.expand_path("../data/plugins", __FILE__)
-if Ohai::OS.collect_os == /mswin|mingw32|windows/
+RSpec.configure do |config|
+ config.before(:each) { @object_pristine = Object.clone }
+ config.after(:each) { remove_constants }
+end
+
+def remove_constants
+ new_object_constants = Object.constants - @object_pristine.constants
+ new_object_constants.each do |constant|
+ Object.send(:remove_const, constant) unless Object.const_get(constant).is_a?(Module)
+ end
+
+ recursive_remove_constants(Ohai::NamedPlugin)
+end
+
+def recursive_remove_constants(object)
+ if object.respond_to?(:constants)
+ object.constants.each do |const|
+ next unless strict_const_defined?(object, const)
+ recursive_remove_constants(object.const_get(const))
+ object.send(:remove_const, const)
+ end
+ end
+end
+
+def strict_const_defined?(object, const)
+ if object.method(:const_defined?).arity == 1
+ object.const_defined?(const)
+ else
+ object.const_defined?(const, false)
+ end
+end
+
+if Ohai::Mixin::OS.collect_os == /mswin|mingw32|windows/
ENV["PATH"] = ""
end
diff --git a/spec/unit/loader_spec.rb b/spec/unit/loader_spec.rb
index 8711484d..12bc55e3 100644
--- a/spec/unit/loader_spec.rb
+++ b/spec/unit/loader_spec.rb
@@ -18,144 +18,101 @@
#
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
-tmp = ENV['TMPDIR'] || ENV['TMP'] || ENV['TEMP'] || '/tmp'
-
-def create_plugin(path, contents)
- fi = File.open(path, "w+")
- fi.write(contents)
- fi.close
-end
describe Ohai::Loader do
- describe "initialize" do
+ before(:each) do
+ @ohai = Ohai::System.new
+ end
+
+ describe "#initialize" do
it "should return an Ohai::Loader object" do
- loader = Ohai::Loader.new(Ohai::System.new)
+ loader = Ohai::Loader.new(@ohai)
loader.should be_a_kind_of(Ohai::Loader)
end
end
describe "#load_plugin" do
- before(:all) do
- begin
- Dir.mkdir("#{tmp}/plugins")
- rescue Errno::EEXIST
- # ignore
- end
-
- @plugin_path = Ohai::Config[:plugin_path]
- Ohai::Config[:plugin_path] = ["#{tmp}/plugins"]
- end
-
before(:each) do
- @ohai = Ohai::System.new
- @loader = Ohai::Loader.new(@ohai)
- @loader.stub(:collect_provides).and_return(@ohai.attributes)
- end
-
- after(:each) do
- Dir[File.join("#{tmp}/plugins", "*.rb")].each do |file|
- File.delete(file)
- end
- end
+ @name = :Test
+ @v6name = "test"
+ @path = "test.rb"
- after(:all) do
- begin
- Dir.delete("#{tmp}/plugins")
- rescue
- # begin
- end
-
- Ohai::Config[:plugin_path] = @plugin_path
+ @loader = Ohai::Loader.new(@ohai)
+ @loader.stub(:collect_provides).and_return({})
end
- it "should warn if a plugin cannot be loaded" do
+ it "should log a warning if a plugin cannot be loaded" do
Ohai::Log.should_receive(:warn).with(/Unable to open or read plugin/)
- @loader.load_plugin("fake.rb")
+ IO.stub(:read).with(anything()).and_raise(IOError)
+ @loader.load_plugin("")
end
- it "should detect and return a v6 plugin" do
- plugin_string = <<EOF
-provides "thing"
-thing Mash.new
+ it "should detect a version 6 plugin and emit deprecation message" do
+ contents = <<EOF
+provides "test"
+test Mash.new
EOF
- create_plugin("#{tmp}/plugins/v6.rb", plugin_string)
+ IO.stub(:read).with(@path).and_return(contents)
Ohai::Log.should_receive(:warn).with(/[DEPRECATION]/)
- @loader.load_plugin("#{tmp}/plugins/v6.rb").version.should eql(:version6)
+ plugin = @loader.load_plugin(@path, @v6name)
+ plugin.version.should eql(:version6)
end
- it "should detect and return a v7 plugin" do
- plugin_string = <<EOF
-Ohai.plugin do
- provides "thing"
- collect_data do
- thing Mash.new
- end
+ it "should detect a version 7 plugin" do
+ contents = <<EOF
+Ohai.plugin(:#{@name}) do
end
EOF
- create_plugin("#{tmp}/plugins/v7.rb", plugin_string)
- @loader.load_plugin("#{tmp}/plugins/v7.rb").version.should eql(:version7)
+ IO.stub(:read).with(@path).and_return(contents)
+ plugin = @loader.load_plugin(@path)
+ plugin.version.should eql(:version7)
end
- it "should warn with NoMethodError when plugin uses non-dsl command" do
- plugin_string = <<EOF
-Ohai.plugin do
- requires "thing"
+ it "should log a warning from NoMethodError when plugin uses a non dsl command" do
+ contents = <<EOF
+Ohai.plugin(:#{@name}) do
+ requires "test"
end
EOF
- create_plugin("#{tmp}/plugins/broken.rb", plugin_string)
+ IO.stub(:read).with(@path).and_return(contents)
Ohai::Log.should_receive(:warn).with(/[UNSUPPORTED OPERATION]/)
- @loader.load_plugin("#{tmp}/plugins.broken.rb")
+ @loader.load_plugin(@path)
end
end
describe "#collect_provides" do
before(:each) do
- @ohai = Ohai::System.new
+ @name = :Test
+ @path = "test.rb"
@loader = Ohai::Loader.new(@ohai)
end
- it "should add a provided attribute to ohai attributes" do
- klass = Ohai.plugin { provides 'attribute' }
- plugin = klass.new(@ohai, "")
+ it "should add provided attributes to Ohai" do
+ klass = Ohai.plugin(@name) { provides("attr") }
+ plugin = klass.new(@ohai, @path)
@loader.collect_provides(plugin)
- @ohai.attributes.should have_key('attribute')
+ @ohai.attributes.should have_key(:attr)
end
- it "should add subattributes" do
- klass = Ohai.plugin { provides 'attribute/subattribute' }
- plugin = klass.new(@ohai, "")
+ it "should add provided subattributes to Ohai" do
+ klass = Ohai.plugin(@name) { provides("attr/sub") }
+ plugin = klass.new(@ohai, @plath)
@loader.collect_provides(plugin)
- @ohai.attributes.should have_key('attribute')
- @ohai.attributes['attribute'].should have_key('subattribute')
+ @ohai.attributes.should have_key(:attr)
+ @ohai.attributes[:attr].should have_key(:sub)
end
- it "should collect provides for a list" do
- klass = Ohai.plugin { provides 'one', 'two', 'three' }
- plugin = klass.new(@ohai, "")
- @loader.collect_provides(plugin)
- %w{ one two three }.each do |attr|
- @ohai.attributes.should have_key(attr)
- end
- end
+ it "should collect the unique providers for an attribute" do
+ n = 3
+ klass = Ohai.plugin(@name) { provides("attr") }
- it "should add the providing plugin to attribute providers" do
- klass = Ohai.plugin { provides 'attribute' }
- plugin = klass.new(@ohai, "")
- @loader.collect_provides(plugin)
- @ohai.attributes['attribute']['providers'].should eql([plugin])
- end
-
- it "should add to the providers list for multiple providing plugins" do
- klasses = []
- 2.times do
- klasses << Ohai.plugin { provides 'attribute' }
+ plugins = []
+ n.times do
+ plugins << klass.new(@ohai, @path)
end
- plugins = []
- klasses.each { |klass| plugins << klass.new(@ohai, "") }
plugins.each { |plugin| @loader.collect_provides(plugin) }
-
- @ohai.attributes['attribute']['providers'].should eql(plugins)
+ @ohai.attributes[:attr][:_providers].should eql(plugins)
end
end
end
diff --git a/spec/unit/plugins/chef_spec.rb b/spec/unit/plugins/chef_spec.rb
index 0d9a206c..e12b202b 100644
--- a/spec/unit/plugins/chef_spec.rb
+++ b/spec/unit/plugins/chef_spec.rb
@@ -27,7 +27,7 @@ begin
before(:each) do
@plugin = get_plugin("chef")
end
-
+
it "should set [:chef_packages][:chef][:version] to the current chef version", :if => defined?(Chef) do
@plugin.run
@plugin[:chef_packages][:chef][:version].should == Chef::VERSION
diff --git a/spec/unit/plugins/cloud_spec.rb b/spec/unit/plugins/cloud_spec.rb
index e4dc1ef3..78e7740f 100644
--- a/spec/unit/plugins/cloud_spec.rb
+++ b/spec/unit/plugins/cloud_spec.rb
@@ -18,7 +18,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
describe Ohai::System, "plugin cloud" do
- before do
+ before(:each) do
@plugin = get_plugin("cloud")
end
diff --git a/spec/unit/plugins/darwin/cpu_spec.rb b/spec/unit/plugins/darwin/cpu_spec.rb
index 2ea93ea9..63fd1796 100644
--- a/spec/unit/plugins/darwin/cpu_spec.rb
+++ b/spec/unit/plugins/darwin/cpu_spec.rb
@@ -22,7 +22,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Darwin cpu plugin" do
before(:each) do
@plugin = get_plugin("darwin/cpu")
-
+ @plugin.stub(:collect_os).and_return(:darwin)
@plugin.stub(:shell_out).with("sysctl -n hw.physicalcpu").and_return(mock_shell_out(0, "1", ""))
@plugin.stub(:shell_out).with("sysctl -n hw.logicalcpu").and_return(mock_shell_out(0, "2", ""))
end
diff --git a/spec/unit/plugins/darwin/hostname_spec.rb b/spec/unit/plugins/darwin/hostname_spec.rb
index 2b258aeb..c2d9a5dd 100644
--- a/spec/unit/plugins/darwin/hostname_spec.rb
+++ b/spec/unit/plugins/darwin/hostname_spec.rb
@@ -21,12 +21,12 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Darwin hostname plugin" do
before(:each) do
- @plugin = get_plugin("darwin/hostname")
- @plugin[:os] = "darwin"
+ @plugin = get_plugin("hostname")
+ @plugin.stub(:collect_os).and_return(:darwin)
@plugin.stub(:shell_out).with("hostname -s").and_return(mock_shell_out(0, "katie", ""))
@plugin.stub(:shell_out).with("hostname").and_return(mock_shell_out(0, "katie.bethell", ""))
end
-
+
it_should_check_from("darwin::hostname", "hostname", "hostname -s", "katie")
it_should_check_from("darwin::hostname", "fqdn", "hostname", "katie.bethell")
diff --git a/spec/unit/plugins/darwin/kernel_spec.rb b/spec/unit/plugins/darwin/kernel_spec.rb
index 7b36d4b4..d2033a45 100644
--- a/spec/unit/plugins/darwin/kernel_spec.rb
+++ b/spec/unit/plugins/darwin/kernel_spec.rb
@@ -21,9 +21,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Darwin kernel plugin" do
before(:each) do
- @plugin = get_plugin("darwin/kernel")
- @plugin[:kernel] = Mash.new
- @plugin[:kernel][:name] = "darwin"
+ @plugin = get_plugin("kernel")
+ @plugin.stub(:collect_os).and_return(:darwin)
+ @plugin.stub(:init_kernel).and_return({})
@plugin.should_receive(:shell_out).with("kextstat -k -l").and_return(mock_shell_out(0, "", ""))
end
diff --git a/spec/unit/plugins/darwin/network_spec.rb b/spec/unit/plugins/darwin/network_spec.rb
index 6e949456..2cf5ed04 100644
--- a/spec/unit/plugins/darwin/network_spec.rb
+++ b/spec/unit/plugins/darwin/network_spec.rb
@@ -19,7 +19,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Darwin Network Plugin" do
- before do
+ before(:each) do
@darwin_ifconfig = <<-DARWIN_IFCONFIG
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
options=3<RXCSUM,TXCSUM>
@@ -413,6 +413,7 @@ net.smb.fs.tcprcvbuf: 261120
DARWIN_SYSCTL
@plugin = get_plugin("darwin/network")
+ @plugin.stub(:collect_os).and_return(:darwin)
# @stdin_ifconfig = StringIO.new
# @stdin_arp = StringIO.new
@@ -426,19 +427,10 @@ net.smb.fs.tcprcvbuf: 261120
@plugin.stub(:shell_out).with("route -n get default").and_return(mock_shell_out(0, @darwin_route, ""))
@plugin.stub(:shell_out).with("netstat -i -d -l -b -n")
-
- Ohai::Log.should_receive(:warn).with(/unable to detect/).exactly(3).times
-
- %w{ darwin/hostname hostname network }.each do |plgn|
- p = get_plugin(plgn)
- p.stub(:shell_out).with("hostname -s").and_return(mock_shell_out(0, "katie", ""))
- p.stub(:shell_out).with("hostname").and_return(mock_shell_out(0, "katie.bethell", ""))
- p.run
- end
end
describe "gathering IP layer address info" do
- before do
+ before(:each) do
@plugin.stub(:shell_out).with("arp -an").and_return(mock_shell_out(0, @darwin_arp, ""))
@plugin.stub(:shell_out).with("ifconfig -a").and_return(mock_shell_out(0, @darwin_ifconfig, ""))
@plugin.stub(:shell_out).with("netstat -i -d -l -b -n").and_return(mock_shell_out(0, @darwin_netstat, ""))
diff --git a/spec/unit/plugins/darwin/platform_spec.rb b/spec/unit/plugins/darwin/platform_spec.rb
index c7b02f37..bae1ca72 100644
--- a/spec/unit/plugins/darwin/platform_spec.rb
+++ b/spec/unit/plugins/darwin/platform_spec.rb
@@ -22,12 +22,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Darwin plugin platform" do
before(:each) do
@plugin = get_plugin("darwin/platform")
-
- @plugin[:os] = "darwin"
+ @plugin.stub(:collect_os).and_return(:darwin)
@stdout = "ProductName: Mac OS X\nProductVersion: 10.5.5\nBuildVersion: 9F33"
@plugin.stub(:shell_out).with("/usr/bin/sw_vers").and_return(mock_shell_out(0, @stdout, ""))
end
-
+
it "should run sw_vers" do
@plugin.should_receive(:shell_out).with("/usr/bin/sw_vers").and_return(mock_shell_out(0, @stdout, ""))
@plugin.run
diff --git a/spec/unit/plugins/darwin/system_profiler_spec.rb b/spec/unit/plugins/darwin/system_profiler_spec.rb
index 20e99f72..5efad018 100644
--- a/spec/unit/plugins/darwin/system_profiler_spec.rb
+++ b/spec/unit/plugins/darwin/system_profiler_spec.rb
@@ -29,8 +29,9 @@ end
describe Ohai::System, "Darwin system_profiler plugin", :unix_only do
before(:each) do
@plugin = get_plugin("darwin/system_profiler")
+ @plugin.stub(:collect_os).and_return(:darwin)
end
-
+
it "should return the right serial number" do
mini_cmd = "system_profiler -xml -detailLevel mini SPParallelATAData SPAudioData SPBluetoothData"
mini_cmd += " SPCardReaderData SPDiagnosticsData SPDiscBurningData SPEthernetData SPFibreChannelData"
diff --git a/spec/unit/plugins/freebsd/hostname_spec.rb b/spec/unit/plugins/freebsd/hostname_spec.rb
index 19d4bd99..cb71b230 100644
--- a/spec/unit/plugins/freebsd/hostname_spec.rb
+++ b/spec/unit/plugins/freebsd/hostname_spec.rb
@@ -21,12 +21,12 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "FreeBSD hostname plugin" do
before(:each) do
- @plugin = get_plugin("freebsd/hostname")
- @plugin[:os] = "freebsd"
+ @plugin = get_plugin("hostname")
+ @plugin.stub(:collect_os).and_return(:freebsd)
@plugin.stub(:shell_out).with("hostname -s").and_return(mock_shell_out(0, "katie", ""))
@plugin.stub(:shell_out).with("hostname -f").and_return(mock_shell_out(0, "katie.bethell", ""))
end
-
+
it_should_check_from("freebsd::hostname", "hostname", "hostname -s", "katie")
it_should_check_from("freebsd::hostname", "fqdn", "hostname -f", "katie.bethell")
diff --git a/spec/unit/plugins/freebsd/kernel_spec.rb b/spec/unit/plugins/freebsd/kernel_spec.rb
index e4f7174f..ccfb19d7 100644
--- a/spec/unit/plugins/freebsd/kernel_spec.rb
+++ b/spec/unit/plugins/freebsd/kernel_spec.rb
@@ -21,12 +21,12 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "FreeBSD kernel plugin" do
before(:each) do
- @plugin = get_plugin("freebsd/kernel")
+ @plugin = get_plugin("kernel")
+ @plugin.stub(:collect_os).and_return(:freebsd)
+ @plugin.stub(:init_kernel).and_return({:name => "freebsd"})
@plugin.stub(:shell_out).with("uname -i").and_return(mock_shell_out(0, "foo\n", ""))
@plugin.stub(:shell_out).with("sysctl kern.securelevel").and_return(mock_shell_out(0, "kern.securelevel: 1", ""))
@plugin.stub(:shell_out).with( Ohai.abs_path( "/sbin/kldstat" )).and_return(mock_shell_out(0, " 1 7 0xc0400000 97f830 kernel", ""))
- @plugin[:kernel] = Mash.new
- @plugin[:kernel][:name] = "freebsd"
end
it "should set the kernel_os to the kernel_name value" do
diff --git a/spec/unit/plugins/freebsd/platform_spec.rb b/spec/unit/plugins/freebsd/platform_spec.rb
index 798b1063..a38db60e 100644
--- a/spec/unit/plugins/freebsd/platform_spec.rb
+++ b/spec/unit/plugins/freebsd/platform_spec.rb
@@ -24,9 +24,9 @@ describe Ohai::System, "FreeBSD plugin platform" do
@plugin = get_plugin("freebsd/platform")
@plugin.stub(:shell_out).with("uname -s").and_return(mock_shell_out(0, "FreeBSD\n", ""))
@plugin.stub(:shell_out).with("uname -r").and_return(mock_shell_out(0, "7.1\n", ""))
- @plugin[:os] = "freebsd"
+ @plugin.stub(:collect_os).and_return(:freebsd)
end
-
+
it "should set platform to lowercased lsb[:id]" do
@plugin.run
@plugin[:platform].should == "freebsd"
diff --git a/spec/unit/plugins/freebsd/virtualization_spec.rb b/spec/unit/plugins/freebsd/virtualization_spec.rb
index 02f3f090..1072f051 100644
--- a/spec/unit/plugins/freebsd/virtualization_spec.rb
+++ b/spec/unit/plugins/freebsd/virtualization_spec.rb
@@ -22,7 +22,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "FreeBSD virtualization plugin" do
before(:each) do
@plugin = get_plugin("freebsd/virtualization")
- @plugin[:os] = "freebsd"
+ @plugin.stub(:collect_os).and_return(:freebsd)
+ @plugin.extend(SimpleFromFile)
@plugin.stub(:shell_out).with("sysctl -n security.jail.jailed").and_return(mock_shell_out(0, "0", ""))
@plugin.stub(:shell_out).with("#{ Ohai.abs_path( "/sbin/kldstat" )}").and_return(mock_shell_out(0, "", ""))
@plugin.stub(:shell_out).with("jls -n").and_return(mock_shell_out(0, "",""))
diff --git a/spec/unit/plugins/hostname_spec.rb b/spec/unit/plugins/hostname_spec.rb
index 5891811a..38860f0f 100644
--- a/spec/unit/plugins/hostname_spec.rb
+++ b/spec/unit/plugins/hostname_spec.rb
@@ -22,6 +22,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
describe Ohai::System, "hostname plugin" do
before(:each) do
@plugin = get_plugin("hostname")
+ @plugin.stub(:collect_os).and_return(:default)
end
it "should set the domain to everything after the first dot of the fqdn" do
diff --git a/spec/unit/plugins/kernel_spec.rb b/spec/unit/plugins/kernel_spec.rb
index a3bf1626..737573c6 100644
--- a/spec/unit/plugins/kernel_spec.rb
+++ b/spec/unit/plugins/kernel_spec.rb
@@ -22,9 +22,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
describe Ohai::System, "plugin kernel" do
before(:each) do
@plugin = get_plugin("kernel")
-
- @plugin[:languages] = Mash.new
- @plugin[:languages][:ruby] = Mash.new
+ @plugin.stub(:collect_os).and_return(:default) # for debugging
@plugin.stub(:shell_out).with("uname -s").and_return(mock_shell_out(0, "Darwin\n", ""))
@plugin.stub(:shell_out).with("uname -r").and_return(mock_shell_out(0, "9.5.0\n", ""))
@plugin.stub(:shell_out).with("uname -v").and_return(mock_shell_out(0, "Darwin Kernel Version 9.5.0: Wed Sep 3 11:29:43 PDT 2008; root:xnu-1228.7.58~1\/RELEASE_I386\n", ""))
diff --git a/spec/unit/plugins/linux/cpu_spec.rb b/spec/unit/plugins/linux/cpu_spec.rb
index 925d0553..5f55eb5f 100644
--- a/spec/unit/plugins/linux/cpu_spec.rb
+++ b/spec/unit/plugins/linux/cpu_spec.rb
@@ -22,7 +22,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Linux cpu plugin" do
before(:each) do
@plugin = get_plugin("linux/cpu")
- @plugin[:os] = "linux"
+ @plugin.stub(:collect_os).and_return(:linux)
@double_file = double("/proc/cpuinfo")
@double_file.stub(:each).
and_yield("processor : 0").
diff --git a/spec/unit/plugins/linux/filesystem_spec.rb b/spec/unit/plugins/linux/filesystem_spec.rb
index d6f70f79..cdd601b5 100644
--- a/spec/unit/plugins/linux/filesystem_spec.rb
+++ b/spec/unit/plugins/linux/filesystem_spec.rb
@@ -21,7 +21,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Linux filesystem plugin" do
before(:each) do
@plugin = get_plugin("linux/filesystem")
- @plugin[:os] = "linux"
+ @plugin.stub(:collect_os).and_return(:linux)
@plugin.extend(SimpleFromFile)
@plugin.stub(:shell_out).with("df -P").and_return(mock_shell_out(0, "", ""))
diff --git a/spec/unit/plugins/linux/hostname_spec.rb b/spec/unit/plugins/linux/hostname_spec.rb
index 5ec0fb6e..0715a135 100644
--- a/spec/unit/plugins/linux/hostname_spec.rb
+++ b/spec/unit/plugins/linux/hostname_spec.rb
@@ -21,8 +21,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Linux hostname plugin" do
before(:each) do
- @plugin = get_plugin("linux/hostname")
- @plugin[:os] = "linux"
+ @plugin = get_plugin("hostname")
+ @plugin.stub(:collect_os).and_return(:linux)
@plugin.stub(:shell_out).with("hostname -s").and_return(mock_shell_out(0, "katie", ""))
@plugin.stub(:shell_out).with("hostname --fqdn").and_return(mock_shell_out(0, "katie.bethell", ""))
end
diff --git a/spec/unit/plugins/linux/kernel_spec.rb b/spec/unit/plugins/linux/kernel_spec.rb
index 557a0d00..068b8f10 100644
--- a/spec/unit/plugins/linux/kernel_spec.rb
+++ b/spec/unit/plugins/linux/kernel_spec.rb
@@ -20,7 +20,6 @@
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
require File.expand_path(File.dirname(__FILE__) + '/../../path/ohai_plugin_common.rb')
-
describe Ohai::System, "Linux kernel plugin" do
before(:each) do
@env_lsmod = <<-ENV_LSMOD
@@ -33,17 +32,18 @@ serio_raw 13031 0
virtio_balloon 13168 0
floppy 55441 0
ENV_LSMOD
- @plugin = get_plugin("linux/kernel")
+ @plugin = get_plugin("kernel")
+ @plugin.stub(:collect_os).and_return(:linux)
+ @plugin.stub(:init_kernel).and_return({})
@plugin.stub(:shell_out).with("uname -o").and_return(mock_shell_out(0, "Linux", ""))
@plugin.stub(:shell_out).with("env lsmod").and_return(mock_shell_out(0, @env_lsmod, ""))
@plugin.should_receive(:shell_out).with("env lsmod").at_least(1).times
- @plugin[:kernel] = {}
@plugin.run
end
it_should_check_from_deep_mash("linux::kernel", "kernel", "os", "uname -o", [0, "Linux", ""])
- test_plugin([ "kernel", "linux/kernel" ], [ "uname", "env" ]) do | p |
+ test_plugin([ "kernel" ], [ "uname", "env" ]) do | p |
p.test([ "centos-5.9", "centos-6.4", "ubuntu-10.04", "ubuntu-12.04" ], [ "x86", "x64" ], [[]],
{ "kernel" => { "os" => "GNU/Linux" }})
p.test([ "ubuntu-13.04" ], [ "x64" ], [[]],
diff --git a/spec/unit/plugins/linux/lsb_spec.rb b/spec/unit/plugins/linux/lsb_spec.rb
index 7bbdaef1..6863170f 100644
--- a/spec/unit/plugins/linux/lsb_spec.rb
+++ b/spec/unit/plugins/linux/lsb_spec.rb
@@ -24,7 +24,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Linux lsb plugin" do
before(:each) do
@plugin = get_plugin("linux/lsb")
- @plugin[:os] = "linux"
+ @plugin.stub(:collect_os).and_return(:linux)
@plugin.extend(SimpleFromFile)
end
diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb
index 22cb6800..a3ae46a2 100644
--- a/spec/unit/plugins/linux/network_spec.rb
+++ b/spec/unit/plugins/linux/network_spec.rb
@@ -257,14 +257,6 @@ IP_ROUTE_SCOPE
@plugin = get_plugin("linux/network")
@plugin.stub(:shell_out).with("ifconfig -a").and_return([0, @linux_ifconfig, ""])
@plugin.stub(:shell_out).with("arp -an").and_return([0, @linux_arp_an, ""])
- Ohai::Log.should_receive(:warn).with(/unable to detect/).exactly(3).times
-
- %w{ linux/hostname hostname network }.each do |plgn|
- p = get_plugin(plgn)
- p.stub(:shell_out).with("hostname -s").and_return(mock_shell_out(0, "katie", ""))
- p.stub(:shell_out).with("hostname --fqdn").and_return(mock_shell_out(0, "katie.bethell", ""))
- p.run
- end
end
["ifconfig","iproute2"].each do |network_method|
diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb
index 4ab6bba2..190eec7d 100644
--- a/spec/unit/plugins/linux/platform_spec.rb
+++ b/spec/unit/plugins/linux/platform_spec.rb
@@ -24,7 +24,7 @@ describe Ohai::System, "Linux plugin platform" do
before(:each) do
@plugin = get_plugin("linux/platform")
@plugin.extend(SimpleFromFile)
- @plugin[:os] = "linux"
+ @plugin.stub(:collect_os).and_return(:linux)
@plugin[:lsb] = Mash.new
File.stub(:exists?).with("/etc/debian_version").and_return(false)
File.stub(:exists?).with("/etc/redhat-release").and_return(false)
@@ -37,7 +37,7 @@ describe Ohai::System, "Linux plugin platform" do
File.stub(:exists?).with("/etc/oracle-release").and_return(false)
File.stub(:exists?).with("/usr/bin/raspi-config").and_return(false)
end
-
+
describe "on lsb compliant distributions" do
before(:each) do
@plugin[:lsb][:id] = "Ubuntu"
diff --git a/spec/unit/plugins/linux/uptime_spec.rb b/spec/unit/plugins/linux/uptime_spec.rb
index 14d26a4d..0f17b484 100644
--- a/spec/unit/plugins/linux/uptime_spec.rb
+++ b/spec/unit/plugins/linux/uptime_spec.rb
@@ -21,8 +21,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Linux plugin uptime" do
before(:each) do
- @plugin = get_plugin("linux/uptime")
- @plugin[:os] = "linux"
+ @plugin = get_plugin("uptime")
+ @plugin.stub(:collect_os).and_return(:linux)
@double_file = double("/proc/uptime", { :gets => "18423 989" })
File.stub(:open).with("/proc/uptime").and_return(@double_file)
end
diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb
index 5392f610..dfd8c3e4 100644
--- a/spec/unit/plugins/linux/virtualization_spec.rb
+++ b/spec/unit/plugins/linux/virtualization_spec.rb
@@ -21,7 +21,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Linux virtualization platform" do
before(:each) do
@plugin = get_plugin("linux/virtualization")
- @plugin[:os] = "linux"
+ @plugin.stub(:collect_os).and_return(:linux)
@plugin.extend(SimpleFromFile)
# default to all requested Files not existing
diff --git a/spec/unit/plugins/netbsd/hostname_spec.rb b/spec/unit/plugins/netbsd/hostname_spec.rb
index 3c8bd6c6..b77bf696 100644
--- a/spec/unit/plugins/netbsd/hostname_spec.rb
+++ b/spec/unit/plugins/netbsd/hostname_spec.rb
@@ -21,8 +21,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "NetBSD hostname plugin" do
before(:each) do
- @plugin = get_plugin("netbsd/hostname")
- @plugin[:os] = "netbsd"
+ @plugin = get_plugin("hostname")
+ @plugin.stub(:collect_os).and_return(:netbsd)
@plugin.stub(:shell_out).with("hostname -s").and_return(mock_shell_out(0, "katie\n", ""))
@plugin.stub(:shell_out).with("hostname").and_return(mock_shell_out(0, "katie.bethell", ""))
end
diff --git a/spec/unit/plugins/netbsd/kernel_spec.rb b/spec/unit/plugins/netbsd/kernel_spec.rb
index 832176d4..f08f2caa 100644
--- a/spec/unit/plugins/netbsd/kernel_spec.rb
+++ b/spec/unit/plugins/netbsd/kernel_spec.rb
@@ -21,12 +21,12 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "NetBSD kernel plugin" do
before(:each) do
- @plugin = get_plugin("netbsd/kernel")
+ @plugin = get_plugin("kernel")
+ @plugin.stub(:collect_os).and_return(:netbsd)
+ @plugin.stub(:init_kernel).and_return({})
@plugin.stub(:shell_out).with("uname -i").and_return(mock_shell_out(0, "foo", ""))
@plugin.stub(:shell_out).with("sysctl kern.securelevel").and_return(mock_shell_out(0, "kern.securelevel: 1\n", ""))
@plugin.stub(:shell_out).with("#{ Ohai.abs_path( "/usr/bin/modstat" )}").and_return(mock_shell_out(0, " 1 7 0xc0400000 97f830 kernel", ""))
- @plugin[:kernel] = Mash.new
- @plugin[:kernel][:name] = "netbsd"
end
it "should set the kernel_os to the kernel_name value" do
diff --git a/spec/unit/plugins/netbsd/platform_spec.rb b/spec/unit/plugins/netbsd/platform_spec.rb
index 4397d100..f1a91758 100644
--- a/spec/unit/plugins/netbsd/platform_spec.rb
+++ b/spec/unit/plugins/netbsd/platform_spec.rb
@@ -16,7 +16,6 @@
# limitations under the License.
#
-
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "NetBSD plugin platform" do
@@ -24,7 +23,7 @@ describe Ohai::System, "NetBSD plugin platform" do
@plugin = get_plugin("netbsd/platform")
@plugin.stub(:shell_out).with("uname -s").and_return(mock_shell_out(0, "NetBSD\n", ""))
@plugin.stub(:shell_out).with("uname -r").and_return(mock_shell_out(0, "4.5\n", ""))
- @plugin[:os] = "netbsd"
+ @plugin.stub(:collect_os).and_return(:netbsd)
end
it "should set platform to lowercased lsb[:id]" do
diff --git a/spec/unit/plugins/openbsd/hostname_spec.rb b/spec/unit/plugins/openbsd/hostname_spec.rb
index e7a4b207..9c75c0f2 100644
--- a/spec/unit/plugins/openbsd/hostname_spec.rb
+++ b/spec/unit/plugins/openbsd/hostname_spec.rb
@@ -21,12 +21,12 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "OpenBSD hostname plugin" do
before(:each) do
- @plugin = get_plugin("openbsd/hostname")
- @plugin[:os] = "openbsd"
+ @plugin = get_plugin("hostname")
+ @plugin.stub(:collect_os).and_return(:openbsd)
@plugin.stub(:shell_out).with("hostname -s").and_return(mock_shell_out(0, "katie", ""))
@plugin.stub(:shell_out).with("hostname").and_return(mock_shell_out(0, "katie.bethell", ""))
end
-
+
it_should_check_from("openbsd::hostname", "hostname", "hostname -s", "katie")
it_should_check_from("openbsd::hostname", "fqdn", "hostname", "katie.bethell")
diff --git a/spec/unit/plugins/openbsd/kernel_spec.rb b/spec/unit/plugins/openbsd/kernel_spec.rb
index 8979b431..1d1643b5 100644
--- a/spec/unit/plugins/openbsd/kernel_spec.rb
+++ b/spec/unit/plugins/openbsd/kernel_spec.rb
@@ -21,12 +21,12 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "OpenBSD kernel plugin" do
before(:each) do
- @plugin = get_plugin("openbsd/kernel")
+ @plugin = get_plugin("kernel")
+ @plugin.stub(:collect_os).and_return(:openbsd)
+ @plugin.stub(:init_kernel).and_return({})
@plugin.stub(:shell_out).with("uname -i").and_return(mock_shell_out(0, "foo", ""))
@plugin.stub(:shell_out).with("sysctl kern.securelevel").and_return(mock_shell_out(0, "kern.securelevel: 1\n", ""))
@plugin.stub(:shell_out).with( Ohai.abs_path( "/usr/bin/modstat" )).and_return(mock_shell_out(0, " 1 7 0xc0400000 97f830 kernel", ""))
- @plugin[:kernel] = Mash.new
- @plugin[:kernel][:name] = "openbsd"
end
it "should set the kernel_os to the kernel_name value" do
diff --git a/spec/unit/plugins/openbsd/platform_spec.rb b/spec/unit/plugins/openbsd/platform_spec.rb
index e11f2495..915323ef 100644
--- a/spec/unit/plugins/openbsd/platform_spec.rb
+++ b/spec/unit/plugins/openbsd/platform_spec.rb
@@ -24,12 +24,7 @@ describe Ohai::System, "OpenBSD plugin platform" do
@plugin = get_plugin("openbsd/platform")
@plugin.stub(:shell_out).with("uname -s").and_return(mock_shell_out(0, "OpenBSD\n", ""))
@plugin.stub(:shell_out).with("uname -r").and_return(mock_shell_out(0, "4.5\n", ""))
- @plugin[:os] = "openbsd"
- end
-
- it "should set platform to lowercased lsb[:id]" do
- @plugin.run
- @plugin[:platform].should == "openbsd"
+ @plugin.stub(:collect_os).and_return(:openbsd)
end
it "should set platform_version to lsb[:release]" do
diff --git a/spec/unit/plugins/os_spec.rb b/spec/unit/plugins/os_spec.rb
index 86faa1e0..2f5df02f 100644
--- a/spec/unit/plugins/os_spec.rb
+++ b/spec/unit/plugins/os_spec.rb
@@ -24,8 +24,6 @@ ORIGINAL_CONFIG_HOST_OS = ::RbConfig::CONFIG['host_os']
describe Ohai::System, "plugin os" do
before(:each) do
@plugin = get_plugin("os")
- @plugin[:languages] = Mash.new
- @plugin[:languages][:ruby] = Mash.new
@plugin[:kernel] = Mash.new
@plugin[:kernel][:release] = "kings of leon"
end
diff --git a/spec/unit/plugins/platform_spec.rb b/spec/unit/plugins/platform_spec.rb
index cf743a96..704038fc 100644
--- a/spec/unit/plugins/platform_spec.rb
+++ b/spec/unit/plugins/platform_spec.rb
@@ -22,6 +22,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
describe Ohai::System, "plugin platform" do
before(:each) do
@plugin = get_plugin("platform")
+ @plugin.stub(:collect_os).and_return(:default)
@plugin[:os] = 'monkey'
@plugin[:os_version] = 'poop'
end
diff --git a/spec/unit/plugins/sigar/network_route_spec.rb b/spec/unit/plugins/sigar/network_route_spec.rb
index 45fec414..6d71798c 100644
--- a/spec/unit/plugins/sigar/network_route_spec.rb
+++ b/spec/unit/plugins/sigar/network_route_spec.rb
@@ -33,7 +33,8 @@ describe Ohai::System, "Sigar network route plugin" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = get_plugin("sigar/network_route", @ohai)
+ @plugin = get_plugin("sigar/network", @ohai)
+ @plugin.stub(:collect_os).and_return(:sigar)
@sigar = double("Sigar")
@net_info_conf={
:default_gateway => "192.168.1.254",
@@ -112,7 +113,7 @@ describe Ohai::System, "Sigar network route plugin" do
net_arp.stub(k).and_return(v)
end
@sigar.stub(:fqdn).and_return("localhost.localdomain")
- @sigar.should_receive(:net_info).at_least(2).times.and_return(net_info)
+ @sigar.should_receive(:net_info).once.times.and_return(net_info)
@sigar.should_receive(:net_interface_list).once.and_return(["eth0"])
@sigar.should_receive(:net_interface_config).with("eth0").and_return(net_conf)
@sigar.should_receive(:net_interface_stat).with("eth0").and_return(net_stat)
@@ -120,17 +121,7 @@ describe Ohai::System, "Sigar network route plugin" do
# Since we double net_route_list here, flags never gets called
@sigar.should_receive(:net_route_list).once.and_return([net_route])
- Sigar.should_receive(:new).at_least(2).times.and_return(@sigar)
-
- %w{ languages ruby kernel os }.each do |plgn|
- get_plugin(plgn, @ohai).run
- end
- @plugin.data[:os]="sigar"
-
- #Ohai::Log.should_receive(:warn).with(/unable to detect ip6address/).once
- %w{ sigar/hostname hostname sigar/network network }.each do |plgn|
- get_plugin(plgn, @ohai).run
- end
+ Sigar.should_receive(:new).once.and_return(@sigar)
@plugin.run
end
diff --git a/spec/unit/plugins/solaris2/cpu_spec.rb b/spec/unit/plugins/solaris2/cpu_spec.rb
index 73a5c06b..1d472179 100644
--- a/spec/unit/plugins/solaris2/cpu_spec.rb
+++ b/spec/unit/plugins/solaris2/cpu_spec.rb
@@ -19,7 +19,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Solaris2.X cpu plugin" do
before(:each) do
@plugin = get_plugin("solaris2/cpu")
- @plugin[:os] = "solaris2"
+ @plugin.stub(:collect_os).and_return("solaris2")
@plugin.stub(:shell_out).with("psrinfo | wc -l").and_return(mock_shell_out(0, "32\n", ""))
@plugin.stub(:shell_out).with("psrinfo -p").and_return(mock_shell_out(0, "4\n", ""))
diff --git a/spec/unit/plugins/solaris2/hostname_spec.rb b/spec/unit/plugins/solaris2/hostname_spec.rb
index 6b6acd6d..4ed8ae26 100644
--- a/spec/unit/plugins/solaris2/hostname_spec.rb
+++ b/spec/unit/plugins/solaris2/hostname_spec.rb
@@ -20,12 +20,12 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Solaris2.X hostname plugin" do
before(:each) do
- @plugin = get_plugin("solaris2/hostname")
- @plugin[:os] = "solaris2"
+ @plugin = get_plugin("hostname")
+ @plugin.stub(:collect_os).and_return(:solaris2)
@plugin.stub(:shell_out).with("hostname").and_return(mock_shell_out(0, "kitteh\n", ""))
Socket.stub(:getaddrinfo).and_return( [["AF_INET", 0, "kitteh.inurfridge.eatinurfoodz", "10.1.2.3", 2, 0, 0]] );
end
-
+
it_should_check_from("solaris2::hostname", "hostname", "hostname", "kitteh")
it "should get the fqdn value from socket getaddrinfo" do
diff --git a/spec/unit/plugins/solaris2/kernel_spec.rb b/spec/unit/plugins/solaris2/kernel_spec.rb
index 008672ec..d252441a 100644
--- a/spec/unit/plugins/solaris2/kernel_spec.rb
+++ b/spec/unit/plugins/solaris2/kernel_spec.rb
@@ -134,8 +134,9 @@ describe Ohai::System, "Solaris2.X kernel plugin" do
TOOMUCH
before(:each) do
- @plugin = get_plugin("solaris2/kernel")
- @plugin[:kernel] = Mash.new
+ @plugin = get_plugin("kernel")
+ @plugin.stub(:collect_os).and_return(:solaris2)
+ @plugin.stub(:init_kernel).and_return({})
@plugin.stub(:shell_out).with("uname -s").and_return(mock_shell_out(0, "SunOS\n", ""))
@plugin.stub(:shell_out).with("modinfo").and_return(mock_shell_out(0, MODINFO, ""))
end
diff --git a/spec/unit/plugins/solaris2/memory_spec.rb b/spec/unit/plugins/solaris2/memory_spec.rb
index fc57fceb..fca1a914 100644
--- a/spec/unit/plugins/solaris2/memory_spec.rb
+++ b/spec/unit/plugins/solaris2/memory_spec.rb
@@ -19,7 +19,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Solaris2.X memory plugin" do
before(:each) do
@plugin = get_plugin("solaris2/memory")
- @plugin[:os] = "solaris2"
+ @plugin.stub(:collect_os).and_return("solaris2")
@plugin.stub(:shell_out).with("prtconf -m").and_return(mock_shell_out(0, "8194\n", ""))
end
diff --git a/spec/unit/plugins/solaris2/network_spec.rb b/spec/unit/plugins/solaris2/network_spec.rb
index 08561682..c895aa60 100644
--- a/spec/unit/plugins/solaris2/network_spec.rb
+++ b/spec/unit/plugins/solaris2/network_spec.rb
@@ -112,6 +112,7 @@ ROUTE_GET
@ifconfig_lines = @solaris_ifconfig.split("\n")
@plugin = get_plugin("solaris2/network")
+ @plugin.stub(:collect_os).and_return(:solaris2)
@plugin[:network] = Mash.new
@plugin.stub(:shell_out).with("ifconfig -a").and_return(mock_shell_out(0, @solaris_route_get, ""))
diff --git a/spec/unit/plugins/solaris2/platform_spec.rb b/spec/unit/plugins/solaris2/platform_spec.rb
index 5be59f76..d7ce9556 100644
--- a/spec/unit/plugins/solaris2/platform_spec.rb
+++ b/spec/unit/plugins/solaris2/platform_spec.rb
@@ -22,7 +22,7 @@ describe Ohai::System, "Solaris plugin platform" do
before(:each) do
@plugin = get_plugin("solaris2/platform")
@plugin.extend(SimpleFromFile)
- @plugin[:os] = "solaris2"
+ @plugin.stub(:collect_os).and_return(:solaris2)
@plugin.stub(:shell_out).with("/sbin/uname -X")
end
diff --git a/spec/unit/plugins/solaris2/virtualization_spec.rb b/spec/unit/plugins/solaris2/virtualization_spec.rb
index 15a5667a..b2b02511 100644
--- a/spec/unit/plugins/solaris2/virtualization_spec.rb
+++ b/spec/unit/plugins/solaris2/virtualization_spec.rb
@@ -27,7 +27,7 @@ The physical processor has 1 virtual processor (0)
PSRINFO_PV
@plugin = get_plugin("solaris2/virtualization")
- @plugin[:os] = "solaris2"
+ @plugin.stub(:collect_os).and_return(:solaris2)
@plugin.extend(SimpleFromFile)
# default to all requested Files not existing
diff --git a/spec/unit/runner_spec.rb b/spec/unit/runner_spec.rb
index 4cb73e62..efa3985c 100644
--- a/spec/unit/runner_spec.rb
+++ b/spec/unit/runner_spec.rb
@@ -25,7 +25,12 @@ describe Ohai::Runner, "run_plugin" do
@ohai = Ohai::System.new
@runner = Ohai::Runner.new(@ohai, true)
- klass = Ohai.plugin { provides("thing"); collect_data { thing(Mash.new) } }
+ klass = Ohai.plugin(:Test) {
+ provides("thing")
+ collect_data {
+ thing(Mash.new)
+ }
+ }
@plugin = klass.new(@ohai, "/tmp/plugins/thing.rb")
end
@@ -54,7 +59,13 @@ describe Ohai::Runner, "run_plugin" do
describe "when the dependency does not exist" do
before(:each) do
- klass = Ohai.plugin { provides("thing"); depends("other_thing"); collect_data { thing(other_thing) } }
+ klass = Ohai.plugin(:Test) {
+ provides("thing")
+ depends("other_thing")
+ collect_data {
+ thing(other_thing)
+ }
+ }
@plugin = klass.new(@ohai, "/tmp/plugins/thing.rb")
end
@@ -70,8 +81,19 @@ describe Ohai::Runner, "run_plugin" do
describe "when the dependency has a single provider" do
before(:each) do
- klass1 = Ohai.plugin { provides("thing"); collect_data { thing("thang") } }
- klass2 = Ohai.plugin { provides("other"); depends("thing"); collect_data { other(thing) } }
+ klass1 = Ohai.plugin(:Thing) {
+ provides("thing")
+ collect_data {
+ thing("thang")
+ }
+ }
+ klass2 = Ohai.plugin(:Other) {
+ provides("other")
+ depends("thing")
+ collect_data {
+ other(thing)
+ }
+ }
@plugins = []
[klass1, klass2].each do |klass|
@@ -82,9 +104,9 @@ describe Ohai::Runner, "run_plugin" do
it "should locate the provider" do
@ohai.attributes[:thing] = Mash.new
- @ohai.attributes[:thing][:providers] = [@plugin1]
+ @ohai.attributes[:thing][:_providers] = [@plugin1]
@ohai.attributes[:other] = Mash.new
- @ohai.attributes[:other][:providers] = [@plugin2]
+ @ohai.attributes[:other][:_providers] = [@plugin2]
@runner.should_receive(:fetch_providers).twice.with(["thing"]).and_return([@plugin1])
@runner.should_receive(:fetch_providers).with([]).and_return([])
@@ -104,8 +126,19 @@ describe Ohai::Runner, "run_plugin" do
describe "when the dependency has multiple providers" do
before(:each) do
- klass1 = Ohai.plugin { provides("thing"); collect_data { thing(Mash.new) } }
- klass2 = Ohai.plugin { provides("other"); depends("thing"); collect_data { other(thing) } }
+ klass1 = Ohai.plugin(:Thing) {
+ provides("thing")
+ collect_data {
+ thing(Mash.new)
+ }
+ }
+ klass2 = Ohai.plugin(:Other) {
+ provides("other")
+ depends("thing")
+ collect_data {
+ other(thing)
+ }
+ }
@plugins = []
[klass1, klass1, klass2].each do |klass|
@@ -116,9 +149,9 @@ describe Ohai::Runner, "run_plugin" do
it "should locate each provider" do
@ohai.attributes[:thing] = Mash.new
- @ohai.attributes[:thing][:providers] = [@plugin1, @plugin2]
+ @ohai.attributes[:thing][:_providers] = [@plugin1, @plugin2]
@ohai.attributes[:other] = Mash.new
- @ohai.attributes[:other][:providers] = [@plugin3]
+ @ohai.attributes[:other][:_providers] = [@plugin3]
@runner.should_receive(:fetch_providers).exactly(3).times.with(["thing"]).and_return([@plugin1, @plugin2])
@runner.should_receive(:fetch_providers).twice.with([]).and_return([])
@@ -141,9 +174,25 @@ describe Ohai::Runner, "run_plugin" do
@ohai = Ohai::System.new
@runner = Ohai::Runner.new(@ohai, true)
- klass1 = Ohai.plugin { provides("one"); collect_data { one(1) } }
- klass2 = Ohai.plugin { provides("two"); collect_data { two(2) } }
- klass3 = Ohai.plugin { provides("three"); depends("one", "two"); collect_data { three(3) } }
+ klass1 = Ohai.plugin(:One) {
+ provides("one")
+ collect_data {
+ one(1)
+ }
+ }
+ klass2 = Ohai.plugin(:Two) {
+ provides("two")
+ collect_data {
+ two(2)
+ }
+ }
+ klass3 = Ohai.plugin(:Three) {
+ provides("three")
+ depends("one", "two")
+ collect_data {
+ three(3)
+ }
+ }
@plugins = []
[klass1, klass2, klass3].each do |klass|
@@ -154,11 +203,11 @@ describe Ohai::Runner, "run_plugin" do
it "should locate each provider" do
@ohai.attributes[:one] = Mash.new
- @ohai.attributes[:one][:providers] = [@plugin1]
+ @ohai.attributes[:one][:_providers] = [@plugin1]
@ohai.attributes[:two] = Mash.new
- @ohai.attributes[:two][:providers] = [@plugin2]
+ @ohai.attributes[:two][:_providers] = [@plugin2]
@ohai.attributes[:three] = Mash.new
- @ohai.attributes[:three][:providers] = [@plugin3]
+ @ohai.attributes[:three][:_providers] = [@plugin3]
@runner.should_receive(:fetch_providers).twice.with([]).and_return([])
@runner.should_receive(:fetch_providers).exactly(3).times.with(["one", "two"]).and_return([@plugin1, @plugin2])
@@ -180,8 +229,20 @@ describe Ohai::Runner, "run_plugin" do
@ohai = Ohai::System.new
@runner = Ohai::Runner.new(@ohai, true)
- klass1 = Ohai.plugin { provides("thing"); depends("other"); collect_data { thing(other) } }
- klass2 = Ohai.plugin { provides("other"); depends("thing"); collect_data { other(thing) } }
+ klass1 = Ohai.plugin(:Thing) {
+ provides("thing")
+ depends("other")
+ collect_data {
+ thing(other)
+ }
+ }
+ klass2 = Ohai.plugin(:Other) {
+ provides("other")
+ depends("thing")
+ collect_data {
+ other(thing)
+ }
+ }
@plugins = []
[klass1, klass2].each_with_index do |klass, idx|
@@ -202,9 +263,20 @@ describe Ohai::Runner, "run_plugin" do
@ohai = Ohai::System.new
@runner = Ohai::Runner.new(@ohai, true)
- klassA = Ohai.plugin { provides("A"); depends("B", "C"); collect_data { } }
- klassB = Ohai.plugin { provides("B"); depends("C"); collect_data { } }
- klassC = Ohai.plugin { provides("C"); collect_data { } }
+ klassA = Ohai.plugin(:A) {
+ provides("A")
+ depends("B", "C")
+ collect_data { }
+ }
+ klassB = Ohai.plugin(:B) {
+ provides("B")
+ depends("C")
+ collect_data { }
+ }
+ klassC = Ohai.plugin(:C) {
+ provides("C")
+ collect_data { }
+ }
@plugins = []
[klassA, klassB, klassC].each do |klass|
@@ -213,11 +285,11 @@ describe Ohai::Runner, "run_plugin" do
@pluginA, @pluginB, @pluginC = @plugins
@ohai.attributes[:A] = Mash.new
- @ohai.attributes[:A][:providers] = [@pluginA]
+ @ohai.attributes[:A][:_providers] = [@pluginA]
@ohai.attributes[:B] = Mash.new
- @ohai.attributes[:B][:providers] = [@pluginB]
+ @ohai.attributes[:B][:_providers] = [@pluginB]
@ohai.attributes[:C] = Mash.new
- @ohai.attributes[:C][:providers] = [@pluginC]
+ @ohai.attributes[:C][:_providers] = [@pluginC]
@runner.stub(:fetch_providers).with(["C"]).and_return([@pluginC])
@runner.stub(:fetch_providers).with([]).and_return([])
@@ -256,7 +328,7 @@ describe Ohai::Runner, "fetch_providers" do
it "should return the provider" do
plugin = Ohai::DSL::Plugin.new(@ohai, "")
@ohai.attributes[:single] = Mash.new
- @ohai.attributes[:single][:providers] = [plugin]
+ @ohai.attributes[:single][:_providers] = [plugin]
dependency_providers = @runner.fetch_providers(["single"])
dependency_providers.should eql([plugin])
@@ -268,7 +340,7 @@ describe Ohai::Runner, "fetch_providers" do
plugin1 = Ohai::DSL::Plugin.new(@ohai, "")
plugin2 = Ohai::DSL::Plugin.new(@ohai, "")
@ohai.attributes[:single] = Mash.new
- @ohai.attributes[:single][:providers] = [plugin1, plugin2]
+ @ohai.attributes[:single][:_providers] = [plugin1, plugin2]
dependency_providers = @runner.fetch_providers(["single"])
dependency_providers.should eql([plugin1, plugin2])
@@ -282,9 +354,9 @@ describe Ohai::Runner, "fetch_providers" do
plugin1 = Ohai::DSL::Plugin.new(@ohai, "")
plugin2 = Ohai::DSL::Plugin.new(@ohai, "")
@ohai.attributes[:one] = Mash.new
- @ohai.attributes[:one][:providers] = [plugin1]
+ @ohai.attributes[:one][:_providers] = [plugin1]
@ohai.attributes[:two] = Mash.new
- @ohai.attributes[:two][:providers] = [plugin2]
+ @ohai.attributes[:two][:_providers] = [plugin2]
dependency_providers = @runner.fetch_providers(["one", "two"])
dependency_providers.should eql([plugin1, plugin2])
@@ -295,9 +367,9 @@ describe Ohai::Runner, "fetch_providers" do
it "should return unique providers" do
plugin = Ohai::DSL::Plugin.new(@ohai, "")
@ohai.attributes[:one] = Mash.new
- @ohai.attributes[:one][:providers] = [plugin]
+ @ohai.attributes[:one][:_providers] = [plugin]
@ohai.attributes[:two] = Mash.new
- @ohai.attributes[:two][:providers] = [plugin]
+ @ohai.attributes[:two][:_providers] = [plugin]
dependency_providers = @runner.fetch_providers(["one", "two"])
dependency_providers.should eql([plugin])
@@ -311,7 +383,7 @@ describe Ohai::Runner, "fetch_providers" do
@ohai.attributes[:top] = Mash.new
@ohai.attributes[:top][:middle] = Mash.new
@ohai.attributes[:top][:middle][:bottom] = Mash.new
- @ohai.attributes[:top][:middle][:bottom][:providers] = [plugin]
+ @ohai.attributes[:top][:middle][:bottom][:_providers] = [plugin]
dependency_providers = @runner.fetch_providers(["top/middle/bottom"])
dependency_providers.should eql([plugin])
@@ -319,14 +391,32 @@ describe Ohai::Runner, "fetch_providers" do
end
end
-describe Ohai::Runner, "#cycle_sources" do
+describe Ohai::Runner, "#get_cycle" do
before(:each) do
@ohai = Ohai::System.new
@runner = Ohai::Runner.new(@ohai, true)
- klass1 = Ohai.plugin { provides("one"); depends("two"); collect_data { one(two) } }
- klass2 = Ohai.plugin { provides("two"); depends("one"); collect_data { two(one) } }
- klass3 = Ohai.plugin { provides("three"); depends("two"); collect_data { three(two) } }
+ klass1 = Ohai.plugin(:One) {
+ provides("one")
+ depends("two")
+ collect_data {
+ one(two)
+ }
+ }
+ klass2 = Ohai.plugin(:Two) {
+ provides("two")
+ depends("one")
+ collect_data {
+ two(one)
+ }
+ }
+ klass3 = Ohai.plugin(:Three) {
+ provides("three")
+ depends("two")
+ collect_data {
+ three(two)
+ }
+ }
plugins = []
[klass1, klass2, klass3].each_with_index do |klass, idx|
@@ -339,15 +429,15 @@ describe Ohai::Runner, "#cycle_sources" do
cycle = [@plugin1, @plugin2]
cycle_start = @plugin1
- sources = @runner.cycle_sources(cycle, cycle_start)
- sources.should eql([@plugin1.source, @plugin2.source])
+ cycle_names = @runner.get_cycle(cycle, cycle_start)
+ cycle_names.should eql([@plugin1.name, @plugin2.name])
end
it "should return the sources for only the plugins in the cycle, when there are plugins before the cycle begins" do
cycle = [@plugin3, @plugin1, @plugin2]
cycle_start = @plugin1
- sources = @runner.cycle_sources(cycle, cycle_start)
- sources.should eql([@plugin1.source, @plugin2.source])
+ cycle_names = @runner.get_cycle(cycle, cycle_start)
+ cycle_names.should eql([@plugin1.name, @plugin2.name])
end
end
diff --git a/spec/unit/system_spec.rb b/spec/unit/system_spec.rb
index c29ca2b2..b6607624 100644
--- a/spec/unit/system_spec.rb
+++ b/spec/unit/system_spec.rb
@@ -40,15 +40,15 @@ describe "Ohai::System" do
describe "#load_plugins" do
before(:each) do
- Ohai::OS.stub(:collect_os).and_return("ubuntu")
+ Ohai::Mixin::OS.stub(:collect_os).and_return("ubuntu")
loader = double('@loader')
Ohai::Loader.stub(:new) { loader }
@ohai = Ohai::System.new
- klass = Ohai.plugin { }
+ klass = Ohai.plugin(:Test) { }
plugin = klass.new(@ohai, "/tmp/plugins/empty.rb")
- loader.stub(:load_plugin).with("/tmp/plugins/empty.rb").and_return(plugin)
+ loader.stub(:load_plugin).with("/tmp/plugins/empty.rb", anything()).and_return(plugin)
end
it "should load plugins when plugin_path has a trailing slash" do
@@ -70,7 +70,7 @@ describe "Ohai::System" do
it "should add loaded plugins to @v6_dependency_solver" do
Ohai::Config[:plugin_path] = ["/tmp/plugins"]
- Ohai::OS.stub(:collect_os).and_return("ubuntu")
+ Ohai::Mixin::OS.stub(:collect_os).and_return("ubuntu")
Dir.should_receive(:[]).with("/tmp/plugins/*").and_return(["/tmp/plugins/empty.rb"])
Dir.should_receive(:[]).with("/tmp/plugins/ubuntu/**/*").and_return([])
File.stub(:expand_path).with("/tmp/plugins").and_return("/tmp/plugins")
@@ -83,15 +83,16 @@ describe "Ohai::System" do
describe "with v6 plugins only" do
before(:each) do
@ohai = Ohai::System.new
- @klass = Ohai.v6plugin { collect_contents("") }
@plugins = []
- 5.times do |x|
- @plugins << @klass.new(@ohai, "/tmp/plugins/plugin#{x}.rb")
- end
-
- ['one', 'two', 'three', 'four', 'five'].each_with_index do |plugin_name, idx|
- @ohai.v6_dependency_solver[plugin_name] = @plugins[idx]
+ @names = ['one', 'two', 'three', 'four', 'five']
+ @names.each do |name|
+ k = Ohai.v6plugin(name) {
+ collect_contents("")
+ }
+ p = k.new(@ohai, "/tmp/plugins/#{name}.rb")
+ @ohai.v6_dependency_solver[name] = p
+ @plugins << p
end
@ohai.stub(:collect_providers).and_return([])
@@ -125,7 +126,7 @@ describe "Ohai::System" do
Ohai::Runner.stub(:new) { @runner }
@ohai = Ohai::System.new
- klass = Ohai.plugin { }
+ klass = Ohai.plugin(:Empty) { }
plugin = klass.new(@ohai, "/tmp/plugins/empty.rb")
@ohai.stub(:collect_providers).and_return([plugin])
end
@@ -147,10 +148,21 @@ describe "Ohai::System" do
@ohai = Ohai::System.new
- klass = Ohai.plugin { provides("itself"); collect_data { itself("me") } }
+ @names = [:One, :Two, :Three, :Four, :Five]
+
+ klasses = []
+ @names.each do |name|
+ klasses << Ohai.plugin(name) {
+ provides("itself")
+ collect_data {
+ itself("me")
+ }
+ }
+ end
+
@plugins = []
- 5.times do |x|
- @plugins << klass.new(@ohai, "/tmp/plugins/plugin#{x}.rb")
+ klasses.each do |klass|
+ @plugins << klass.new(@ohai, "")
end
@ohai.stub(:collect_providers).and_return(@plugins)
@@ -167,17 +179,45 @@ describe "Ohai::System" do
describe "with v6 plugins that depend on v7 plugins" do
before(:each) do
@ohai = Ohai::System.new
+ loader = Ohai::Loader.new(@ohai)
- @plugin_path = Ohai::Config[:plugin_path]
- Ohai::Config[:plugin_path] = [File.expand_path(File.dirname(__FILE__) + '/../data/plugins')]
- @ohai.load_plugins
+ messages = <<EOF
+require_plugin 'v6message'
+require_plugin 'v7message'
+provides 'messages'
+
+messages Mash.new
+messages[:v6message] = v6message
+messages[:v7message] = v7message
+EOF
+ v6message = <<EOF
+provides 'v6message'
+v6message "update me!"
+EOF
+ v7message = <<EOF
+Ohai.plugin(:V7message) do
+ provides 'v7message'
+
+ collect_data(:default) do
+ v7message "v7 plugins are awesome!"
+ end
+end
+EOF
+ @names = [:Messages, :V6message, :V7message]
@plugins = []
- @ohai.v6_dependency_solver.each { |plugin_name, plugin| @plugins << plugin }
- end
+ [
+ [messages, :Messages],
+ [v6message, :V6message],
+ [v7message, :V7message]
+ ].each do |contents, name|
+ IO.stub(:read).with("tmp/#{name.to_s.downcase}.rb").and_return(contents)
+ @plugins << loader.load_plugin("tmp/#{name.to_s.downcase}.rb", name)
+ end
- after(:each) do
- Ohai::Config[:plugin_path] = @plugin_path
+ @plugins.each do |plugin|
+ @ohai.v6_dependency_solver[File.basename(plugin.source, '.rb')] = plugin
+ end
end
it "should run each plugin" do
@@ -205,24 +245,25 @@ describe "Ohai::System" do
before(:each) do
@ohai = Ohai::System.new
- klass = Ohai.plugin { }
+ @names = [:Zero, :One, :Two, :Three]
@plugins = []
- 4.times do
- @plugins << klass.new(@ohai, "")
+ @names.each do |name|
+ k = Ohai.plugin(name) { }
+ @plugins << k.new(@ohai, "")
end
end
it "should find all the plugins providing attributes" do
a = @ohai.attributes
a[:zero] = Mash.new
- a[:zero][:providers] = [@plugins[0]]
+ a[:zero][:_providers] = [@plugins[0]]
a[:one] = Mash.new
- a[:one][:providers] = [@plugins[1]]
+ a[:one][:_providers] = [@plugins[1]]
a[:one][:two] = Mash.new
- a[:one][:two][:providers] = [@plugins[2]]
+ a[:one][:two][:_providers] = [@plugins[2]]
a[:stub] = Mash.new
a[:stub][:three] = Mash.new
- a[:stub][:three][:providers] = [@plugins[3]]
+ a[:stub][:three][:_providers] = [@plugins[3]]
providers = @ohai.collect_providers(@ohai.attributes)
providers.size.should eql(@plugins.size)
@@ -238,16 +279,12 @@ describe "Ohai::System" do
Ohai::Config[:plugin_path] = ["/tmp/plugins"]
@ohai = Ohai::System.new
- klass = Ohai.v6plugin { }
+ klass = Ohai.v6plugin("empty") { }
@plugin = klass.new(@ohai, "/tmp/plugins/empty.rb")
@ohai.stub(:plugin_for).with("empty").and_return(@plugin)
end
- after(:each) do
- Ohai::Config[:plugin_path] = @plugin_path
- end
-
it "should immediately return if force is false and the plugin has already run" do
@ohai.v6_dependency_solver['empty'] = @plugin
@plugin.stub(:has_run?).and_return(true)
@@ -307,15 +344,18 @@ provides 'v6attr'
require_plugin 'v7plugin'
v6attr message
EOF
- v6klass = Ohai.v6plugin { collect_contents(v6string) }
- v7klass = Ohai.plugin { provides("message"); collect_data { message("hey.") } }
+ v6klass = Ohai.v6plugin('v6plugin') { collect_contents(v6string) }
+ v7klass = Ohai.plugin(:V7plugin) {
+ provides("message")
+ collect_data { message("hey.") }
+ }
@v6plugin = v6klass.new(@ohai, "/tmp/plugins/v6plugin.rb")
@v7plugin = v7klass.new(@ohai, "/tmp/plugins/v7plugin.rb")
@ohai.v6_dependency_solver['v6plugin'] = @v6plugin
@ohai.v6_dependency_solver['v7plugin'] = @v7plugin
@ohai.attributes[:message] = Mash.new
- @ohai.attributes[:message][:providers] = [@v7plugin]
+ @ohai.attributes[:message][:_providers] = [@v7plugin]
end
it "should run the plugin it requires" do
@@ -340,9 +380,16 @@ provides 'v6attr'
require_plugin 'v7plugin'
v6attr message
EOF
- v6klass = Ohai.v6plugin { collect_contents(v6string) }
- v7klass = Ohai.plugin { provides("message"); depends("other"); collect_data{ message(other) } }
- otherklass = Ohai.plugin { provides("other"); collect_data{ other("o hai") } }
+ v6klass = Ohai.v6plugin('v6plugin') { collect_contents(v6string) }
+ v7klass = Ohai.plugin(:V7plugin) {
+ provides("message")
+ depends("other")
+ collect_data{ message(other) }
+ }
+ otherklass = Ohai.plugin(:Other) {
+ provides("other")
+ collect_data{ other("o hai") }
+ }
@v6plugin = v6klass.new(@ohai, "/tmp/plugin/v6plugin.rb")
@v7plugin = v7klass.new(@ohai, "/tmp/plugins/v7plugin.rb")
@@ -355,9 +402,9 @@ EOF
a = @ohai.attributes
a[:message] = Mash.new
- a[:message][:providers] = [@v7plugin]
+ a[:message][:_providers] = [@v7plugin]
a[:other] = Mash.new
- a[:other][:providers] = [@other]
+ a[:other][:_providers] = [@other]
end
it "should resolve the v7 plugin dependencies" do
@@ -388,7 +435,7 @@ EOF
Ohai::Loader.stub(:new) { @loader }
@ohai = Ohai::System.new
- @klass = Ohai.v6plugin { }
+ @klass = Ohai.v6plugin('empty') { }
end
it "should find a plugin with a simple name" do
@@ -396,7 +443,7 @@ EOF
File.stub(:join).with("/tmp/plugins", "empty.rb").and_return("/tmp/plugins/empty.rb")
File.stub(:expand_path).with("/tmp/plugins/empty.rb").and_return("/tmp/plugins/empty.rb")
File.stub(:exist?).with("/tmp/plugins/empty.rb").and_return(true)
- @loader.stub(:load_plugin).with("/tmp/plugins/empty.rb").and_return(plugin)
+ @loader.stub(:load_plugin).with("/tmp/plugins/empty.rb", "empty").and_return(plugin)
found_plugin = @ohai.plugin_for("empty")
found_plugin.should eql(plugin)
@@ -407,7 +454,7 @@ EOF
File.stub(:join).with("/tmp/plugins", "ubuntu/empty.rb").and_return("/tmp/plugins/ubuntu/empty.rb")
File.stub(:expand_path).with("/tmp/plugins/ubuntu/empty.rb").and_return("/tmp/plugins/ubuntu/empty.rb")
File.stub(:exist?).with("/tmp/plugins/ubuntu/empty.rb").and_return(true)
- @loader.stub(:load_plugin).with("/tmp/plugins/ubuntu/empty.rb").and_return(plugin)
+ @loader.stub(:load_plugin).with("/tmp/plugins/ubuntu/empty.rb", "ubuntu::empty").and_return(plugin)
found_plugin = @ohai.plugin_for("ubuntu::empty")
found_plugin.should eql(plugin)
@@ -426,7 +473,7 @@ EOF
File.stub(:join).with("/tmp/plugins", "empty.rb").and_return("/tmp/plugins/empty.rb")
File.stub(:expand_path).with("/tmp/plugins/empty.rb").and_return("/tmp/plugins/empty.rb")
File.stub(:exist?).with("/tmp/plugins/empty.rb").and_return(true)
- @loader.stub(:load_plugin).with("/tmp/plugins/empty.rb").and_return(plugin)
+ @loader.stub(:load_plugin).with("/tmp/plugins/empty.rb", "empty").and_return(plugin)
@ohai.plugin_for("empty")
@ohai.v6_dependency_solver.should have_key('empty')