From 9d30b2603365ee71c8b8cb23635079827189a9c2 Mon Sep 17 00:00:00 2001 From: Paul Lathrop Date: Tue, 25 Mar 2008 10:30:41 -0700 Subject: Fixes #1148 - replaces #!/usr/bin/ruby with #!/usr/bin/env ruby. --- lib/puppet/dsl.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/dsl.rb b/lib/puppet/dsl.rb index 966feaf9b..714b350f8 100644 --- a/lib/puppet/dsl.rb +++ b/lib/puppet/dsl.rb @@ -1,7 +1,7 @@ # Just quick mess-around to see what a DSL would look like. # # This is what the executable could look like: -##!/usr/bin/ruby +##!/usr/bin/env ruby # #require 'puppet' #require 'puppet/dsl' @@ -23,7 +23,7 @@ # And here's what an example config could look like: # -##!/usr/bin/ruby +##!/usr/bin/env ruby # # # require 'puppet' -- cgit From 4c63b69f4b634b1b30cfcd6bd5b770a5518b6814 Mon Sep 17 00:00:00 2001 From: Blake Barnett Date: Thu, 27 Mar 2008 20:36:04 -0700 Subject: Add a bunch of directives, allows a full parse of stanford's huge nagios config Also reformatted a bit --- lib/puppet/external/nagios/base.rb | 106 +++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 46 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/external/nagios/base.rb b/lib/puppet/external/nagios/base.rb index efc3982b4..25c689559 100755 --- a/lib/puppet/external/nagios/base.rb +++ b/lib/puppet/external/nagios/base.rb @@ -228,7 +228,9 @@ class Nagios::Base # This is probably a bad idea. def name=(value) - send(self.class.namevar.to_s + "=", value) + unless self.class.namevar.to_s == "name" + send(self.class.namevar.to_s + "=", value) + end end def namevar @@ -318,59 +320,64 @@ class Nagios::Base self.class.name end - # object types - newtype :command do - setparameters :command_name, :command_line - end + # object types + newtype :command do + setparameters :command_name, :command_line + end - newtype :contact do + newtype :contact do setparameters :contact_name, :alias, :host_notification_period, - :host_notification_commands, :service_notification_period, - :service_notification_commands, - :email, :pager, :service_notification_options, :host_notification_options + :host_notification_commands, :service_notification_period, + :service_notification_commands, :register, :email, :pager, + :service_notification_options, :host_notification_options setsuperior "person" - end + end - newtype :contactgroup do - setparameters :contactgroup_name, :alias, :members - end + newtype :contactgroup do + setparameters :contactgroup_name, :alias, :members + end - newtype :host do + newtype :host do setparameters :host_name, :notifications_enabled, :event_handler_enabled, - :flap_detection_enabled, :process_perf_data, :retain_status_information, - :retain_nonstatus_information, :register, :use, :alias, - :address, :check_command, :max_check_attempts, :notification_interval, - :notification_period, :notification_options, :checks_enabled, - :failure_prediction_enabled, :parents + :flap_detection_enabled, :process_perf_data, :retain_status_information, + :retain_nonstatus_information, :register, :use, :alias, + :address, :check_command, :max_check_attempts, :notification_interval, + :notification_period, :notification_options, :checks_enabled, + :failure_prediction_enabled, :parents, :contact_groups setsuperior "person" - map :address => "ipHostNumber" - end - - newtype :hostextinfo do - auxiliary = true + end + newtype :hostextinfo do + auxiliary = true setparameters :host_name, :notes_url, :icon_image, :icon_image_alt, :vrml_image, - "2d_coords".intern, "3d_coords".intern + "2d_coords".intern, "3d_coords".intern setnamevar :host_name - end + end - newtype :hostgroup do + newtype :hostgroup do setparameters :hostgroup_name, :alias, :contact_groups, :members - end + end + + newtype :hostescalation do + setparameters :name, :first_notification, :last_notification, + :notification_interval, :contact_groups, + :escalation_options, :register, :hostgroup_name + setnamevar :name + end - newtype :hostgroupescalation do - auxiliary = true + newtype :hostgroupescalation do + auxiliary = true setparameters :hostgroup_name, :first_notification, :last_notification, - :contact_groups, :notification_interval + :contact_groups, :notification_interval setnamevar :hostgroup_name - end + end - newtype :service do + newtype :service do attach :host => :host_name setparameters :name, :active_checks_enabled, :passive_checks_enabled, :parallelize_check, :obsess_over_service, :check_freshness, @@ -381,41 +388,48 @@ class Nagios::Base :normal_check_interval, :retry_check_interval, :contact_groups, :notification_interval, :notification_period, :notification_options, :service_description, :host_name, :freshness_threshold, - :check_command + :check_command, :hostgroup_name, :event_handler, :servicegroups, :host suppress :host_name setnamevar :service_description - end + end - newtype :servicedependency do + newtype :servicedependency do auxiliary = true setparameters :host_name, :service_description, :dependent_host_name, - :dependent_service_description, :execution_failure_criteria, - :notification_failure_criteria + :dependent_service_description, :execution_failure_criteria, + :notification_failure_criteria, :hostgroup_name, + :dependent_hostgroup_name setnamevar :host_name - end + end newtype :serviceescalation do setparameters :host_name, :service_description, :first_notification, - :last_notification, :contact_groups, :notification_interval + :last_notification, :contact_groups, :notification_interval, :hostgroup_name setnamevar :host_name end - newtype :serviceextinfo do + newtype :servicegroup do + setparameters :servicegroup_name, :alias + + setnamevar :servicegroup_name + end + + newtype :serviceextinfo do auxiliary = true setparameters :host_name, :service_description, :icon_image, :icon_image_alt setnamevar :host_name - end + end - newtype :timeperiod do - setparameters :timeperiod_name, :alias, :sunday, :monday, :tuesday, :wednesday, - :thursday, :friday, :saturday - end + newtype :timeperiod do + setparameters :timeperiod_name, :alias, :sunday, :monday, :tuesday, + :wednesday, :thursday, :friday, :saturday + end end # $Id$ -- cgit From 4f8df9803a9ad2f31d3e86418732a230b5cee3f3 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Mon, 31 Mar 2008 09:10:10 +1100 Subject: Added updated fix for #1020 --- lib/puppet/network/xmlrpc/client.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/network/xmlrpc/client.rb b/lib/puppet/network/xmlrpc/client.rb index f6a5e8db6..b55511871 100644 --- a/lib/puppet/network/xmlrpc/client.rb +++ b/lib/puppet/network/xmlrpc/client.rb @@ -48,7 +48,11 @@ module Puppet::Network Puppet.warning "Transient SSL write error; restarting connection and retrying" self.recycle_connection retry - end + elsif detail.message =~ /certificate verify failed/ || /hostname was not match/ || /hostname not match/ + Puppet.warning "Certificate verification failed; consider using the certname configuration option" + self.recycle_connection + retry + end raise XMLRPCClientError, "Certificates were not trusted: %s" % detail rescue ::XMLRPC::FaultException => detail -- cgit From eae5cee12df708de5cebfbed2fff42a1890070f5 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 31 Mar 2008 11:48:14 -0500 Subject: Fixing a duplicate word in the mount docs --- lib/puppet/type/mount.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/type/mount.rb b/lib/puppet/type/mount.rb index ca8e27e17..e18630cc8 100755 --- a/lib/puppet/type/mount.rb +++ b/lib/puppet/type/mount.rb @@ -95,7 +95,7 @@ module Puppet # Solaris specifies two devices, not just one. newproperty(:blockdevice) do - desc "The the device to fsck. This is property is only valid + desc "The device to fsck. This is property is only valid on Solaris, and in most cases will default to the correct value." -- cgit From 4a39d64180377d12d994110cd38b350282863892 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Tue, 1 Apr 2008 09:58:36 +1100 Subject: Revert "Added updated fix for #1020" This reverts commit 4f8df9803a9ad2f31d3e86418732a230b5cee3f3. --- lib/puppet/network/xmlrpc/client.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/network/xmlrpc/client.rb b/lib/puppet/network/xmlrpc/client.rb index b55511871..f6a5e8db6 100644 --- a/lib/puppet/network/xmlrpc/client.rb +++ b/lib/puppet/network/xmlrpc/client.rb @@ -48,11 +48,7 @@ module Puppet::Network Puppet.warning "Transient SSL write error; restarting connection and retrying" self.recycle_connection retry - elsif detail.message =~ /certificate verify failed/ || /hostname was not match/ || /hostname not match/ - Puppet.warning "Certificate verification failed; consider using the certname configuration option" - self.recycle_connection - retry - end + end raise XMLRPCClientError, "Certificates were not trusted: %s" % detail rescue ::XMLRPC::FaultException => detail -- cgit From e51d05c9aa86db2911a68622fcf983e543576f07 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Tue, 1 Apr 2008 10:34:29 +1100 Subject: Better fix for #1020 --- lib/puppet/network/xmlrpc/client.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/puppet') diff --git a/lib/puppet/network/xmlrpc/client.rb b/lib/puppet/network/xmlrpc/client.rb index f6a5e8db6..357a766a1 100644 --- a/lib/puppet/network/xmlrpc/client.rb +++ b/lib/puppet/network/xmlrpc/client.rb @@ -49,6 +49,11 @@ module Puppet::Network self.recycle_connection retry end + ["certificate verify failed", "hostname was not match", "hostname not match"].each do |str| + if detail.message.include?(str) + Puppet.warning "Certificate validation failed; considering using the certname configuration option" + end + end raise XMLRPCClientError, "Certificates were not trusted: %s" % detail rescue ::XMLRPC::FaultException => detail -- cgit From f927b97f9ba454dab23255a259642b6b5dc1aae9 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Tue, 1 Apr 2008 10:40:25 +1100 Subject: Updates to rrdgraph documentation --- lib/puppet/reports/rrdgraph.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/reports/rrdgraph.rb b/lib/puppet/reports/rrdgraph.rb index 2611f0369..03d8a5bdd 100644 --- a/lib/puppet/reports/rrdgraph.rb +++ b/lib/puppet/reports/rrdgraph.rb @@ -1,8 +1,10 @@ Puppet::Reports.register_report(:rrdgraph) do desc "Graph all available data about hosts using the RRD library. You must have the Ruby RRDtool library installed to use this report, which - you can get from `the RubyRRDTool RubyForge page`_. This package requires - the binary rrdtool2 package to be installed. + you can get from `the RubyRRDTool RubyForge page`_. This package may also + be available as ``ruby-rrd`` or ``rrdtool-ruby`` in your distribution's package + management system. The library and/or package will both require the binary + ``rrdtool`` package from your distribution to be installed. .. _the RubyRRDTool RubyForge page: http://rubyforge.org/projects/rubyrrdtool/ -- cgit From 6f32e95ce25fb6de40836cb7c7678f39c5e77879 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 31 Mar 2008 21:02:52 -0500 Subject: Adding the report reference back; I don't really know why I removed it, since the information in it isn't anywhere else. --- lib/puppet/reference/report.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lib/puppet/reference/report.rb (limited to 'lib/puppet') diff --git a/lib/puppet/reference/report.rb b/lib/puppet/reference/report.rb new file mode 100644 index 000000000..be8e64751 --- /dev/null +++ b/lib/puppet/reference/report.rb @@ -0,0 +1,23 @@ +require 'puppet/reports' + +report = Puppet::Util::Reference.newreference :report, :doc => "All available transaction reports" do + Puppet::Reports.reportdocs +end + +report.header = " +Puppet clients can report back to the server after each transaction. This +transaction report is sent as a YAML dump of the +``Puppet::Transaction::Report`` class and includes every log message that was +generated during the transaction along with as many metrics as Puppet knows how +to collect. See `ReportsAndReporting Reports and Reporting`:trac: +for more information on how to use reports. + +Currently, clients default to not sending in reports; you can enable reporting +by setting the ``report`` parameter to true. + +To use a report, set the ``reports`` parameter on the server; multiple +reports must be comma-separated. You can also specify ``none`` to disable +reports entirely. + +Puppet provides multiple report handlers that will process client reports: +" -- cgit From 2036d22cfa950ed84957427b98f69c1719b64dd7 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Thu, 3 Apr 2008 20:59:51 +1100 Subject: Fixes debian service enabled/disable issue as detailed in #1161. --- lib/puppet/provider/service/debian.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/provider/service/debian.rb b/lib/puppet/provider/service/debian.rb index f0f6fe1ef..da38c10a2 100755 --- a/lib/puppet/provider/service/debian.rb +++ b/lib/puppet/provider/service/debian.rb @@ -22,7 +22,7 @@ Puppet::Type.type(:service).provide :debian, :parent => :init do # If it's enabled, then it will print output showing removal of # links. - if output =~ /etc\/rc[\dS].d|not installed/ + if output =~ /etc\/rc[\dS].d\/S|not installed/ return :true else return :false -- cgit From e621985d24fbd417690f763276d7d895c0640042 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Fri, 4 Apr 2008 01:16:36 +1100 Subject: Changed some non-standard Ruby locations to env ruby shebangs --- lib/puppet/external/nagios.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/external/nagios.rb b/lib/puppet/external/nagios.rb index 78459fcb6..0dcae4c6d 100755 --- a/lib/puppet/external/nagios.rb +++ b/lib/puppet/external/nagios.rb @@ -1,4 +1,4 @@ -#!/usr/local/bin/ruby -w +#!/usr/bin/env ruby -w #-------------------- # A script to retrieve hosts from ldap and create an importable -- cgit From 6f1c46955a49647c14ede85304c25c7137dd9ab6 Mon Sep 17 00:00:00 2001 From: Andreas Rogge Date: Wed, 2 Apr 2008 19:55:25 +0200 Subject: Extend workaround from 56aad69f8cdf8b0b08fdb7985014986223fa4455 to not only fix UIDs but also GIDs Fixes #1169 Fixes #804 (workaround was probably incomplete, as required changes in lib/puppet/util/posix.rb were missing) Signed-off-by: Andreas Rogge --- lib/puppet/type/file/group.rb | 20 +++++++++++++------- lib/puppet/util/posix.rb | 4 ++-- 2 files changed, 15 insertions(+), 9 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/type/file/group.rb b/lib/puppet/type/file/group.rb index 5f7caf342..cc482ff31 100755 --- a/lib/puppet/type/file/group.rb +++ b/lib/puppet/type/file/group.rb @@ -11,12 +11,8 @@ module Puppet end def id2name(id) - if id > 70000 - return nil - end - if id.is_a?(Symbol) - return id.to_s - end + return id.to_s if id.is_a?(Symbol) + return nil if id > Puppet[:maximum_uid].to_i begin group = Etc.getgrgid(id) rescue ArgumentError @@ -73,7 +69,17 @@ module Puppet @method = :chown end - return stat.gid + currentvalue = stat.gid + + # On OS X, files that are owned by -2 get returned as really + # large GIDs instead of negative ones. This isn't a Ruby bug, + # it's an OS X bug, since it shows up in perl, too. + if currentvalue > Puppet[:maximum_uid].to_i + self.warning "Apparently using negative GID (%s) on a platform that does not consistently handle them" % currentvalue + currentvalue = :silly + end + + return currentvalue end # Determine if the group is valid, and if so, return the GID diff --git a/lib/puppet/util/posix.rb b/lib/puppet/util/posix.rb index c518a8797..cc0340ef7 100755 --- a/lib/puppet/util/posix.rb +++ b/lib/puppet/util/posix.rb @@ -13,7 +13,7 @@ module Puppet::Util::POSIX end prefix = "get" + space.to_s if id.is_a?(Integer) - if id > 1000000 + if id > Puppet[:maximum_uid].to_i Puppet.err "Tried to get %s field for silly id %s" % [field, id] return nil end @@ -40,7 +40,7 @@ module Puppet::Util::POSIX end if id.is_a?(Integer) integer = true - if id > 1000000 + if id > Puppet[:maximum_uid].to_i Puppet.err "Tried to get %s field for silly id %s" % [field, id] return nil end -- cgit From 80f8b80eacfa80bfd7b7d4f348838592161ed97a Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 8 Apr 2008 11:19:15 -0500 Subject: Adding validation to the user type to confirm that the group list does not contain any commas. This seems to be a common problem. --- lib/puppet/type/user.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/puppet') diff --git a/lib/puppet/type/user.rb b/lib/puppet/type/user.rb index 48e35f2c8..71507d172 100755 --- a/lib/puppet/type/user.rb +++ b/lib/puppet/type/user.rb @@ -220,6 +220,9 @@ module Puppet if value =~ /^\d+$/ raise ArgumentError, "Group names must be provided, not numbers" end + if value.include?(",") + raise ArgumentError, "Group names must be provided as an array, not a comma-separated list" + end end end -- cgit From bd858dff513c36f63bcadc13116558fc151c04be Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 8 Apr 2008 11:22:03 -0500 Subject: Changing the default environment to production. --- lib/puppet/defaults.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index 0f01c2ee2..eed1a00f3 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -128,7 +128,7 @@ module Puppet This is more useful as a server-side setting than client, but any environment chosen must be in this list. Values should be separated by a comma."], - :environment => {:default => "development", :desc => "The environment Puppet is running in. For clients + :environment => {:default => "production", :desc => "The environment Puppet is running in. For clients (e.g., ``puppetd``) this determines the environment itself, which is used to find modules and much more. For servers (i.e., ``puppetmasterd``) this provides the default environment for nodes -- cgit From 1458123550140c6e45982c139daeeca80d0afd22 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 7 Apr 2008 23:39:21 -0500 Subject: Adding an envelope module to handle indirected instance expiration. --- lib/puppet/indirector/envelope.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 lib/puppet/indirector/envelope.rb (limited to 'lib/puppet') diff --git a/lib/puppet/indirector/envelope.rb b/lib/puppet/indirector/envelope.rb new file mode 100644 index 000000000..ef7952ef6 --- /dev/null +++ b/lib/puppet/indirector/envelope.rb @@ -0,0 +1,13 @@ +require 'puppet/indirector' + +# Provide any attributes or functionality needed for indirected +# instances. +module Puppet::Indirector::Envelope + attr_accessor :expiration + + def expired? + return false unless expiration + return false if expiration >= Time.now + return true + end +end -- cgit From 8e1e06ff1c65bc5d8162fce41776e31b9f00d1bf Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 7 Apr 2008 23:39:51 -0500 Subject: Removing unused code from the file_serving/metadata class. --- lib/puppet/file_serving/metadata.rb | 9 --------- 1 file changed, 9 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/file_serving/metadata.rb b/lib/puppet/file_serving/metadata.rb index 56712122c..beecaef48 100644 --- a/lib/puppet/file_serving/metadata.rb +++ b/lib/puppet/file_serving/metadata.rb @@ -11,15 +11,6 @@ require 'puppet/file_serving/indirection_hooks' # A class that handles retrieving file metadata. class Puppet::FileServing::Metadata < Puppet::FileServing::FileBase - module MetadataHelper - include Puppet::FileServing::IndirectionHooks - - def post_find(instance) - end - - def post_search(key, options = {}) - end - end include Puppet::Util::Checksums -- cgit From c6729d134b6b0479e091928ee68abb9008d0f71d Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 7 Apr 2008 23:47:01 -0500 Subject: Reworking the caching layer to use TTLs instead of versions based on timestamps. This just modifies the indirection class itself, there is still some work to do to remove version code from other classes. --- lib/puppet/indirector/indirection.rb | 96 +++++++++++++++++++++++++++++------- 1 file changed, 77 insertions(+), 19 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index d47433c60..91cc42b17 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -1,4 +1,5 @@ require 'puppet/util/docs' +require 'puppet/indirector/envelope' # The class that connects functional classes with their different collection # back-ends. Each indirection has a set of associated terminus classes, @@ -28,8 +29,7 @@ class Puppet::Indirector::Indirection # Find an indirected model by name. This is provided so that Terminus classes # can specifically hook up with the indirections they are associated with. def self.model(name) - match = @@indirections.find { |i| i.name == name } - return nil unless match + return nil unless match = @@indirections.find { |i| i.name == name } match.model end @@ -65,6 +65,25 @@ class Puppet::Indirector::Indirection @@indirections.delete(self) if @@indirections.include?(self) end + # Set the time-to-live for instances created through this indirection. + def ttl=(value) + raise ArgumentError, "Indirection TTL must be an integer" unless value.is_a?(Fixnum) + @ttl = value + end + + # Default to the runinterval for the ttl. + def ttl + unless defined?(@ttl) + @ttl = Puppet[:runinterval].to_i + end + @ttl + end + + # Calculate the expiration date for a returned instance. + def expiration + Time.now + ttl + end + # Generate the full doc string. def doc text = "" @@ -106,6 +125,12 @@ class Puppet::Indirector::Indirection end end + # Set the options that can be passed on to the terminus instances. + attr_reader :option_struct + def options=(options) + @option_struct = Struct.new(*options) + end + # Return the singleton terminus for this indirection. def terminus(terminus_name = nil) # Get the name of the terminus. @@ -161,29 +186,41 @@ class Puppet::Indirector::Indirection check_authorization(:find, terminus_name, ([key] + args)) # See if our instance is in the cache and up to date. - if cache? and cache.has_most_recent?(key, terminus(terminus_name).version(key)) - Puppet.debug "Using cached %s %s" % [self.name, key] - return cache.find(key, *args) + if cache? and cached = cache.find(key, *args) + if cached.expired? + Puppet.info "Cached %s %s expired at %s; not using" % [self.name, key, cached.expiration] + else + Puppet.debug "Using cached %s %s" % [self.name, key] + return cached + end end # Otherwise, return the result from the terminus, caching if appropriate. if result = terminus(terminus_name).find(key, *args) - result.version ||= Time.now.utc + # Include the envelope module, so we can set the expiration. + result.extend(Puppet::Indirector::Envelope) + result.expiration ||= self.expiration if cache? Puppet.info "Caching %s %s" % [self.name, key] cache.save(result, *args) end - terminus(terminus_name).post_find(result) if terminus(terminus_name).respond_to?(:post_find) - return result end + + return nil end - def destroy(*args) - check_authorization(:destroy, terminus_class, args) + def destroy(key, *args) + check_authorization(:destroy, terminus_class, ([key] + args)) + + terminus.destroy(key, *args) + + if cache? and cached = cache.find(key, *args) + cache.destroy(key, *args) + end - terminus.destroy(*args) + nil end def search(*args) @@ -191,21 +228,22 @@ class Puppet::Indirector::Indirection result = terminus.search(*args) - terminus().post_search(result) if terminus().respond_to?(:post_search) - result end # these become instance methods def save(instance, *args) - check_authorization(:save, terminus_class, ([instance] + args)) + if respond_to?(:select_terminus) + terminus_name = select_terminus(instance.name, *args) + else + terminus_name = terminus_class + end - instance.version ||= Time.now.utc - dest = cache? ? cache : terminus - return if dest.has_most_recent?(instance.name, instance.version) - Puppet.info "Caching %s %s" % [self.name, instance.name] if cache? + check_authorization(:save, terminus_name, ([instance] + args)) + + # If caching is enabled, save our document there, do cache.save(instance, *args) if cache? - terminus.save(instance, *args) + terminus(terminus_class).save(instance, *args) end def version(*args) @@ -226,6 +264,20 @@ class Puppet::Indirector::Indirection end end + # Handle a given indirected call. + def prepare_call(method, arguments) + raise ArgumentError, "Options must be a hash" unless arguments.is_a?(Hash) + + # Set any terminus options. + options = option_struct ? set_options(option_struct, arguments) : nil + + tclass = choose_terminus(options) + + check_authorization(method, tclass, options) + + return terminus(tclass), options + end + # Create a new terminus instance. def make_terminus(terminus_class) # Load our terminus class. @@ -234,4 +286,10 @@ class Puppet::Indirector::Indirection end return klass.new end + + # Create a struct instance with all of the appropriate options set + # from the provided hash. + def set_options(struct, arguments) + struct.new(struct.members.inject([]) { |array, param| arguments[param.to_sym]; array } ) + end end -- cgit From 941177a4902f4bfe7b8b3f528ce6648752f5409c Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 7 Apr 2008 23:54:58 -0500 Subject: Changing how destroy works, just a bit -- it now accepts the name of the instance to be destroyed, rather than the instance itself. --- lib/puppet/indirector/file.rb | 13 ++++++++----- lib/puppet/indirector/indirection.rb | 2 ++ lib/puppet/indirector/memory.rb | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/indirector/file.rb b/lib/puppet/indirector/file.rb index c2d36c46b..8c984154b 100644 --- a/lib/puppet/indirector/file.rb +++ b/lib/puppet/indirector/file.rb @@ -2,21 +2,23 @@ require 'puppet/indirector/terminus' # An empty terminus type, meant to just return empty objects. class Puppet::Indirector::File < Puppet::Indirector::Terminus - def destroy(file) + # Remove files on disk. + def destroy(name) if respond_to?(:path) - path = path(file.name) + path = path(name) else - path = file.path + path = name end - raise Puppet::Error.new("File %s does not exist; cannot destroy" % [file]) unless File.exist?(path) + raise Puppet::Error.new("File %s does not exist; cannot destroy" % [name]) unless File.exist?(path) begin File.unlink(path) rescue => detail - raise Puppet::Error, "Could not remove %s: %s" % [file, detail] + raise Puppet::Error, "Could not remove %s: %s" % [name, detail] end end + # Return a model instance for a given file on disk. def find(name) if respond_to?(:path) path = path(name) @@ -35,6 +37,7 @@ class Puppet::Indirector::File < Puppet::Indirector::Terminus return model.new(content) end + # Save a new file to disk. def save(file) if respond_to?(:path) path = path(file.name) diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index 91cc42b17..6f1497319 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -211,6 +211,7 @@ class Puppet::Indirector::Indirection return nil end + # Remove something via the terminus. def destroy(key, *args) check_authorization(:destroy, terminus_class, ([key] + args)) @@ -223,6 +224,7 @@ class Puppet::Indirector::Indirection nil end + # Search for more than one instance. Should always return an array. def search(*args) check_authorization(:search, terminus_class, args) diff --git a/lib/puppet/indirector/memory.rb b/lib/puppet/indirector/memory.rb index 5bfcec95d..b97e6ffb6 100644 --- a/lib/puppet/indirector/memory.rb +++ b/lib/puppet/indirector/memory.rb @@ -6,9 +6,9 @@ class Puppet::Indirector::Memory < Puppet::Indirector::Terminus @instances = {} end - def destroy(instance) - raise ArgumentError.new("Could not find %s to destroy" % instance) unless @instances.include?(instance.name) - @instances.delete(instance.name) + def destroy(name) + raise ArgumentError.new("Could not find %s to destroy" % name) unless @instances.include?(name) + @instances.delete(name) end def find(name) -- cgit From f9881edd5d4b9f86c1da1c66fb12324d0f9c3c41 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 8 Apr 2008 02:17:31 -0500 Subject: Adding a Request class to the Indirection layer. This class is currently only used internally by the Indirection instances, but I expect that I will soon be pushing it to all of the terminus types. I still need to fix a couple of tests that will get broken by this commit. --- lib/puppet/indirector/indirection.rb | 89 ++++++++++++++---------------------- lib/puppet/indirector/request.rb | 18 ++++++++ 2 files changed, 52 insertions(+), 55 deletions(-) create mode 100644 lib/puppet/indirector/request.rb (limited to 'lib/puppet') diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index 6f1497319..735fc54da 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -1,5 +1,6 @@ require 'puppet/util/docs' require 'puppet/indirector/envelope' +require 'puppet/indirector/request' # The class that connects functional classes with their different collection # back-ends. Each indirection has a set of associated terminus classes, @@ -125,12 +126,6 @@ class Puppet::Indirector::Indirection end end - # Set the options that can be passed on to the terminus instances. - attr_reader :option_struct - def options=(options) - @option_struct = Struct.new(*options) - end - # Return the singleton terminus for this indirection. def terminus(terminus_name = nil) # Get the name of the terminus. @@ -173,17 +168,8 @@ class Puppet::Indirector::Indirection end def find(key, *args) - # Select the appropriate terminus if there's a hook - # for doing so. This allows the caller to pass in some kind - # of URI that the indirection can use for routing to the appropriate - # terminus. - if respond_to?(:select_terminus) - terminus_name = select_terminus(key, *args) - else - terminus_name = terminus_class - end - - check_authorization(:find, terminus_name, ([key] + args)) + request = request(key, :find, *args) + terminus = prepare(request) # See if our instance is in the cache and up to date. if cache? and cached = cache.find(key, *args) @@ -196,7 +182,7 @@ class Puppet::Indirector::Indirection end # Otherwise, return the result from the terminus, caching if appropriate. - if result = terminus(terminus_name).find(key, *args) + if result = terminus.find(key, *args) # Include the envelope module, so we can set the expiration. result.extend(Puppet::Indirector::Envelope) result.expiration ||= self.expiration @@ -213,7 +199,8 @@ class Puppet::Indirector::Indirection # Remove something via the terminus. def destroy(key, *args) - check_authorization(:destroy, terminus_class, ([key] + args)) + request = request(key, :destroy, *args) + terminus = prepare(request) terminus.destroy(key, *args) @@ -225,59 +212,52 @@ class Puppet::Indirector::Indirection end # Search for more than one instance. Should always return an array. - def search(*args) - check_authorization(:search, terminus_class, args) + def search(key, *args) + request = request(key, :search, *args) + terminus = prepare(request) - result = terminus.search(*args) + result = terminus.search(key, *args) result end - # these become instance methods + # Save the instance in the appropriate terminus. This method is + # normally an instance method on the indirected class. def save(instance, *args) - if respond_to?(:select_terminus) - terminus_name = select_terminus(instance.name, *args) - else - terminus_name = terminus_class - end - - check_authorization(:save, terminus_name, ([instance] + args)) + request = request(instance.name, :save, *args) + terminus = prepare(request) # If caching is enabled, save our document there, do cache.save(instance, *args) if cache? - terminus(terminus_class).save(instance, *args) - end - - def version(*args) - terminus.version(*args) + terminus.save(instance, *args) end private # Check authorization if there's a hook available; fail if there is one # and it returns false. - def check_authorization(method, terminus_name, arguments) - # Don't check authorization if there's no node. - # LAK:FIXME This is a hack and is quite possibly not the design we want. - return unless arguments[-1].is_a?(Hash) and arguments[-1][:node] + def check_authorization(request, terminus) + return unless request.options[:node] - if terminus(terminus_name).respond_to?(:authorized?) and ! terminus(terminus_name).authorized?(method, *arguments) - raise ArgumentError, "Not authorized to call %s with %s" % [method, arguments[0]] + return unless terminus.respond_to?(:authorized?) + + unless terminus.authorized?(request) + raise ArgumentError, "Not authorized to call %s with %s" % [request.method, request.options.inspect] end end - # Handle a given indirected call. - def prepare_call(method, arguments) - raise ArgumentError, "Options must be a hash" unless arguments.is_a?(Hash) - - # Set any terminus options. - options = option_struct ? set_options(option_struct, arguments) : nil - - tclass = choose_terminus(options) + # Setup a request, pick the appropriate terminus, check the request's authorization, and return it. + def prepare(request) + # Pick our terminus. + if respond_to?(:select_terminus) + terminus_name = select_terminus(request) + else + terminus_name = terminus_class + end - check_authorization(method, tclass, options) + check_authorization(request, terminus(terminus_name)) - return terminus(tclass), options + return terminus(terminus_name) end # Create a new terminus instance. @@ -289,9 +269,8 @@ class Puppet::Indirector::Indirection return klass.new end - # Create a struct instance with all of the appropriate options set - # from the provided hash. - def set_options(struct, arguments) - struct.new(struct.members.inject([]) { |array, param| arguments[param.to_sym]; array } ) + # Set up our request object. + def request(key, method, arguments = nil) + Puppet::Indirector::Request.new(self.name, key, method, arguments) end end diff --git a/lib/puppet/indirector/request.rb b/lib/puppet/indirector/request.rb new file mode 100644 index 000000000..a5495641d --- /dev/null +++ b/lib/puppet/indirector/request.rb @@ -0,0 +1,18 @@ +require 'puppet/indirector' + +# Provide any attributes or functionality needed for indirected +# instances. +class Puppet::Indirector::Request + attr_accessor :indirection_name, :key, :method, :options + + def initialize(indirection_name, key, method, options = {}) + @indirection_name, @key, @method, @options = indirection_name, key, method, (options || {}) + + raise ArgumentError, "Request options must be a hash, not %s" % @options.class unless @options.is_a?(Hash) + end + + # Look up the indirection based on the name provided. + def indirection + Puppet::Indirector::Indirection.instance(@indirection_name) + end +end -- cgit From 69a321f07dc0cbec7a0471a3378e9330d12c47b7 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 8 Apr 2008 02:38:20 -0500 Subject: Fixing the tests that were failing because of the use of the indirection request object. --- lib/puppet/file_serving/indirection_hooks.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/file_serving/indirection_hooks.rb b/lib/puppet/file_serving/indirection_hooks.rb index 141642efe..66ed169dc 100644 --- a/lib/puppet/file_serving/indirection_hooks.rb +++ b/lib/puppet/file_serving/indirection_hooks.rb @@ -12,7 +12,8 @@ module Puppet::FileServing::IndirectionHooks PROTOCOL_MAP = {"puppet" => :rest, "file" => :file, "puppetmounts" => :file_server} # Pick an appropriate terminus based on the protocol. - def select_terminus(full_uri, options = {}) + def select_terminus(request) + full_uri = request.key # Short-circuit to :file if it's a fully-qualified path. return PROTOCOL_MAP["file"] if full_uri =~ /^#{::File::SEPARATOR}/ begin @@ -29,11 +30,12 @@ module Puppet::FileServing::IndirectionHooks terminus = :file_server end + # This is the backward-compatible module terminus. if terminus == :file_server and uri.path =~ %r{^/([^/]+)\b} modname = $1 if modname == "modules" terminus = :modules - elsif terminus(:modules).find_module(modname, options[:node]) + elsif terminus(:modules).find_module(modname, request.options[:node]) Puppet.warning "DEPRECATION NOTICE: Found file '%s' in module without using the 'modules' mount; please prefix path with '/modules'" % uri.path terminus = :modules end -- cgit From 38f0f483faeba28d12a5f4e1d52e8d10ab96e68b Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 8 Apr 2008 10:18:42 -0500 Subject: Fixing an errant comment --- lib/puppet/indirector/indirection.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index 735fc54da..1b6613035 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -227,7 +227,7 @@ class Puppet::Indirector::Indirection request = request(instance.name, :save, *args) terminus = prepare(request) - # If caching is enabled, save our document there, do + # If caching is enabled, save our document there cache.save(instance, *args) if cache? terminus.save(instance, *args) end -- cgit From 768315bd6e8ecd064ab473187c10b4633f09523c Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 8 Apr 2008 11:39:29 -0500 Subject: Adding the ability for indirection requests to be created with instances instead of just keys. --- lib/puppet/indirector/request.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/indirector/request.rb b/lib/puppet/indirector/request.rb index a5495641d..708862b28 100644 --- a/lib/puppet/indirector/request.rb +++ b/lib/puppet/indirector/request.rb @@ -3,10 +3,17 @@ require 'puppet/indirector' # Provide any attributes or functionality needed for indirected # instances. class Puppet::Indirector::Request - attr_accessor :indirection_name, :key, :method, :options + attr_accessor :indirection_name, :key, :method, :options, :instance def initialize(indirection_name, key, method, options = {}) - @indirection_name, @key, @method, @options = indirection_name, key, method, (options || {}) + @indirection_name, @method, @options = indirection_name, method, (options || {}) + + if key.is_a?(String) or key.is_a?(Symbol) + @key = key + else + @instance = key + @key = @instance.name + end raise ArgumentError, "Request options must be a hash, not %s" % @options.class unless @options.is_a?(Hash) end -- cgit From 644d6baae132a097170631f90521e878e31a5a0a Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 8 Apr 2008 14:09:29 -0500 Subject: Fixing some tests that were failing because new base types were added to Naginator, but no new related resource types were added. --- lib/puppet/type/nagios_hostescalation.rb | 3 +++ lib/puppet/type/nagios_servicegroup.rb | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 lib/puppet/type/nagios_hostescalation.rb create mode 100644 lib/puppet/type/nagios_servicegroup.rb (limited to 'lib/puppet') diff --git a/lib/puppet/type/nagios_hostescalation.rb b/lib/puppet/type/nagios_hostescalation.rb new file mode 100644 index 000000000..5d18af2a6 --- /dev/null +++ b/lib/puppet/type/nagios_hostescalation.rb @@ -0,0 +1,3 @@ +require 'puppet/util/nagios_maker' + +Puppet::Util::NagiosMaker.create_nagios_type :hostescalation diff --git a/lib/puppet/type/nagios_servicegroup.rb b/lib/puppet/type/nagios_servicegroup.rb new file mode 100644 index 000000000..fef669639 --- /dev/null +++ b/lib/puppet/type/nagios_servicegroup.rb @@ -0,0 +1,3 @@ +require 'puppet/util/nagios_maker' + +Puppet::Util::NagiosMaker.create_nagios_type :servicegroup -- cgit From bf728d23caca4f58ae4ede1a2d477c9fc15e0bdc Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 8 Apr 2008 18:21:18 -0500 Subject: Intermediate commit. This commit adds a Request instance into the indirection, pushing it all the way to the terminus instances. It's a big commit because it requires modifying every terminus class. There are still some thorny design issues. In particular, who should be responsible for making the request object? I've tried having both the indirection class and the Indirector module creating it, and both have their issues. Also, the Catalog class previously allowed passing Node instances directly to the find method, which is now no longer possible because the Request class would treat the node as the instance being found. We need the request class to have two modes, one when it's passed an instance and one when it's passed a key. --- lib/puppet/indirector.rb | 49 ++++++++++++---------------- lib/puppet/indirector/checksum/file.rb | 4 +-- lib/puppet/indirector/direct_file_server.rb | 14 ++++---- lib/puppet/indirector/file.rb | 28 ++++++++-------- lib/puppet/indirector/file_metadata/file.rb | 4 +-- lib/puppet/indirector/indirection.rb | 50 +++++++++++++---------------- lib/puppet/indirector/memory.rb | 14 ++++---- lib/puppet/indirector/plain.rb | 4 +-- lib/puppet/indirector/request.rb | 2 +- lib/puppet/indirector/yaml.rb | 28 +++++++--------- lib/puppet/transaction/report.rb | 4 +++ 11 files changed, 94 insertions(+), 107 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/indirector.rb b/lib/puppet/indirector.rb index c30c097b2..a8a7a84d1 100644 --- a/lib/puppet/indirector.rb +++ b/lib/puppet/indirector.rb @@ -9,6 +9,7 @@ module Puppet::Indirector require 'puppet/indirector/indirection' require 'puppet/indirector/terminus' + require 'puppet/indirector/envelope' # Declare that the including class indirects its methods to # this terminus. The terminus name must be the name of a Puppet @@ -20,6 +21,7 @@ module Puppet::Indirector # populate this class with the various new methods extend ClassMethods include InstanceMethods + include Puppet::Indirector::Envelope # instantiate the actual Terminus for that type and this name (:ldap, w/ args :node) # & hook the instantiated Terminus into this class (Node: @indirection = terminus) @@ -28,41 +30,32 @@ module Puppet::Indirector end module ClassMethods - attr_reader :indirection + attr_reader :indirection - def cache_class=(klass) - indirection.cache_class = klass - end + def cache_class=(klass) + indirection.cache_class = klass + end - def terminus_class=(klass) - indirection.terminus_class = klass - end + def terminus_class=(klass) + indirection.terminus_class = klass + end - def find(*args) - indirection.find(*args) - end + def find(*args) + indirection.find Puppet::Indirector::Request.new(indirection.name, :find, *args) + end - def destroy(*args) - indirection.destroy(*args) - end + def destroy(*args) + indirection.destroy Puppet::Indirector::Request.new(indirection.name, :destroy, *args) + end - def search(*args) - indirection.search(*args) - end - - def version(*args) - indirection.version(*args) - end + def search(*args) + indirection.search Puppet::Indirector::Request.new(indirection.name, :search, *args) + end end module InstanceMethods - # Make it easy for the model to set versions, - # which are used for caching and such. - attr_accessor :version - - # these become instance methods - def save(*args) - self.class.indirection.save(self, *args) - end + def save(*args) + self.class.indirection.save Puppet::Indirector::Request.new(self.class.indirection.name, :save, self, *args) + end end end diff --git a/lib/puppet/indirector/checksum/file.rb b/lib/puppet/indirector/checksum/file.rb index 3b196a1f8..5489b40e8 100644 --- a/lib/puppet/indirector/checksum/file.rb +++ b/lib/puppet/indirector/checksum/file.rb @@ -18,8 +18,8 @@ class Puppet::Checksum::File < Puppet::Indirector::File path.join(File::SEPARATOR) end - def save(file) - path = File.dirname(path(file.name)) + def save(request) + path = File.dirname(path(request.key)) # Make the directories if necessary. unless FileTest.directory?(path) diff --git a/lib/puppet/indirector/direct_file_server.rb b/lib/puppet/indirector/direct_file_server.rb index 31cc9aa16..1711356f9 100644 --- a/lib/puppet/indirector/direct_file_server.rb +++ b/lib/puppet/indirector/direct_file_server.rb @@ -11,17 +11,17 @@ class Puppet::Indirector::DirectFileServer < Puppet::Indirector::Terminus include Puppet::Util::URIHelper include Puppet::FileServing::TerminusHelper - def find(key, options = {}) - uri = key2uri(key) + def find(request) + uri = key2uri(request.key) return nil unless FileTest.exists?(uri.path) - instance = model.new(key, :path => uri.path) - instance.links = options[:links] if options[:links] + instance = model.new(request.key, :path => uri.path) + instance.links = request.options[:links] if request.options[:links] return instance end - def search(key, options = {}) - uri = key2uri(key) + def search(request) + uri = key2uri(request.key) return nil unless FileTest.exists?(uri.path) - path2instances(key, uri.path, options) + path2instances(request.key, uri.path, request.options) end end diff --git a/lib/puppet/indirector/file.rb b/lib/puppet/indirector/file.rb index 8c984154b..e5382155f 100644 --- a/lib/puppet/indirector/file.rb +++ b/lib/puppet/indirector/file.rb @@ -3,27 +3,27 @@ require 'puppet/indirector/terminus' # An empty terminus type, meant to just return empty objects. class Puppet::Indirector::File < Puppet::Indirector::Terminus # Remove files on disk. - def destroy(name) + def destroy(request) if respond_to?(:path) - path = path(name) + path = path(request.key) else - path = name + path = request.key end - raise Puppet::Error.new("File %s does not exist; cannot destroy" % [name]) unless File.exist?(path) + raise Puppet::Error.new("File %s does not exist; cannot destroy" % [request.key]) unless File.exist?(path) begin File.unlink(path) rescue => detail - raise Puppet::Error, "Could not remove %s: %s" % [name, detail] + raise Puppet::Error, "Could not remove %s: %s" % [request.key, detail] end end # Return a model instance for a given file on disk. - def find(name) + def find(request) if respond_to?(:path) - path = path(name) + path = path(request.key) else - path = name + path = request.key end return nil unless File.exist?(path) @@ -38,20 +38,20 @@ class Puppet::Indirector::File < Puppet::Indirector::Terminus end # Save a new file to disk. - def save(file) + def save(request) if respond_to?(:path) - path = path(file.name) + path = path(request.key) else - path = file.path + path = request.key end dir = File.dirname(path) - raise Puppet::Error.new("Cannot save %s; parent directory %s does not exist" % [file, dir]) unless File.directory?(dir) + raise Puppet::Error.new("Cannot save %s; parent directory %s does not exist" % [request.key, dir]) unless File.directory?(dir) begin - File.open(path, "w") { |f| f.print file.content } + File.open(path, "w") { |f| f.print request.instance.content } rescue => detail - raise Puppet::Error, "Could not write %s: %s" % [file, detail] + raise Puppet::Error, "Could not write %s: %s" % [request.key, detail] end end end diff --git a/lib/puppet/indirector/file_metadata/file.rb b/lib/puppet/indirector/file_metadata/file.rb index b36846bbe..c46015c38 100644 --- a/lib/puppet/indirector/file_metadata/file.rb +++ b/lib/puppet/indirector/file_metadata/file.rb @@ -9,14 +9,14 @@ require 'puppet/indirector/direct_file_server' class Puppet::Indirector::FileMetadata::File < Puppet::Indirector::DirectFileServer desc "Retrieve file metadata directly from the local filesystem." - def find(key, options = {}) + def find(request) return unless data = super data.collect_attributes return data end - def search(key, options = {}) + def search(request) return unless result = super result.each { |instance| instance.collect_attributes } diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index 1b6613035..56cd687af 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -126,6 +126,11 @@ class Puppet::Indirector::Indirection end end + # Set up our request object. + def request(key, method, arguments = nil) + Puppet::Indirector::Request.new(self.name, key, method, arguments) + end + # Return the singleton terminus for this indirection. def terminus(terminus_name = nil) # Get the name of the terminus. @@ -167,28 +172,27 @@ class Puppet::Indirector::Indirection end end - def find(key, *args) - request = request(key, :find, *args) + def find(request) terminus = prepare(request) # See if our instance is in the cache and up to date. - if cache? and cached = cache.find(key, *args) + if cache? and cached = cache.find(request) if cached.expired? - Puppet.info "Cached %s %s expired at %s; not using" % [self.name, key, cached.expiration] + Puppet.info "Cached %s %s expired at %s; not using" % [self.name, request.key, cached.expiration] else - Puppet.debug "Using cached %s %s" % [self.name, key] + Puppet.debug "Using cached %s %s" % [self.name, request.key] return cached end end # Otherwise, return the result from the terminus, caching if appropriate. - if result = terminus.find(key, *args) - # Include the envelope module, so we can set the expiration. - result.extend(Puppet::Indirector::Envelope) + if result = terminus.find(request) result.expiration ||= self.expiration if cache? - Puppet.info "Caching %s %s" % [self.name, key] - cache.save(result, *args) + Puppet.info "Caching %s %s" % [self.name, request.key] + cached_request = request.clone + cached_request.instance = result + cache.save(cached_request) end return result @@ -198,38 +202,35 @@ class Puppet::Indirector::Indirection end # Remove something via the terminus. - def destroy(key, *args) - request = request(key, :destroy, *args) + def destroy(request) terminus = prepare(request) - terminus.destroy(key, *args) + terminus.destroy(request) - if cache? and cached = cache.find(key, *args) - cache.destroy(key, *args) + if cache? and cached = cache.find(request) + cache.destroy(request) end nil end # Search for more than one instance. Should always return an array. - def search(key, *args) - request = request(key, :search, *args) + def search(request) terminus = prepare(request) - result = terminus.search(key, *args) + result = terminus.search(request) result end # Save the instance in the appropriate terminus. This method is # normally an instance method on the indirected class. - def save(instance, *args) - request = request(instance.name, :save, *args) + def save(request) terminus = prepare(request) # If caching is enabled, save our document there - cache.save(instance, *args) if cache? - terminus.save(instance, *args) + cache.save(request) if cache? + terminus.save(request) end private @@ -268,9 +269,4 @@ class Puppet::Indirector::Indirection end return klass.new end - - # Set up our request object. - def request(key, method, arguments = nil) - Puppet::Indirector::Request.new(self.name, key, method, arguments) - end end diff --git a/lib/puppet/indirector/memory.rb b/lib/puppet/indirector/memory.rb index b97e6ffb6..19acc14e2 100644 --- a/lib/puppet/indirector/memory.rb +++ b/lib/puppet/indirector/memory.rb @@ -6,16 +6,16 @@ class Puppet::Indirector::Memory < Puppet::Indirector::Terminus @instances = {} end - def destroy(name) - raise ArgumentError.new("Could not find %s to destroy" % name) unless @instances.include?(name) - @instances.delete(name) + def destroy(request) + raise ArgumentError.new("Could not find %s to destroy" % request.key) unless @instances.include?(request.key) + @instances.delete(request.key) end - def find(name) - @instances[name] + def find(request) + @instances[request.key] end - def save(instance) - @instances[instance.name] = instance + def save(request) + @instances[request.key] = request.instance end end diff --git a/lib/puppet/indirector/plain.rb b/lib/puppet/indirector/plain.rb index 8bdf8469c..2caa0946d 100644 --- a/lib/puppet/indirector/plain.rb +++ b/lib/puppet/indirector/plain.rb @@ -3,7 +3,7 @@ require 'puppet/indirector/terminus' # An empty terminus type, meant to just return empty objects. class Puppet::Indirector::Plain < Puppet::Indirector::Terminus # Just return nothing. - def find(name) - indirection.model.new(name) + def find(request) + indirection.model.new(request.key) end end diff --git a/lib/puppet/indirector/request.rb b/lib/puppet/indirector/request.rb index 708862b28..68b7ee160 100644 --- a/lib/puppet/indirector/request.rb +++ b/lib/puppet/indirector/request.rb @@ -5,7 +5,7 @@ require 'puppet/indirector' class Puppet::Indirector::Request attr_accessor :indirection_name, :key, :method, :options, :instance - def initialize(indirection_name, key, method, options = {}) + def initialize(indirection_name, method, key, options = {}) @indirection_name, @method, @options = indirection_name, method, (options || {}) if key.is_a?(String) or key.is_a?(Symbol) diff --git a/lib/puppet/indirector/yaml.rb b/lib/puppet/indirector/yaml.rb index 4dd29159e..23bca02b8 100644 --- a/lib/puppet/indirector/yaml.rb +++ b/lib/puppet/indirector/yaml.rb @@ -3,23 +3,22 @@ require 'puppet/indirector/terminus' # The base class for YAML indirection termini. class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus # Read a given name's file in and convert it from YAML. - def find(name) - raise ArgumentError.new("You must specify the name of the object to retrieve") unless name - file = path(name) + def find(request) + file = path(request.key) return nil unless FileTest.exist?(file) begin return from_yaml(File.read(file)) rescue => detail - raise Puppet::Error, "Could not read YAML data for %s %s: %s" % [indirection.name, name, detail] + raise Puppet::Error, "Could not read YAML data for %s %s: %s" % [indirection.name, request.key, detail] end end # Convert our object to YAML and store it to the disk. - def save(object) - raise ArgumentError.new("You can only save objects that respond to :name") unless object.respond_to?(:name) + def save(request) + raise ArgumentError.new("You can only save objects that respond to :name") unless request.instance.respond_to?(:name) - file = path(object.name) + file = path(request.key) basedir = File.dirname(file) @@ -29,15 +28,15 @@ class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus end begin - File.open(file, "w", 0660) { |f| f.print to_yaml(object) } + File.open(file, "w", 0660) { |f| f.print to_yaml(request.instance) } rescue TypeError => detail - Puppet.err "Could not save %s %s: %s" % [self.name, object.name, detail] + Puppet.err "Could not save %s %s: %s" % [self.name, request.key, detail] end end - def version(name) - return nil unless FileTest.exist?(path(name)) - return File.stat(path(name)).mtime + # Return the path to a given node's file. + def path(name) + File.join(Puppet[:yamldir], self.class.indirection_name.to_s, name.to_s + ".yaml") end private @@ -49,9 +48,4 @@ class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus def to_yaml(object) YAML.dump(object) end - - # Return the path to a given node's file. - def path(name) - File.join(Puppet[:yamldir], self.class.indirection_name.to_s, name.to_s + ".yaml") - end end diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb index 56f8a602a..bd62ebbe6 100644 --- a/lib/puppet/transaction/report.rb +++ b/lib/puppet/transaction/report.rb @@ -34,6 +34,10 @@ class Puppet::Transaction::Report end end + def name + host + end + # Create a new metric. def newmetric(name, hash) metric = Puppet::Util::Metric.new(name) -- cgit From 7774d9c443f19d44a1e2dab459fc4bfb94e75244 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 8 Apr 2008 21:21:59 -0500 Subject: Ported the rest of the indirection terminuses over to expecting requests instead of having a random interface. --- lib/puppet/indirector/catalog/compiler.rb | 16 +++++----------- lib/puppet/indirector/exec.rb | 4 ++-- lib/puppet/indirector/facts/facter.rb | 4 ++-- lib/puppet/indirector/ldap.rb | 4 ++-- lib/puppet/indirector/node/exec.rb | 13 +++---------- lib/puppet/indirector/node/ldap.rb | 9 ++++----- lib/puppet/indirector/node/plain.rb | 9 +-------- lib/puppet/indirector/report/processor.rb | 4 ++-- lib/puppet/indirector/terminus.rb | 27 --------------------------- 9 files changed, 21 insertions(+), 69 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/indirector/catalog/compiler.rb b/lib/puppet/indirector/catalog/compiler.rb index 6d769b97d..ecc340f75 100644 --- a/lib/puppet/indirector/catalog/compiler.rb +++ b/lib/puppet/indirector/catalog/compiler.rb @@ -13,11 +13,9 @@ class Puppet::Node::Catalog::Compiler < Puppet::Indirector::Code attr_accessor :code # Compile a node's catalog. - def find(key, client = nil, clientip = nil) - if key.is_a?(Puppet::Node) - node = key - else - node = find_node(key) + def find(request) + unless node = request.options[:node] || find_node(request.key) + raise ArgumentError, "Could not find node '%s'; cannot compile" % request.key end if catalog = compile(node) @@ -102,16 +100,12 @@ class Puppet::Node::Catalog::Compiler < Puppet::Indirector::Code def find_node(key) # If we want to use the cert name as our key # LAK:FIXME This needs to be figured out somehow, but it requires the routing. + # This should be able to use the request, yay. #if Puppet[:node_name] == 'cert' and client # key = client #end - # Note that this is reasonable, because either their node source should actually - # know about the node, or they should be using the ``null`` node source, which - # will always return data. - unless node = Puppet::Node.find_by_any_name(key) - raise Puppet::Error, "Could not find node '%s'" % key - end + return nil unless node = Puppet::Node.find_by_any_name(key) # Add any external data to the node. add_node_data(node) diff --git a/lib/puppet/indirector/exec.rb b/lib/puppet/indirector/exec.rb index 7e4ac8d18..2462e31da 100644 --- a/lib/puppet/indirector/exec.rb +++ b/lib/puppet/indirector/exec.rb @@ -3,9 +3,9 @@ require 'puppet/util' class Puppet::Indirector::Exec < Puppet::Indirector::Terminus # Look for external node definitions. - def find(name) + def find(request) # Run the command. - unless output = query(name) + unless output = query(request.key) return nil end diff --git a/lib/puppet/indirector/facts/facter.rb b/lib/puppet/indirector/facts/facter.rb index a8c47e3bf..465d90c13 100644 --- a/lib/puppet/indirector/facts/facter.rb +++ b/lib/puppet/indirector/facts/facter.rb @@ -56,8 +56,8 @@ class Puppet::Node::Facts::Facter < Puppet::Indirector::Code end # Look a host's facts up in Facter. - def find(key) - Puppet::Node::Facts.new(key, Facter.to_hash) + def find(request) + Puppet::Node::Facts.new(request.key, Facter.to_hash) end def save(facts) diff --git a/lib/puppet/indirector/ldap.rb b/lib/puppet/indirector/ldap.rb index fb883def6..07ad38933 100644 --- a/lib/puppet/indirector/ldap.rb +++ b/lib/puppet/indirector/ldap.rb @@ -2,10 +2,10 @@ require 'puppet/indirector/terminus' class Puppet::Indirector::Ldap < Puppet::Indirector::Terminus # Perform our ldap search and process the result. - def find(name) + def find(request) # We have to use 'yield' here because the LDAP::Entry objects # get destroyed outside the scope of the search, strangely. - ldapsearch(name) { |entry| return process(name, entry) } + ldapsearch(request.key) { |entry| return process(request.key, entry) } # Return nil if we haven't found something. return nil diff --git a/lib/puppet/indirector/node/exec.rb b/lib/puppet/indirector/node/exec.rb index dcfc625b2..52cbc370c 100644 --- a/lib/puppet/indirector/node/exec.rb +++ b/lib/puppet/indirector/node/exec.rb @@ -15,20 +15,13 @@ class Puppet::Node::Exec < Puppet::Indirector::Exec end # Look for external node definitions. - def find(name) + def find(request) output = super or return nil # Translate the output to ruby. - result = translate(name, output) + result = translate(request.key, output) - return create_node(name, result) - end - - # Use the version of the facts, since we assume that's the main thing - # that changes. If someone wants their own way of defining version, - # they can easily provide their own, um, version of this class. - def version(name) - Puppet::Node::Facts.version(name) + return create_node(request.key, result) end private diff --git a/lib/puppet/indirector/node/ldap.rb b/lib/puppet/indirector/node/ldap.rb index 73b5cdd70..6c41c18d4 100644 --- a/lib/puppet/indirector/node/ldap.rb +++ b/lib/puppet/indirector/node/ldap.rb @@ -12,8 +12,11 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap end # Look for our node in ldap. - def find(name) + def find(request) return nil unless information = super + + name = request.key + node = Puppet::Node.new(name) parent_info = nil @@ -123,8 +126,4 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap end filter end - - def version(name) - Puppet::Node::Facts.version(name) - end end diff --git a/lib/puppet/indirector/node/plain.rb b/lib/puppet/indirector/node/plain.rb index 8058563e6..37ceb064d 100644 --- a/lib/puppet/indirector/node/plain.rb +++ b/lib/puppet/indirector/node/plain.rb @@ -11,16 +11,9 @@ class Puppet::Node::Plain < Puppet::Indirector::Plain node instance before it is returned." # Just return an empty node. - def find(name) + def find(request) node = super node.fact_merge node end - - # Use the version of the facts, since we assume that's the main thing - # that changes. If someone wants their own way of defining version, - # they can easily provide their own, um, version of this class. - def version(name) - Puppet::Node::Facts.version(name) - end end diff --git a/lib/puppet/indirector/report/processor.rb b/lib/puppet/indirector/report/processor.rb index fa2b7f36b..135f1649d 100644 --- a/lib/puppet/indirector/report/processor.rb +++ b/lib/puppet/indirector/report/processor.rb @@ -10,8 +10,8 @@ class Puppet::Transaction::Report::Processor < Puppet::Indirector::Code Puppet.settings.use(:main, :reporting, :metrics) end - def save(report) - process(report) + def save(request) + process(request.instance) end private diff --git a/lib/puppet/indirector/terminus.rb b/lib/puppet/indirector/terminus.rb index 3015c8a37..22c56a4d2 100644 --- a/lib/puppet/indirector/terminus.rb +++ b/lib/puppet/indirector/terminus.rb @@ -128,20 +128,6 @@ class Puppet::Indirector::Terminus end end - # Do we have an update for this object? This compares the provided version - # to our version, and returns true if our version is at least as high - # as the asked-about version. - def has_most_recent?(key, vers) - raise Puppet::DevError.new("Cannot check update status when no 'version' method is defined") unless respond_to?(:version) - - if existing_version = version(key) - #puts "%s fresh: %s (%s vs %s)" % [self.name, (existing_version.to_f >= vers.to_f).inspect, existing_version.to_f, vers.to_f] - existing_version.to_f >= vers.to_f - else - false - end - end - def indirection self.class.indirection end @@ -163,17 +149,4 @@ class Puppet::Indirector::Terminus def terminus_type self.class.terminus_type end - - # Provide a default method for retrieving an instance's version. - # By default, just find the resource and get its version. Individual - # terminus types can override this method to provide custom definitions of - # 'versions'. - def version(name) - raise Puppet::DevError.new("Cannot retrieve an instance's version without a :find method") unless respond_to?(:find) - if instance = find(name) - instance.version - else - nil - end - end end -- cgit From d420701522990dd7c55bda7ea1e070254e9dcd13 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 8 Apr 2008 23:48:48 -0500 Subject: Making the log messages around caching better. --- lib/puppet/indirector/indirection.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index 56cd687af..536735c21 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -178,9 +178,9 @@ class Puppet::Indirector::Indirection # See if our instance is in the cache and up to date. if cache? and cached = cache.find(request) if cached.expired? - Puppet.info "Cached %s %s expired at %s; not using" % [self.name, request.key, cached.expiration] + Puppet.info "Not using expired %s for %s from cache; expired at %s" % [self.name, request.key, cached.expiration] else - Puppet.debug "Using cached %s %s" % [self.name, request.key] + Puppet.debug "Using cached %s for %s" % [self.name, request.key] return cached end end @@ -189,7 +189,7 @@ class Puppet::Indirector::Indirection if result = terminus.find(request) result.expiration ||= self.expiration if cache? - Puppet.info "Caching %s %s" % [self.name, request.key] + Puppet.info "Caching %s for %s" % [self.name, request.key] cached_request = request.clone cached_request.instance = result cache.save(cached_request) -- cgit From f285f1aab525a2585532fda0b15b7fd28e994491 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 10 Apr 2008 13:14:58 -0500 Subject: Moved the request creation into the Indirection class instead of the Indirector module. Also, added an 'expire' method to the indirector, so there's an easy way to expire cached instances. --- lib/puppet/indirector.rb | 13 ++++++--- lib/puppet/indirector/indirection.rb | 55 +++++++++++++++++++++++++++--------- 2 files changed, 51 insertions(+), 17 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/indirector.rb b/lib/puppet/indirector.rb index a8a7a84d1..2402b9cbe 100644 --- a/lib/puppet/indirector.rb +++ b/lib/puppet/indirector.rb @@ -40,22 +40,27 @@ module Puppet::Indirector indirection.terminus_class = klass end + # Expire any cached instance. + def expire(*args) + indirection.expire *args + end + def find(*args) - indirection.find Puppet::Indirector::Request.new(indirection.name, :find, *args) + indirection.find *args end def destroy(*args) - indirection.destroy Puppet::Indirector::Request.new(indirection.name, :destroy, *args) + indirection.destroy *args end def search(*args) - indirection.search Puppet::Indirector::Request.new(indirection.name, :search, *args) + indirection.search *args end end module InstanceMethods def save(*args) - self.class.indirection.save Puppet::Indirector::Request.new(self.class.indirection.name, :save, self, *args) + self.class.indirection.save self, *args end end end diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index 536735c21..ccb7ef6e7 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -127,8 +127,8 @@ class Puppet::Indirector::Indirection end # Set up our request object. - def request(key, method, arguments = nil) - Puppet::Indirector::Request.new(self.name, key, method, arguments) + def request(method, key, arguments = nil) + Puppet::Indirector::Request.new(self.name, method, key, arguments) end # Return the singleton terminus for this indirection. @@ -172,7 +172,26 @@ class Puppet::Indirector::Indirection end end - def find(request) + # Expire a cached object, if one is cached. Note that we don't actually + # remove it, we expire it and write it back out to disk. This way people + # can still use the expired object if they want. + def expire(key, *args) + request = request(:expire, key, *args) + + return nil unless cache? + + return nil unless instance = cache.find(key, *args) + + # Set an expiration date in the past + instance.expiration = Time.now - 60 + + cache.save(instance, *args) + end + + # Search for an instance in the appropriate terminus, caching the + # results if caching is configured.. + def find(key, *args) + request = request(:find, key, *args) terminus = prepare(request) # See if our instance is in the cache and up to date. @@ -190,9 +209,7 @@ class Puppet::Indirector::Indirection result.expiration ||= self.expiration if cache? Puppet.info "Caching %s for %s" % [self.name, request.key] - cached_request = request.clone - cached_request.instance = result - cache.save(cached_request) + cache.save request(:save, result, *args) end return result @@ -202,12 +219,14 @@ class Puppet::Indirector::Indirection end # Remove something via the terminus. - def destroy(request) + def destroy(key, *args) + request = request(:destroy, key, *args) terminus = prepare(request) terminus.destroy(request) - if cache? and cached = cache.find(request) + if cache? and cached = cache.find(request(:find, key, *args)) + # Reuse the existing request, since it's equivalent. cache.destroy(request) end @@ -215,17 +234,24 @@ class Puppet::Indirector::Indirection end # Search for more than one instance. Should always return an array. - def search(request) + def search(key, *args) + request = request(:search, key, *args) terminus = prepare(request) - result = terminus.search(request) + if result = terminus.search(request) + raise Puppet::DevError, "Search results from terminus %s are not an array" % terminus.name unless result.is_a?(Array) - result + result.each do |instance| + instance.expiration ||= self.expiration + end + return result + end end # Save the instance in the appropriate terminus. This method is # normally an instance method on the indirected class. - def save(request) + def save(instance, *args) + request = request(:save, instance, *args) terminus = prepare(request) # If caching is enabled, save our document there @@ -238,12 +264,15 @@ class Puppet::Indirector::Indirection # Check authorization if there's a hook available; fail if there is one # and it returns false. def check_authorization(request, terminus) + # At this point, we're assuming authorization makes no sense without + # client information. return unless request.options[:node] + # This is only to authorize via a terminus-specific authorization hook. return unless terminus.respond_to?(:authorized?) unless terminus.authorized?(request) - raise ArgumentError, "Not authorized to call %s with %s" % [request.method, request.options.inspect] + raise ArgumentError, "Not authorized to call %s on %s with %s" % [request.method, request.key, request.options.inspect] end end -- cgit From 738889ba027b894867209d5175c716f9a2cc54c6 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 10 Apr 2008 14:44:14 -0500 Subject: Fixing the expire method (it wasn't using a request internally), and fixing the Facts class so it auto-expires any associated cached nodes when facts are saved. --- lib/puppet/indirector/indirection.rb | 6 ++++-- lib/puppet/node/facts.rb | 10 +++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index ccb7ef6e7..15358a801 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -180,12 +180,14 @@ class Puppet::Indirector::Indirection return nil unless cache? - return nil unless instance = cache.find(key, *args) + return nil unless instance = cache.find(request(:find, key, *args)) + + Puppet.info "Expiring the %s cache of %s" % [self.name, instance.name] # Set an expiration date in the past instance.expiration = Time.now - 60 - cache.save(instance, *args) + cache.save(request(:save, instance, *args)) end # Search for an instance in the appropriate terminus, caching the diff --git a/lib/puppet/node/facts.rb b/lib/puppet/node/facts.rb index c60be3fcf..8ee90b4ac 100755 --- a/lib/puppet/node/facts.rb +++ b/lib/puppet/node/facts.rb @@ -8,8 +8,16 @@ class Puppet::Node::Facts # the node sources. extend Puppet::Indirector + # We want to expire any cached nodes if the facts are saved. + module NodeExpirer + def save(instance, *args) + Puppet::Node.expire(instance.name) + super + end + end + # Use the node source as the indirection terminus. - indirects :facts, :terminus_class => :facter + indirects :facts, :terminus_class => :facter, :extend => NodeExpirer attr_accessor :name, :values -- cgit From 3718b6410b6d0312027308c809ca5bf623538498 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 10 Apr 2008 15:49:12 -0500 Subject: Fixing #1173 -- classes and definitions can now have the same name as a directory with no failures. --- lib/puppet/module.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb index 54212710d..b86931664 100644 --- a/lib/puppet/module.rb +++ b/lib/puppet/module.rb @@ -132,7 +132,7 @@ class Puppet::Module def manifests(rest) rest ||= "init.pp" p = File::join(path, MANIFESTS, rest) - files = Dir.glob(p) + files = Dir.glob(p).reject { |f| FileTest.directory?(f) } if files.size == 0 files = Dir.glob(p + ".pp") end -- cgit From 376628d117f43d3319bfa1cc65d54c2d7af10b42 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 10 Apr 2008 23:17:36 -0500 Subject: Removed the code from the client that tries to avoid recompiling the catalog. The client will now always recompile, assuming it can reach the server. It will still use the cached config if there's a failure. --- lib/puppet/network/client/master.rb | 58 ++----------------------------------- 1 file changed, 2 insertions(+), 56 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/network/client/master.rb b/lib/puppet/network/client/master.rb index 955acbfb5..22bb3fa4e 100644 --- a/lib/puppet/network/client/master.rb +++ b/lib/puppet/network/client/master.rb @@ -49,6 +49,8 @@ class Puppet::Network::Client::Master < Puppet::Network::Client end # Return the list of dynamic facts as an array of symbols + # NOTE:LAK(2008/04/10): This code is currently unused, since we now always + # recompile. def self.dynamic_facts # LAK:NOTE See http://snurl.com/21zf8 [groups_google_com] x = Puppet.settings[:dynamicfacts].split(/\s*,\s*/).collect { |fact| fact.downcase } @@ -97,31 +99,6 @@ class Puppet::Network::Client::Master < Puppet::Network::Client end end - # Check whether our catalog is up to date - def fresh?(facts) - if Puppet[:ignorecache] - Puppet.notice "Ignoring cache" - return false - end - unless self.compile_time - Puppet.debug "No cached compile time" - return false - end - if facts_changed?(facts) - Puppet.info "Facts have changed; recompiling" unless local? - return false - end - - newcompile = @driver.freshness - # We're willing to give a 2 second drift - if newcompile - @compile_time.to_i < 1 - return true - else - Puppet.debug "Server compile time is %s vs %s" % [newcompile, @compile_time.to_i] - return false - end - end - # Let the daemon run again, freely in the filesystem. Frolick, little # daemon! def enable @@ -148,11 +125,6 @@ class Puppet::Network::Client::Master < Puppet::Network::Client # Retrieve the plugins. getplugins() if Puppet[:pluginsync] - if (self.catalog or FileTest.exist?(self.cachefile)) and self.fresh?(facts) - Puppet.info "Configuration is up to date" - return if use_cached_config - end - Puppet.debug("Retrieving catalog") # If we can't retrieve the catalog, just return, which will either @@ -451,32 +423,6 @@ class Puppet::Network::Client::Master < Puppet::Network::Client loadfacts() - # Have the facts changed since we last compiled? - def facts_changed?(facts) - oldfacts = (Puppet::Util::Storage.cache(:configuration)[:facts] || {}).dup - newfacts = facts.dup - self.class.dynamic_facts.each do |fact| - [oldfacts, newfacts].each do |facthash| - facthash.delete(fact) if facthash.include?(fact) - end - end - - if oldfacts == newfacts - return false - else -# unless oldfacts -# puts "no old facts" -# return true -# end -# newfacts.keys.each do |k| -# unless newfacts[k] == oldfacts[k] -# puts "%s: %s vs %s" % [k, newfacts[k], oldfacts[k]] -# end -# end - return true - end - end - # Actually retrieve the catalog, either from the server or from a # local master. def get_actual_config(facts) -- cgit From 2925ad1cb9aa820785afca58c4fb6e34274dadd4 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 10 Apr 2008 23:18:20 -0500 Subject: Fixed #1184 -- definitions now autoload correctly all of the time. --- lib/puppet/parser/parser_support.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb index b86a4792b..d70722fdd 100644 --- a/lib/puppet/parser/parser_support.rb +++ b/lib/puppet/parser/parser_support.rb @@ -237,7 +237,9 @@ class Puppet::Parser::Parser end end - return true if classes.include?(classname) + # We don't know whether we're looking for a class or definition, so we have + # to test for both. + return true if classes.include?(classname) || definitions.include?(classname) unless @loaded.include?(filename) @loaded << filename @@ -249,7 +251,9 @@ class Puppet::Parser::Parser # We couldn't load the file end end - return classes.include?(classname) + # We don't know whether we're looking for a class or definition, so we have + # to test for both. + return classes.include?(classname) || definitions.include?(classname) end # Split an fq name into a namespace and name -- cgit From 4aaad26509b2dc9bd45782ec45231e6ea53a4a37 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 11 Apr 2008 11:34:51 -0500 Subject: Modified the 'master' handler to use the Catalog class to compile node configurations, rather than using the Configuration handler, which was never used directly. I removed the Configuration handler as a result. Modified the 'master' handler (responsible for sending configurations to clients) to always return Time.now as its compile date, so configurations will always get recompiled. --- lib/puppet/indirector/catalog/compiler.rb | 18 +-- lib/puppet/network/handler/configuration.rb | 184 ---------------------------- lib/puppet/network/handler/master.rb | 21 +--- lib/puppet/parser/resource.rb | 6 + 4 files changed, 11 insertions(+), 218 deletions(-) delete mode 100644 lib/puppet/network/handler/configuration.rb (limited to 'lib/puppet') diff --git a/lib/puppet/indirector/catalog/compiler.rb b/lib/puppet/indirector/catalog/compiler.rb index ecc340f75..2b5e8d912 100644 --- a/lib/puppet/indirector/catalog/compiler.rb +++ b/lib/puppet/indirector/catalog/compiler.rb @@ -19,7 +19,7 @@ class Puppet::Node::Catalog::Compiler < Puppet::Indirector::Code end if catalog = compile(node) - return catalog.to_transportable + return catalog else # This shouldn't actually happen; we should either return # a config or raise an exception. @@ -44,22 +44,6 @@ class Puppet::Node::Catalog::Compiler < Puppet::Indirector::Code $0 =~ /puppetmasterd/ end - # Return the catalog version. Here we're returning the - # latest of the node, fact, or parse date. These are the - # three things that go into compiling a client catalog, - # so changes in any of them result in changes. - # LAK:FIXME Note that this only works when all three sources - # use timestamps; once one of them moves to using real versions, - # the comparison stops working. - def version(key) - if node = Puppet::Node.find_by_any_name(key) - return [Puppet::Node.version(key).to_f, Puppet::Node::Facts.version(key).to_f, interpreter.catalog_version(node).to_f].sort[-1] - else - # This is the standard for "got nothing for ya". - 0 - end - end - private # Add any extra data necessary to the node. diff --git a/lib/puppet/network/handler/configuration.rb b/lib/puppet/network/handler/configuration.rb deleted file mode 100644 index 8168ce1d5..000000000 --- a/lib/puppet/network/handler/configuration.rb +++ /dev/null @@ -1,184 +0,0 @@ -require 'openssl' -require 'puppet' -require 'puppet/parser/interpreter' -require 'puppet/sslcertificates' -require 'xmlrpc/server' -require 'yaml' - -class Puppet::Network::Handler - class Configuration < Handler - desc "Puppet's configuration compilation interface. Passed a node name - or other key, retrieves information about the node (using the ``node_source``) - and returns a compiled configuration." - - include Puppet::Util - - attr_accessor :local, :classes - - @interface = XMLRPC::Service::Interface.new("configuration") { |iface| - iface.add_method("string configuration(string)") - iface.add_method("string version()") - } - - # Compile a node's configuration. - def configuration(key, client = nil, clientip = nil) - # If we want to use the cert name as our key - if Puppet[:node_name] == 'cert' and client - key = client - end - - # Note that this is reasonable, because either their node source should actually - # know about the node, or they should be using the ``none`` node source, which - # will always return data. - unless node = Puppet::Node.find_by_any_name(key) - raise Puppet::Error, "Could not find node '%s'" % key - end - - # Add any external data to the node. - add_node_data(node) - - configuration = compile(node) - - return translate(configuration) - end - - def initialize(options = {}) - options.each do |param, value| - case param - when :Classes: @classes = value - when :Local: self.local = value - else - raise ArgumentError, "Configuration handler does not accept %s" % param - end - end - - set_server_facts - end - - # Are we running locally, or are our clients networked? - def local? - self.local - end - - # Return the configuration version. - def version(client = nil, clientip = nil) - if client and node = Puppet::Node.find_by_any_name(client) - update_node_check(node) - return interpreter.configuration_version(node) - else - # Just return something that will always result in a recompile, because - # this is local. - return (Time.now + 1000).to_i - end - end - - private - - # Add any extra data necessary to the node. - def add_node_data(node) - # Merge in our server-side facts, so they can be used during compilation. - node.merge(@server_facts) - - # Add any specified classes to the node's class list. - if @classes - @classes.each do |klass| - node.classes << klass - end - end - end - - # Compile the actual configuration. - def compile(node) - # Pick the benchmark level. - if local? - level = :none - else - level = :notice - end - - # Ask the interpreter to compile the configuration. - str = "Compiled configuration for %s" % node.name - if node.environment - str += " in environment %s" % node.environment - end - config = nil - benchmark(level, "Compiled configuration for %s" % node.name) do - begin - config = interpreter.compile(node) - rescue => detail - # If we're local, then we leave it to the local system - # to handle error reporting, but otherwise we do it here - # so the interpreter doesn't need to know if the parser - # is local or not. - Puppet.err(detail.to_s) unless local? - raise - end - end - - return config - end - - # Create our interpreter object. - def create_interpreter - return Puppet::Parser::Interpreter.new - end - - # Create/return our interpreter. - def interpreter - unless defined?(@interpreter) and @interpreter - @interpreter = create_interpreter - end - @interpreter - end - - # Initialize our server fact hash; we add these to each client, and they - # won't change while we're running, so it's safe to cache the values. - def set_server_facts - @server_facts = {} - - # Add our server version to the fact list - @server_facts["serverversion"] = Puppet.version.to_s - - # And then add the server name and IP - {"servername" => "fqdn", - "serverip" => "ipaddress" - }.each do |var, fact| - if value = Facter.value(fact) - @server_facts[var] = value - else - Puppet.warning "Could not retrieve fact %s" % fact - end - end - - if @server_facts["servername"].nil? - host = Facter.value(:hostname) - if domain = Facter.value(:domain) - @server_facts["servername"] = [host, domain].join(".") - else - @server_facts["servername"] = host - end - end - end - - # Translate our configuration appropriately for sending back to a client. - def translate(config) - if local? - config - else - CGI.escape(config.to_yaml(:UseBlock => true)) - end - end - - # Mark that the node has checked in. FIXME this needs to be moved into - # the Node class, or somewhere that's got abstract backends. - def update_node_check(node) - if Puppet.features.rails? and Puppet[:storeconfigs] - Puppet::Rails.connect - - host = Puppet::Rails::Host.find_or_create_by_name(node.name) - host.last_freshcheck = Time.now - host.save - end - end - end -end diff --git a/lib/puppet/network/handler/master.rb b/lib/puppet/network/handler/master.rb index dabfaca50..851ccc7b2 100644 --- a/lib/puppet/network/handler/master.rb +++ b/lib/puppet/network/handler/master.rb @@ -23,8 +23,8 @@ class Puppet::Network::Handler # Tell a client whether there's a fresh config for it def freshness(client = nil, clientip = nil) - client ||= Facter.value("hostname") - config_handler.version(client, clientip) + # Always force a recompile. Newer clients shouldn't do this (as of April 2008). + Time.now end def initialize(hash = {}) @@ -51,8 +51,6 @@ class Puppet::Network::Handler if hash.include?(:Classes) args[:Classes] = hash[:Classes] end - - @config_handler = Puppet::Network::Handler.handler(:configuration).new(args) end # Call our various handlers; this handler is getting deprecated. @@ -63,13 +61,9 @@ class Puppet::Network::Handler # Pass the facts to the fact handler Puppet::Node::Facts.new(client, facts).save unless local? - # And get the configuration from the config handler - config = nil - benchmark(:notice, "Compiled configuration for %s" % client) do - config = config_handler.configuration(client) - end + catalog = Puppet::Node::Catalog.find(client) - return translate(config.extract) + return translate(catalog.extract) end private @@ -93,13 +87,6 @@ class Puppet::Network::Handler return client, clientip end - def config_handler - unless defined? @config_handler - @config_handler = Puppet::Network::Handler.handler(:config).new :local => local? - end - @config_handler - end - # def decode_facts(facts) if @local diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index 4b48ff6cf..d214a60ee 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -303,6 +303,12 @@ class Puppet::Parser::Resource return bucket end + # Convert this resource to a RAL resource. We hackishly go via the + # transportable stuff. + def to_type + to_trans.to_type + end + def to_transobject # Now convert to a transobject obj = Puppet::TransObject.new(@ref.title, @ref.type) -- cgit From b49fd495622b15f96faf944db1e70cbe9e7fe7c4 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 11 Apr 2008 13:01:17 -0500 Subject: Resources now return the 'should' value for properties from the [] accessor method (they previously threw an exception when this method was used with properties). This shouldn't have any affect functionally; it just makes the method equivalent to 'should' for properties, but it works for all attribute types now. --- lib/puppet/metatype/attributes.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/metatype/attributes.rb b/lib/puppet/metatype/attributes.rb index b83fcdd78..3f48f22ff 100644 --- a/lib/puppet/metatype/attributes.rb +++ b/lib/puppet/metatype/attributes.rb @@ -477,13 +477,9 @@ class Puppet::Type end if obj = @parameters[name] - # We throw a failure here, because this method is too - # ambiguous when used with properties. - if obj.is_a?(Puppet::Property) - fail "[] called on a property" - else - return obj.value - end + # Note that if this is a property, then the value is the "should" value, + # not the current value. + obj.value else return nil end -- cgit