Skip to content

Commit

Permalink
Merge pull request #169 from opscode/OHAI-9230
Browse files Browse the repository at this point in the history
Remove plugin names. Ohai.plugin replaces Ohai.plugin(:Name).
  • Loading branch information
Claire McQuin committed Aug 13, 2013
2 parents d223473 + bc4cd37 commit 10e234f
Show file tree
Hide file tree
Showing 146 changed files with 230 additions and 173 deletions.
17 changes: 15 additions & 2 deletions lib/ohai/dsl/plugin.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#
# Author:: Claire McQuin (<claire@opscode.com>)
# Copyright:: Copyright (c) 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 'ohai/os'
Expand All @@ -11,9 +25,8 @@ module Ohai
#=========================================================
# define new plugin class
#=========================================================
def self.plugin(plugin_name, &block)
def self.plugin(&block)
plugin_class = Class.new(DSL::Plugin, &block)
const_set(plugin_name, plugin_class)
end

module DSL
Expand Down
22 changes: 18 additions & 4 deletions lib/ohai/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ class Loader
def initialize(controller)
@attributes = controller.attributes
@plugins = controller.plugins
@sources = controller.sources
end

def load_plugin(plugin_path, plugin_name=nil)
clean_up(plugin_path) if @sources.has_key?(plugin_path)

plugin = nil

begin
Expand All @@ -47,19 +50,30 @@ def load_plugin(plugin_path, plugin_name=nil)
return
end

plugin_key = plugin_name || plugin.name
plugin_key = plugin_name || plugin.to_s
register_plugin(plugin, plugin_path, plugin_key)
collect_provides(plugin, plugin_key)
end

private

def clean_up(file)
key = @sources[file]
@plugins[key][:provides].each do |attr|
@attributes[attr][:providers].delete(key)
end

@plugins.delete(key)
@sources.delete(file)
end

def register_plugin(plugin, file, plugin_key)
@plugins[plugin_key] ||= Mash.new
@sources[file] = plugin_key

p = @plugins[plugin_key]
p[:plugin] = plugin
p[:source] = file
p[:provides] = plugin.provides_attrs
p[:depends] = plugin.depends_attrs
end

Expand All @@ -78,8 +92,8 @@ def collect_provides(plugin, plugin_key)
end
end

a[:_providers] ||= []
a[:_providers] << plugin_key
a[:providers] ||= []
a[:providers] << plugin_key
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/aix/cpu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
# limitations under the License.
#

Ohai.plugin(:Cpu) do
Ohai.plugin do
depends "sigar::cpu"
end
2 changes: 1 addition & 1 deletion lib/ohai/plugins/aix/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
# limitations under the License.
#

Ohai.plugin(:Filesystem) do
Ohai.plugin do
depends "sigar::filesystem"
end
2 changes: 1 addition & 1 deletion lib/ohai/plugins/aix/hostname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
# limitations under the License.
#

Ohai.plugin(:Hostname) do
Ohai.plugin do
depends "sigar::hostname"
end
2 changes: 1 addition & 1 deletion lib/ohai/plugins/aix/memory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
# limitations under the License.
#

Ohai.plugin(:Memory) do
Ohai.plugin do
depends "sigar::memory"
end
2 changes: 1 addition & 1 deletion lib/ohai/plugins/aix/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
# limitations under the License.
#

Ohai.plugin(:Network) do
Ohai.plugin do
depends "sigar::network"
end
2 changes: 1 addition & 1 deletion lib/ohai/plugins/aix/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
# limitations under the License.
#

Ohai.plugin(:Platform) do
Ohai.plugin do
depends "sigar::platform"
end
2 changes: 1 addition & 1 deletion lib/ohai/plugins/aix/ps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.
#

Ohai.plugin(:Ps) do
Ohai.plugin do
provides "command/ps"

depends 'command'
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/aix/uptime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
# limitations under the License.
#

Ohai.plugin(:Uptime) do
Ohai.plugin do
depends "sigar::uptime"
end
2 changes: 1 addition & 1 deletion lib/ohai/plugins/azure.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Ohai.plugin(:Azure) do
Ohai.plugin do
provides "azure"

collect_data do
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

require 'rbconfig'

