[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5
Luke Kanies
luke at puppetlabs.com
Tue May 10 08:05:07 UTC 2011
The following commit has been merged in the experimental branch:
commit a54ee1e292238145bb0def2af6cf9ac22f2acd68
Author: Dan Bode <bodepd at gmail.com>
Date: Sun Feb 13 02:55:42 2011 -0600
(#2) Should not assume interfaces have indirectors
The initial work assumed that all interfaces were just
skins on an indirected data type, but some interfaces will
be more abstract than that.
This commit removes that assumption by extracting all of
the indirector work into a new Indirector subclass of
Interface and then makes all of the new interfaces a subclass
of that rather than of Interface itself.
diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb
index 08a26db..999c38b 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 23e2b9c..85aa2f3 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 51e46c4..48ca2c2 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 30ba558..29dc73b 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 55a6939..144d5ef 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 e40bb56..42ba1fb 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 53c476d..98a8691 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 0000000..f0beb8a
--- /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 7521239..16b216b 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 38f92c6..17b661d 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 68e3069..5d9efa9 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 72f1285..fd6f45f 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 b9b007d..deed0a5 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 619a491..6892926 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 cdb1623..86ccab6 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
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list