diff options
| author | Nick Lewis <nick@puppetlabs.com> | 2011-03-22 16:44:01 -0700 |
|---|---|---|
| committer | Nick Lewis <nick@puppetlabs.com> | 2011-03-22 17:18:51 -0700 |
| commit | 847ac203f9c0b5fce299e87a63b0de5d3ef416f6 (patch) | |
| tree | 1177637a9ae75527b14523d3803c610601e5d54b /lib/puppet/interface | |
| parent | 01ce91816fe061267e9821c07fefb8aa14af4a14 (diff) | |
| download | puppet-847ac203f9c0b5fce299e87a63b0de5d3ef416f6.tar.gz puppet-847ac203f9c0b5fce299e87a63b0de5d3ef416f6.tar.xz puppet-847ac203f9c0b5fce299e87a63b0de5d3ef416f6.zip | |
maint: Implement an InterfaceCollection class to manage interfaces
Having an instance variable on class Interface is insufficient for
Interface::Indirector. This also changes the semantics of "Interface.interface"
to handle registration and loading actions, and for "Interface.new" to only
instantiate an Interface. Thus, consumers of the API should typically use
"Interface.interface", unless they have reasons to not want an interface
automatically registered.
Paired-With: Pieter van de Bruggen
Diffstat (limited to 'lib/puppet/interface')
| -rw-r--r-- | lib/puppet/interface/catalog.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/interface/certificate.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/interface/certificate_request.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/interface/certificate_revocation_list.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/interface/config.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/interface/configurer.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/interface/facts.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/interface/file.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/interface/interface_collection.rb | 50 | ||||
| -rw-r--r-- | lib/puppet/interface/key.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/interface/node.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/interface/report.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/interface/resource.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/interface/resource_type.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/interface/status.rb | 2 |
15 files changed, 64 insertions, 14 deletions
diff --git a/lib/puppet/interface/catalog.rb b/lib/puppet/interface/catalog.rb index c0af53bac..defe32127 100644 --- a/lib/puppet/interface/catalog.rb +++ b/lib/puppet/interface/catalog.rb @@ -1,6 +1,6 @@ require 'puppet/interface/indirector' -Puppet::Interface::Indirector.new(:catalog) do +Puppet::Interface::Indirector.interface(:catalog) do action(:apply) do invoke do |catalog| report = Puppet::Transaction::Report.new("apply") diff --git a/lib/puppet/interface/certificate.rb b/lib/puppet/interface/certificate.rb index 52ba4e3b8..09da0a6c3 100644 --- a/lib/puppet/interface/certificate.rb +++ b/lib/puppet/interface/certificate.rb @@ -1,4 +1,4 @@ require 'puppet/interface/indirector' -Puppet::Interface::Indirector.new(:certificate) do +Puppet::Interface::Indirector.interface(:certificate) do end diff --git a/lib/puppet/interface/certificate_request.rb b/lib/puppet/interface/certificate_request.rb index 77b485f8e..b85c15fef 100644 --- a/lib/puppet/interface/certificate_request.rb +++ b/lib/puppet/interface/certificate_request.rb @@ -1,4 +1,4 @@ require 'puppet/interface/indirector' -Puppet::Interface::Indirector.new(:certificate_request) do +Puppet::Interface::Indirector.interface(:certificate_request) do end diff --git a/lib/puppet/interface/certificate_revocation_list.rb b/lib/puppet/interface/certificate_revocation_list.rb index ee1e6a8c4..956fb6494 100644 --- a/lib/puppet/interface/certificate_revocation_list.rb +++ b/lib/puppet/interface/certificate_revocation_list.rb @@ -1,4 +1,4 @@ require 'puppet/interface/indirector' -Puppet::Interface::Indirector.new(:certificate_revocation_list) do +Puppet::Interface::Indirector.interface(:certificate_revocation_list) do end diff --git a/lib/puppet/interface/config.rb b/lib/puppet/interface/config.rb index 0aecc263f..79d2ee7c1 100644 --- a/lib/puppet/interface/config.rb +++ b/lib/puppet/interface/config.rb @@ -1,6 +1,6 @@ require 'puppet/interface' -Puppet::Interface.new(:config) do +Puppet::Interface.interface(:config) do action(:print) do invoke do |*args| Puppet.settings[:configprint] = args.join(",") diff --git a/lib/puppet/interface/configurer.rb b/lib/puppet/interface/configurer.rb index 2fbde27f1..0d21c4d72 100644 --- a/lib/puppet/interface/configurer.rb +++ b/lib/puppet/interface/configurer.rb @@ -1,6 +1,6 @@ require 'puppet/interface' -Puppet::Interface.new(:configurer) do +Puppet::Interface.interface(:configurer) do action(:synchronize) do invoke do |certname| facts = Puppet::Interface.interface(:facts).find(certname) diff --git a/lib/puppet/interface/facts.rb b/lib/puppet/interface/facts.rb index 8843d297d..97e22714b 100644 --- a/lib/puppet/interface/facts.rb +++ b/lib/puppet/interface/facts.rb @@ -1,7 +1,7 @@ require 'puppet/interface/indirector' require 'puppet/node/facts' -Puppet::Interface::Indirector.new(:facts) do +Puppet::Interface::Indirector.interface(:facts) do set_default_format :yaml # Upload our facts to the server diff --git a/lib/puppet/interface/file.rb b/lib/puppet/interface/file.rb index 859f92ca4..f38af2b92 100644 --- a/lib/puppet/interface/file.rb +++ b/lib/puppet/interface/file.rb @@ -1,5 +1,5 @@ require 'puppet/interface/indirector' -Puppet::Interface::Indirector.new(:file) do +Puppet::Interface::Indirector.interface(:file) do set_indirection_name :file_bucket_file end diff --git a/lib/puppet/interface/interface_collection.rb b/lib/puppet/interface/interface_collection.rb new file mode 100644 index 000000000..47ed702aa --- /dev/null +++ b/lib/puppet/interface/interface_collection.rb @@ -0,0 +1,50 @@ +require 'puppet/interface' + +module Puppet::Interface::InterfaceCollection + @interfaces = {} + + def self.interfaces + unless @loaded + @loaded = true + $LOAD_PATH.each do |dir| + next unless FileTest.directory?(dir) + Dir.chdir(dir) do + Dir.glob("puppet/interface/*.rb").collect { |f| f.sub(/\.rb/, '') }.each do |file| + iname = file.sub(/\.rb/, '') + begin + require iname + rescue Exception => detail + puts detail.backtrace if Puppet[:trace] + raise "Could not load #{iname} from #{dir}/#{file}: #{detail}" + end + end + end + end + end + return @interfaces.keys + end + + def self.[](name) + @interfaces[underscorize(name)] if interface?(name) + end + + def self.interface?(name) + name = underscorize(name) + require "puppet/interface/#{name}" unless @interfaces.has_key? name + return @interfaces.has_key? name + rescue LoadError + return false + end + + def self.register(interface) + @interfaces[underscorize(interface.name)] = interface + end + + def self.underscorize(name) + unless name.to_s =~ /^[-_a-z]+$/i then + raise ArgumentError, "#{name.inspect} (#{name.class}) is not a valid interface name" + end + + name.to_s.downcase.split(/[-_]/).join('_').to_sym + end +end diff --git a/lib/puppet/interface/key.rb b/lib/puppet/interface/key.rb index 9343891d0..57519883d 100644 --- a/lib/puppet/interface/key.rb +++ b/lib/puppet/interface/key.rb @@ -1,4 +1,4 @@ require 'puppet/interface/indirector' -Puppet::Interface::Indirector.new(:key) do +Puppet::Interface::Indirector.interface(:key) do end diff --git a/lib/puppet/interface/node.rb b/lib/puppet/interface/node.rb index 0a0f57a1e..8940fd7dd 100644 --- a/lib/puppet/interface/node.rb +++ b/lib/puppet/interface/node.rb @@ -1,5 +1,5 @@ require 'puppet/interface/indirector' -Puppet::Interface::Indirector.new(:node) do +Puppet::Interface::Indirector.interface(:node) do set_default_format :yaml end diff --git a/lib/puppet/interface/report.rb b/lib/puppet/interface/report.rb index e785ae22d..56a58f6aa 100644 --- a/lib/puppet/interface/report.rb +++ b/lib/puppet/interface/report.rb @@ -1,6 +1,6 @@ require 'puppet/interface/indirector' -Puppet::Interface::Indirector.new(:report) do +Puppet::Interface::Indirector.interface(:report) do action(:submit) do invoke do |report| begin diff --git a/lib/puppet/interface/resource.rb b/lib/puppet/interface/resource.rb index 65f2dec7a..130f40fce 100644 --- a/lib/puppet/interface/resource.rb +++ b/lib/puppet/interface/resource.rb @@ -1,4 +1,4 @@ require 'puppet/interface/indirector' -Puppet::Interface::Indirector.new(:resource) do +Puppet::Interface::Indirector.interface(:resource) do end diff --git a/lib/puppet/interface/resource_type.rb b/lib/puppet/interface/resource_type.rb index bf16652a8..70bf3b95a 100644 --- a/lib/puppet/interface/resource_type.rb +++ b/lib/puppet/interface/resource_type.rb @@ -1,4 +1,4 @@ require 'puppet/interface/indirector' -Puppet::Interface::Indirector.new(:resource_type) do +Puppet::Interface::Indirector.interface(:resource_type) do end diff --git a/lib/puppet/interface/status.rb b/lib/puppet/interface/status.rb index 1a1d349d1..432d1ce54 100644 --- a/lib/puppet/interface/status.rb +++ b/lib/puppet/interface/status.rb @@ -1,4 +1,4 @@ require 'puppet/interface/indirector' -Puppet::Interface::Indirector.new(:status) do +Puppet::Interface::Indirector.interface(:status) do end |
