summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/interface.rb67
-rw-r--r--lib/puppet/interface/catalog.rb4
-rw-r--r--lib/puppet/interface/certificate.rb4
-rw-r--r--lib/puppet/interface/certificate_request.rb4
-rw-r--r--lib/puppet/interface/certificate_revocation_list.rb4
-rw-r--r--lib/puppet/interface/facts.rb4
-rw-r--r--lib/puppet/interface/file.rb4
-rw-r--r--lib/puppet/interface/indirector.rb82
-rw-r--r--lib/puppet/interface/inventory.rb4
-rw-r--r--lib/puppet/interface/key.rb4
-rw-r--r--lib/puppet/interface/node.rb4
-rw-r--r--lib/puppet/interface/report.rb4
-rw-r--r--lib/puppet/interface/resource.rb4
-rw-r--r--lib/puppet/interface/resource_type.rb4
-rw-r--r--lib/puppet/interface/status.rb4
15 files changed, 109 insertions, 92 deletions
diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb
index 08a26db90..999c38bad 100644
--- a/lib/puppet/interface.rb
+++ b/lib/puppet/interface.rb
@@ -38,21 +38,6 @@ class Puppet::Interface
end).sort { |a,b| a.to_s <=> b.to_s }
end
- # Here's your opportunity to override the indirection name. By default
- # it will be the same name as the interface.
- def self.indirection_name
- name.to_sym
- end
-
- # Return an indirection associated with an interface, if one exists
- # One usually does.
- def self.indirection
- unless @indirection
- raise "Could not find data type '#{indirection_name}' for interface '#{name}'" unless @indirection = Puppet::Indirector::Indirection.instance(indirection_name)
- end
- @indirection
- end
-
# Return an interface by name, loading from disk if necessary.
def self.interface(name)
require "puppet/interface/#{name.to_s.downcase}"
@@ -83,7 +68,7 @@ class Puppet::Interface
@name || self.to_s.sub(/.+::/, '').downcase
end
- attr_accessor :from, :type, :verb, :name, :arguments, :indirection
+ attr_accessor :type, :verb, :name, :arguments
def action?(name)
self.class.actions.include?(name.to_sym)
@@ -98,26 +83,6 @@ class Puppet::Interface
end
end
- action :destroy do |name, *args|
- call_indirection_method(:destroy, name, *args)
- end
-
- action :find do |name, *args|
- call_indirection_method(:find, name, *args)
- end
-
- action :save do |name, *args|
- call_indirection_method(:save, name, *args)
- end
-
- action :search do |name, *args|
- call_indirection_method(:search, name, *args)
- end
-
- def indirection
- self.class.indirection
- end
-
def initialize(options = {})
options.each { |opt, val| send(opt.to_s + "=", val) }
@@ -126,34 +91,4 @@ class Puppet::Interface
self.class.load_actions
end
- def set_terminus(from)
- begin
- indirection.terminus_class = from
- rescue => detail
- raise "Could not set '#{indirection.name}' terminus to '#{from}' (#{detail}); valid terminus types are #{terminus_classes(indirection.name).join(", ") }"
- end
- end
-
- def call_indirection_method(method, name, *args)
- begin
- result = indirection.send(method, name, *args)
- rescue => detail
- puts detail.backtrace if Puppet[:trace]
- raise "Could not call #{method} on #{type}: #{detail}"
- end
-
- unless result
- raise "Could not #{method} #{indirection.name} for #{name}"
- end
-
- result
- end
-
- def indirections
- Puppet::Indirector::Indirection.instances.collect { |t| t.to_s }.sort
- end
-
- def terminus_classes(indirection)
- Puppet::Indirector::Terminus.terminus_classes(indirection).collect { |t| t.to_s }.sort
- end
end
diff --git a/lib/puppet/interface/catalog.rb b/lib/puppet/interface/catalog.rb
index 23e2b9cf5..85aa2f37a 100644
--- a/lib/puppet/interface/catalog.rb
+++ b/lib/puppet/interface/catalog.rb
@@ -1,4 +1,4 @@
-require 'puppet/interface'
+require 'puppet/interface/indirector'
-class Puppet::Interface::Catalog < Puppet::Interface
+class Puppet::Interface::Catalog < Puppet::Interface::Indirector
end
diff --git a/lib/puppet/interface/certificate.rb b/lib/puppet/interface/certificate.rb
index 51e46c46b..48ca2c20f 100644
--- a/lib/puppet/interface/certificate.rb
+++ b/lib/puppet/interface/certificate.rb
@@ -1,4 +1,4 @@
-require 'puppet/interface'
+require 'puppet/interface/indirector'
-class Puppet::Interface::Certificate < Puppet::Interface
+class Puppet::Interface::Certificate < Puppet::Interface::Indirector
end
diff --git a/lib/puppet/interface/certificate_request.rb b/lib/puppet/interface/certificate_request.rb
index 30ba5583a..29dc73b9a 100644
--- a/lib/puppet/interface/certificate_request.rb
+++ b/lib/puppet/interface/certificate_request.rb
@@ -1,4 +1,4 @@
-require 'puppet/interface'
+require 'puppet/interface/indirector'
-class Puppet::Interface::Certificate_request < Puppet::Interface
+class Puppet::Interface::Certificate_request < Puppet::Interface::Indirector
end
diff --git a/lib/puppet/interface/certificate_revocation_list.rb b/lib/puppet/interface/certificate_revocation_list.rb
index 55a693918..144d5ef61 100644
--- a/lib/puppet/interface/certificate_revocation_list.rb
+++ b/lib/puppet/interface/certificate_revocation_list.rb
@@ -1,4 +1,4 @@
-require 'puppet/interface'
+require 'puppet/interface/indirector'
-class Puppet::Interface::Certificate_revocation_list < Puppet::Interface
+class Puppet::Interface::Certificate_revocation_list < Puppet::Interface::Indirector
end
diff --git a/lib/puppet/interface/facts.rb b/lib/puppet/interface/facts.rb
index e40bb56d0..42ba1fb81 100644
--- a/lib/puppet/interface/facts.rb
+++ b/lib/puppet/interface/facts.rb
@@ -1,6 +1,6 @@
-require 'puppet/interface'
+require 'puppet/interface/indirector'
-class Puppet::Interface::Facts < Puppet::Interface
+class Puppet::Interface::Facts < Puppet::Interface::Indirector
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 53c476d7c..98a869153 100644
--- a/lib/puppet/interface/file.rb
+++ b/lib/puppet/interface/file.rb
@@ -1,6 +1,6 @@
-require 'puppet/interface'
+require 'puppet/interface/indirector'
-class Puppet::Interface::File < Puppet::Interface
+class Puppet::Interface::File < Puppet::Interface::Indirector
def self.indirection_name
:file_bucket_file
end
diff --git a/lib/puppet/interface/indirector.rb b/lib/puppet/interface/indirector.rb
new file mode 100644
index 000000000..f0beb8a9c
--- /dev/null
+++ b/lib/puppet/interface/indirector.rb
@@ -0,0 +1,82 @@
+require 'puppet'
+require 'puppet/interface'
+
+class Puppet::Interface::Indirector < Puppet::Interface
+
+
+ # Here's your opportunity to override the indirection name. By default
+ # it will be the same name as the interface.
+ def self.indirection_name
+ name.to_sym
+ end
+
+ # Return an indirection associated with an interface, if one exists
+ # One usually does.
+ def self.indirection
+ unless @indirection
+ Puppet.info("Could not find terminus for #{indirection_name}") unless @indirection = Puppet::Indirector::Indirection.instance(indirection_name)
+ end
+ @indirection
+ end
+
+ attr_accessor :from, :indirection
+
+ action :destroy do |name, *args|
+ call_indirection_method(:destroy, name, *args)
+ end
+
+ action :find do |name, *args|
+ call_indirection_method(:find, name, *args)
+ end
+
+ action :save do |name, *args|
+ call_indirection_method(:save, name, *args)
+ end
+
+ action :search do |name, *args|
+ call_indirection_method(:search, name, *args)
+ end
+
+ def indirection
+ self.class.indirection
+ end
+
+ def initialize(options = {})
+ options.each { |opt, val| send(opt.to_s + "=", val) }
+
+ Puppet::Util::Log.newdestination :console
+
+ self.class.load_actions
+ end
+
+ def set_terminus(from)
+ begin
+ indirection.terminus_class = from
+ rescue => detail
+ raise "Could not set '#{indirection.name}' terminus to '#{from}' (#{detail}); valid terminus types are #{terminus_classes(indirection.name).join(", ") }"
+ end
+ end
+
+ def call_indirection_method(method, name, *args)
+ begin
+ result = indirection.send(method, name, *args)
+ rescue => detail
+ puts detail.backtrace if Puppet[:trace]
+ raise "Could not call #{method} on #{type}: #{detail}"
+ end
+
+ unless result
+ raise "Could not #{method} #{indirection.name} for #{name}"
+ end
+
+ result
+ end
+
+ def indirections
+ Puppet::Indirector::Indirection.instances.collect { |t| t.to_s }.sort
+ end
+
+ def terminus_classes(indirection)
+ Puppet::Indirector::Terminus.terminus_classes(indirection).collect { |t| t.to_s }.sort
+ end
+end
diff --git a/lib/puppet/interface/inventory.rb b/lib/puppet/interface/inventory.rb
index 7521239d5..16b216b8b 100644
--- a/lib/puppet/interface/inventory.rb
+++ b/lib/puppet/interface/inventory.rb
@@ -1,4 +1,4 @@
-require 'puppet/interface'
+require 'puppet/interface/indirector'
-class Puppet::Interface::Inventory < Puppet::Interface
+class Puppet::Interface::Inventory < Puppet::Interface::Indirector
end
diff --git a/lib/puppet/interface/key.rb b/lib/puppet/interface/key.rb
index 38f92c66b..17b661da1 100644
--- a/lib/puppet/interface/key.rb
+++ b/lib/puppet/interface/key.rb
@@ -1,4 +1,4 @@
-require 'puppet/interface'
+require 'puppet/interface/indirector'
-class Puppet::Interface::Key < Puppet::Interface
+class Puppet::Interface::Key < Puppet::Interface::Indirector
end
diff --git a/lib/puppet/interface/node.rb b/lib/puppet/interface/node.rb
index 68e30698e..5d9efa932 100644
--- a/lib/puppet/interface/node.rb
+++ b/lib/puppet/interface/node.rb
@@ -1,4 +1,4 @@
-require 'puppet/interface'
+require 'puppet/interface/indirector'
-class Puppet::Interface::Node < Puppet::Interface
+class Puppet::Interface::Node < Puppet::Interface::Indirector
end
diff --git a/lib/puppet/interface/report.rb b/lib/puppet/interface/report.rb
index 72f1285ea..fd6f45f16 100644
--- a/lib/puppet/interface/report.rb
+++ b/lib/puppet/interface/report.rb
@@ -1,4 +1,4 @@
-require 'puppet/interface'
+require 'puppet/interface/indirector'
-class Puppet::Interface::Report < Puppet::Interface
+class Puppet::Interface::Report < Puppet::Interface::Indirector
end
diff --git a/lib/puppet/interface/resource.rb b/lib/puppet/interface/resource.rb
index b9b007d00..deed0a533 100644
--- a/lib/puppet/interface/resource.rb
+++ b/lib/puppet/interface/resource.rb
@@ -1,4 +1,4 @@
-require 'puppet/interface'
+require 'puppet/interface/indirector'
-class Puppet::Interface::Resource < Puppet::Interface
+class Puppet::Interface::Resource < Puppet::Interface::Indirector
end
diff --git a/lib/puppet/interface/resource_type.rb b/lib/puppet/interface/resource_type.rb
index 619a4914b..6892926f0 100644
--- a/lib/puppet/interface/resource_type.rb
+++ b/lib/puppet/interface/resource_type.rb
@@ -1,4 +1,4 @@
-require 'puppet/interface'
+require 'puppet/interface/indirector'
-class Puppet::Interface::Resource_type < Puppet::Interface
+class Puppet::Interface::Resource_type < Puppet::Interface::Indirector
end
diff --git a/lib/puppet/interface/status.rb b/lib/puppet/interface/status.rb
index cdb1623ac..86ccab6e1 100644
--- a/lib/puppet/interface/status.rb
+++ b/lib/puppet/interface/status.rb
@@ -1,4 +1,4 @@
-require 'puppet/interface'
+require 'puppet/interface/indirector'
-class Puppet::Interface::Status < Puppet::Interface
+class Puppet::Interface::Status < Puppet::Interface::Indirector
end