Ohai.plugin(:C) do
Ohai.plugin do
provides "languages/c"

depends "languages"
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/chef.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

require 'chef/version'

Ohai.plugin(:CHEF) do
Ohai.plugin do
provides "chef"

collect_data do
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/cloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

Ohai.plugin(:Cloud) do
Ohai.plugin do
provides "cloud"

depends "ec2"
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.
#

Ohai.plugin(:Command) do
Ohai.plugin do
provides "command"

collect_data do
Expand Down
7 changes: 0 additions & 7 deletions lib/ohai/plugins/counters.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/ohai/plugins/darwin/cpu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.
#

Ohai.plugin(:DarwinCpu) do
Ohai.plugin do
provides "cpu"

collect_data do
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/darwin/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.
#

Ohai.plugin(:DarwinFilesystem) do
Ohai.plugin do
provides "filesystem"

collect_data do
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/darwin/hostname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.
#

Ohai.plugin(:DarwinHostname) do
Ohai.plugin do
provides "fqdn", "hostname"

collect_data do
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/darwin/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.
#

Ohai.plugin(:DarwinKernel) do
Ohai.plugin do
provides "kernel"

collect_data do
Expand Down
9 changes: 6 additions & 3 deletions lib/ohai/plugins/darwin/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

require 'scanf'

Ohai.plugin(:DarwinNetwork) do
Ohai.plugin do
provides "network", "counters/network"

def parse_media(media_string)
Expand Down Expand Up @@ -85,7 +85,10 @@ def locate_interface(ifaces, ifname, mac)
end

collect_data do
network Mash.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]

from("route -n get default").split("\n").each do |line|
if line =~ /(\w+): ([\w\.]+)/
Expand All @@ -97,7 +100,7 @@ def locate_interface(ifaces, ifname, mac)
end
end
end

iface = Mash.new
popen4("ifconfig -a") do |pid, stdin, stdout, stderr|
stdin.close
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/darwin/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.
#

Ohai.plugin(:DarwinPlatform) do
Ohai.plugin do
provides "platform", "platform_version", "platform_build", "platform_family"

collect_data do
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/darwin/ps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.
#

Ohai.plugin(:DarwinPs) do
Ohai.plugin do
provides "command/ps"

depends 'command'
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/darwin/system_profiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.
#

Ohai.plugin(:DarwinSystemProfile) do
Ohai.plugin do
provides "system_profile"

collect_data do
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/darwin/uptime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.
#

Ohai.plugin(:DarwinUptime) do
Ohai.plugin do
provides "uptime", "uptime_seconds"

# kern.boottime: { sec = 1232765114, usec = 823118 } Fri Jan 23 18:45:14 2009
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/dmi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

require "ohai/plugins/dmi_common"

Ohai.plugin(:Dmi) do
Ohai.plugin do
provides "dmi"

# dmidecode does not return data without access to /dev/mem (or its equivalent)
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

require 'ohai/mixin/ec2_metadata'

Ohai.plugin(:Ec2) do
Ohai.plugin do
include Ohai::Mixin::Ec2Metadata

provides "ec2"
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/erlang.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.
#

Ohai.plugin(:Erlang) do
Ohai.plugin do
provides "languages/erlang"

depends "languages"
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/eucalyptus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

require 'ohai/mixin/ec2_metadata'

Ohai.plugin(:Eucalyptus) do
Ohai.plugin do
include Ohai::Mixin::Ec2Metadata

provides "eucalyptus"
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/freebsd/cpu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.
#

Ohai.plugin(:Cpu) do
Ohai.plugin do
provides "cpu"

collect_data do
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/freebsd/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.
#

Ohai.plugin(:Filesystem) do
Ohai.plugin do
provides "filesystem"

collect_data do
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/freebsd/hostname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.
#

Ohai.plugin(:Hostname) do
Ohai.plugin do
provides "hostname", "fqdn"

collect_data do
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/freebsd/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.
#

Ohai.plugin(:Kernel) do
Ohai.plugin do
provides "kernel"

collect_data do
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/freebsd/memory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.
#

Ohai.plugin(:Memory) do
Ohai.plugin do
provides "memory"

collect_data do
Expand Down
Loading

0 comments on commit 10e234f

Please sign in to comment.