From 4609e203fd47f8159118bb74a8308f9c6aee179f Mon Sep 17 00:00:00 2001 From: Pieter van de Bruggen Date: Fri, 25 Mar 2011 14:52:48 -0700 Subject: (#6770) Change versioning; adopt :current over :latest. As per discussion with Luke, versions of an interface are first looked up by requiring 'puppet/interface/{name}', and secondarily looked up by requiring '{name}@{version}/puppet/interface/{name}' if the first failed. A version of `:current` can be used to represent the version living in 'puppet/interface/{name}'. Paired-With: Nick Lewis --- lib/puppet/string/catalog.rb | 40 +++++++++++++ lib/puppet/string/catalog/select.rb | 10 ++++ lib/puppet/string/certificate.rb | 28 +++++++++ lib/puppet/string/certificate_request.rb | 4 ++ lib/puppet/string/certificate_revocation_list.rb | 4 ++ lib/puppet/string/config.rb | 11 ++++ lib/puppet/string/configurer.rb | 12 ++++ lib/puppet/string/facts.rb | 18 ++++++ lib/puppet/string/file.rb | 5 ++ lib/puppet/string/key.rb | 4 ++ lib/puppet/string/node.rb | 5 ++ lib/puppet/string/report.rb | 15 +++++ lib/puppet/string/resource.rb | 4 ++ lib/puppet/string/resource_type.rb | 4 ++ lib/puppet/string/status.rb | 4 ++ lib/puppet/string/string_collection.rb | 66 ++++++++-------------- lib/puppet/string/v0.0.1/catalog.rb | 40 ------------- lib/puppet/string/v0.0.1/catalog/select.rb | 10 ---- lib/puppet/string/v0.0.1/certificate.rb | 28 --------- lib/puppet/string/v0.0.1/certificate_request.rb | 4 -- .../string/v0.0.1/certificate_revocation_list.rb | 4 -- lib/puppet/string/v0.0.1/config.rb | 11 ---- lib/puppet/string/v0.0.1/configurer.rb | 12 ---- lib/puppet/string/v0.0.1/facts.rb | 18 ------ lib/puppet/string/v0.0.1/file.rb | 5 -- lib/puppet/string/v0.0.1/key.rb | 4 -- lib/puppet/string/v0.0.1/node.rb | 5 -- lib/puppet/string/v0.0.1/report.rb | 15 ----- lib/puppet/string/v0.0.1/resource.rb | 4 -- lib/puppet/string/v0.0.1/resource_type.rb | 4 -- lib/puppet/string/v0.0.1/status.rb | 4 -- 31 files changed, 190 insertions(+), 212 deletions(-) create mode 100644 lib/puppet/string/catalog.rb create mode 100644 lib/puppet/string/catalog/select.rb create mode 100644 lib/puppet/string/certificate.rb create mode 100644 lib/puppet/string/certificate_request.rb create mode 100644 lib/puppet/string/certificate_revocation_list.rb create mode 100644 lib/puppet/string/config.rb create mode 100644 lib/puppet/string/configurer.rb create mode 100644 lib/puppet/string/facts.rb create mode 100644 lib/puppet/string/file.rb create mode 100644 lib/puppet/string/key.rb create mode 100644 lib/puppet/string/node.rb create mode 100644 lib/puppet/string/report.rb create mode 100644 lib/puppet/string/resource.rb create mode 100644 lib/puppet/string/resource_type.rb create mode 100644 lib/puppet/string/status.rb delete mode 100644 lib/puppet/string/v0.0.1/catalog.rb delete mode 100644 lib/puppet/string/v0.0.1/catalog/select.rb delete mode 100644 lib/puppet/string/v0.0.1/certificate.rb delete mode 100644 lib/puppet/string/v0.0.1/certificate_request.rb delete mode 100644 lib/puppet/string/v0.0.1/certificate_revocation_list.rb delete mode 100644 lib/puppet/string/v0.0.1/config.rb delete mode 100644 lib/puppet/string/v0.0.1/configurer.rb delete mode 100644 lib/puppet/string/v0.0.1/facts.rb delete mode 100644 lib/puppet/string/v0.0.1/file.rb delete mode 100644 lib/puppet/string/v0.0.1/key.rb delete mode 100644 lib/puppet/string/v0.0.1/node.rb delete mode 100644 lib/puppet/string/v0.0.1/report.rb delete mode 100644 lib/puppet/string/v0.0.1/resource.rb delete mode 100644 lib/puppet/string/v0.0.1/resource_type.rb delete mode 100644 lib/puppet/string/v0.0.1/status.rb (limited to 'lib/puppet/string') diff --git a/lib/puppet/string/catalog.rb b/lib/puppet/string/catalog.rb new file mode 100644 index 000000000..0ddd83176 --- /dev/null +++ b/lib/puppet/string/catalog.rb @@ -0,0 +1,40 @@ +require 'puppet/string/indirector' + +Puppet::String::Indirector.define(:catalog, '0.0.1') do + action(:apply) do + invoke do |catalog| + report = Puppet::Transaction::Report.new("apply") + report.configuration_version = catalog.version + + Puppet::Util::Log.newdestination(report) + + begin + benchmark(:notice, "Finished catalog run") do + catalog.apply(:report => report) + end + rescue => detail + puts detail.backtrace if Puppet[:trace] + Puppet.err "Failed to apply catalog: #{detail}" + end + + report.finalize_report + report + end + end + + action(:download) do + invoke do |certname,facts| + Puppet::Resource::Catalog.terminus_class = :rest + facts_to_upload = {:facts_format => :b64_zlib_yaml, :facts => CGI.escape(facts.render(:b64_zlib_yaml))} + catalog = nil + retrieval_duration = thinmark do + catalog = Puppet::String[:catalog, '0.0.1'].find(certname, facts_to_upload) + end + catalog = catalog.to_ral + catalog.finalize + catalog.retrieval_duration = retrieval_duration + catalog.write_class_file + catalog + end + end +end diff --git a/lib/puppet/string/catalog/select.rb b/lib/puppet/string/catalog/select.rb new file mode 100644 index 000000000..52c77d3ce --- /dev/null +++ b/lib/puppet/string/catalog/select.rb @@ -0,0 +1,10 @@ +# Select and show a list of resources of a given type. +Puppet::String.define(:catalog, '0.0.1') do + action :select do + invoke do |host,type| + catalog = Puppet::Resource::Catalog.indirection.find(host) + + catalog.resources.reject { |res| res.type != type }.each { |res| puts res } + end + end +end diff --git a/lib/puppet/string/certificate.rb b/lib/puppet/string/certificate.rb new file mode 100644 index 000000000..7b2e5f397 --- /dev/null +++ b/lib/puppet/string/certificate.rb @@ -0,0 +1,28 @@ +require 'puppet/string/indirector' +require 'puppet/ssl/host' + +Puppet::String::Indirector.define(:certificate, '0.0.1') do + + action :generate do + invoke do |name| + host = Puppet::SSL::Host.new(name) + host.generate_certificate_request + host.certificate_request.class.indirection.save(host.certificate_request) + end + end + + action :list do + invoke do + Puppet::SSL::Host.indirection.search("*", { + :for => :certificate_request, + }).map { |h| h.inspect } + end + end + + action :sign do + invoke do |name| + Puppet::SSL::Host.indirection.save(Puppet::SSL::Host.new(name)) + end + end + +end diff --git a/lib/puppet/string/certificate_request.rb b/lib/puppet/string/certificate_request.rb new file mode 100644 index 000000000..218b40b98 --- /dev/null +++ b/lib/puppet/string/certificate_request.rb @@ -0,0 +1,4 @@ +require 'puppet/string/indirector' + +Puppet::String::Indirector.define(:certificate_request, '0.0.1') do +end diff --git a/lib/puppet/string/certificate_revocation_list.rb b/lib/puppet/string/certificate_revocation_list.rb new file mode 100644 index 000000000..9731b4f2d --- /dev/null +++ b/lib/puppet/string/certificate_revocation_list.rb @@ -0,0 +1,4 @@ +require 'puppet/string/indirector' + +Puppet::String::Indirector.define(:certificate_revocation_list, '0.0.1') do +end diff --git a/lib/puppet/string/config.rb b/lib/puppet/string/config.rb new file mode 100644 index 000000000..ae1a408cf --- /dev/null +++ b/lib/puppet/string/config.rb @@ -0,0 +1,11 @@ +require 'puppet/string' + +Puppet::String.define(:config, '0.0.1') do + action(:print) do + invoke do |*args| + Puppet.settings[:configprint] = args.join(",") + Puppet.settings.print_config_options + nil + end + end +end diff --git a/lib/puppet/string/configurer.rb b/lib/puppet/string/configurer.rb new file mode 100644 index 000000000..a6ea74b6a --- /dev/null +++ b/lib/puppet/string/configurer.rb @@ -0,0 +1,12 @@ +require 'puppet/string' + +Puppet::String.define(:configurer, '0.0.1') do + action(:synchronize) do + invoke do |certname| + facts = Puppet::String[:facts, '0.0.1'].find(certname) + catalog = Puppet::String[:catalog, '0.0.1'].download(certname, facts) + report = Puppet::String[:catalog, '0.0.1'].apply(catalog) + report + end + end +end diff --git a/lib/puppet/string/facts.rb b/lib/puppet/string/facts.rb new file mode 100644 index 000000000..73acb0df6 --- /dev/null +++ b/lib/puppet/string/facts.rb @@ -0,0 +1,18 @@ +require 'puppet/string/indirector' +require 'puppet/node/facts' + +Puppet::String::Indirector.define(:facts, '0.0.1') do + set_default_format :yaml + + # Upload our facts to the server + action(:upload) do + invoke do |*args| + Puppet::Node::Facts.indirection.terminus_class = :facter + facts = Puppet::Node::Facts.indirection.find(Puppet[:certname]) + Puppet::Node::Facts.indirection.terminus_class = :rest + Puppet::Node::Facts.indirection.save(facts) + Puppet.notice "Uploaded facts for '#{Puppet[:certname]}'" + nil + end + end +end diff --git a/lib/puppet/string/file.rb b/lib/puppet/string/file.rb new file mode 100644 index 000000000..cc5737f28 --- /dev/null +++ b/lib/puppet/string/file.rb @@ -0,0 +1,5 @@ +require 'puppet/string/indirector' + +Puppet::String::Indirector.define(:file, '0.0.1') do + set_indirection_name :file_bucket_file +end diff --git a/lib/puppet/string/key.rb b/lib/puppet/string/key.rb new file mode 100644 index 000000000..95aceade5 --- /dev/null +++ b/lib/puppet/string/key.rb @@ -0,0 +1,4 @@ +require 'puppet/string/indirector' + +Puppet::String::Indirector.define(:key, '0.0.1') do +end diff --git a/lib/puppet/string/node.rb b/lib/puppet/string/node.rb new file mode 100644 index 000000000..bc31a2cf3 --- /dev/null +++ b/lib/puppet/string/node.rb @@ -0,0 +1,5 @@ +require 'puppet/string/indirector' + +Puppet::String::Indirector.define(:node, '0.0.1') do + set_default_format :yaml +end diff --git a/lib/puppet/string/report.rb b/lib/puppet/string/report.rb new file mode 100644 index 000000000..55a008533 --- /dev/null +++ b/lib/puppet/string/report.rb @@ -0,0 +1,15 @@ +require 'puppet/string/indirector' + +Puppet::String::Indirector.define(:report, '0.0.1') do + action(:submit) do + invoke do |report| + begin + Puppet::Transaction::Report.terminus_class = :rest + report.save + rescue => detail + puts detail.backtrace if Puppet[:trace] + Puppet.err "Could not send report: #{detail}" + end + end + end +end diff --git a/lib/puppet/string/resource.rb b/lib/puppet/string/resource.rb new file mode 100644 index 000000000..9838be0fa --- /dev/null +++ b/lib/puppet/string/resource.rb @@ -0,0 +1,4 @@ +require 'puppet/string/indirector' + +Puppet::String::Indirector.define(:resource, '0.0.1') do +end diff --git a/lib/puppet/string/resource_type.rb b/lib/puppet/string/resource_type.rb new file mode 100644 index 000000000..8ca31ea6c --- /dev/null +++ b/lib/puppet/string/resource_type.rb @@ -0,0 +1,4 @@ +require 'puppet/string/indirector' + +Puppet::String::Indirector.define(:resource_type, '0.0.1') do +end diff --git a/lib/puppet/string/status.rb b/lib/puppet/string/status.rb new file mode 100644 index 000000000..41de2bb99 --- /dev/null +++ b/lib/puppet/string/status.rb @@ -0,0 +1,4 @@ +require 'puppet/string/indirector' + +Puppet::String::Indirector.define(:status, '0.0.1') do +end diff --git a/lib/puppet/string/string_collection.rb b/lib/puppet/string/string_collection.rb index e9cba7f55..45a192703 100644 --- a/lib/puppet/string/string_collection.rb +++ b/lib/puppet/string/string_collection.rb @@ -26,61 +26,39 @@ module Puppet::String::StringCollection return @strings.keys end - def self.versions(name) - versions = [] - $LOAD_PATH.each do |dir| - next unless FileTest.directory?(dir) - v_dir = File.join dir, %w[puppet string v*] - Dir.glob(File.join v_dir, "#{name}{.rb,/*.rb}").each do |f| - v = f.sub(%r[.*/v([^/]+?)/#{name}(?:(?:/[^/]+)?.rb)$], '\1') - if validate_version(v) - versions << v - else - warn "'#{v}' (#{f}) is not a valid version string; skipping" - end - end - end - return versions.uniq.sort { |a, b| compare_versions(a, b) } - end - def self.validate_version(version) !!(SEMVER_VERSION =~ version.to_s) end - def self.compare_versions(a, b) - a, b = [a, b].map do |x| - parts = SEMVER_VERSION.match(x).to_a[1..4] - parts[0..2] = parts[0..2].map { |e| e.to_i } - parts - end - - cmp = a[0..2] <=> b[0..2] - if cmp == 0 - cmp = a[3] <=> b[3] - cmp = +1 if a[3].empty? && !b[3].empty? - cmp = -1 if b[3].empty? && !a[3].empty? - end - cmp - end - def self.[](name, version) - version = versions(name).last if version == :latest - unless version.nil? - @strings[underscorize(name)][version] if string?(name, version) - end + @strings[underscorize(name)][version] if string?(name, version) end def self.string?(name, version) - version = versions(name).last if version == :latest - return false if version.nil? - name = underscorize(name) + cache = @strings[name] + return true if cache.has_key?(version) - unless @strings.has_key?(name) && @strings[name].has_key?(version) - require "puppet/string/v#{version}/#{name}" + loaded = cache.keys + + files = ["puppet/string/#{name}"] + unless version == :current + files << "#{name}@#{version}/puppet/string/#{name}" end - return @strings.has_key?(name) && @strings[name].has_key?(version) - rescue LoadError + + files.each do |file| + begin + require file + if version == :current || !file.include?('@') + loaded = (cache.keys - loaded).first + cache[:current] = cache[loaded] unless loaded.nil? + end + return true if cache.has_key?(version) + rescue LoadError + # pass + end + end + return false end diff --git a/lib/puppet/string/v0.0.1/catalog.rb b/lib/puppet/string/v0.0.1/catalog.rb deleted file mode 100644 index 0ddd83176..000000000 --- a/lib/puppet/string/v0.0.1/catalog.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'puppet/string/indirector' - -Puppet::String::Indirector.define(:catalog, '0.0.1') do - action(:apply) do - invoke do |catalog| - report = Puppet::Transaction::Report.new("apply") - report.configuration_version = catalog.version - - Puppet::Util::Log.newdestination(report) - - begin - benchmark(:notice, "Finished catalog run") do - catalog.apply(:report => report) - end - rescue => detail - puts detail.backtrace if Puppet[:trace] - Puppet.err "Failed to apply catalog: #{detail}" - end - - report.finalize_report - report - end - end - - action(:download) do - invoke do |certname,facts| - Puppet::Resource::Catalog.terminus_class = :rest - facts_to_upload = {:facts_format => :b64_zlib_yaml, :facts => CGI.escape(facts.render(:b64_zlib_yaml))} - catalog = nil - retrieval_duration = thinmark do - catalog = Puppet::String[:catalog, '0.0.1'].find(certname, facts_to_upload) - end - catalog = catalog.to_ral - catalog.finalize - catalog.retrieval_duration = retrieval_duration - catalog.write_class_file - catalog - end - end -end diff --git a/lib/puppet/string/v0.0.1/catalog/select.rb b/lib/puppet/string/v0.0.1/catalog/select.rb deleted file mode 100644 index 52c77d3ce..000000000 --- a/lib/puppet/string/v0.0.1/catalog/select.rb +++ /dev/null @@ -1,10 +0,0 @@ -# Select and show a list of resources of a given type. -Puppet::String.define(:catalog, '0.0.1') do - action :select do - invoke do |host,type| - catalog = Puppet::Resource::Catalog.indirection.find(host) - - catalog.resources.reject { |res| res.type != type }.each { |res| puts res } - end - end -end diff --git a/lib/puppet/string/v0.0.1/certificate.rb b/lib/puppet/string/v0.0.1/certificate.rb deleted file mode 100644 index 7b2e5f397..000000000 --- a/lib/puppet/string/v0.0.1/certificate.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'puppet/string/indirector' -require 'puppet/ssl/host' - -Puppet::String::Indirector.define(:certificate, '0.0.1') do - - action :generate do - invoke do |name| - host = Puppet::SSL::Host.new(name) - host.generate_certificate_request - host.certificate_request.class.indirection.save(host.certificate_request) - end - end - - action :list do - invoke do - Puppet::SSL::Host.indirection.search("*", { - :for => :certificate_request, - }).map { |h| h.inspect } - end - end - - action :sign do - invoke do |name| - Puppet::SSL::Host.indirection.save(Puppet::SSL::Host.new(name)) - end - end - -end diff --git a/lib/puppet/string/v0.0.1/certificate_request.rb b/lib/puppet/string/v0.0.1/certificate_request.rb deleted file mode 100644 index 218b40b98..000000000 --- a/lib/puppet/string/v0.0.1/certificate_request.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'puppet/string/indirector' - -Puppet::String::Indirector.define(:certificate_request, '0.0.1') do -end diff --git a/lib/puppet/string/v0.0.1/certificate_revocation_list.rb b/lib/puppet/string/v0.0.1/certificate_revocation_list.rb deleted file mode 100644 index 9731b4f2d..000000000 --- a/lib/puppet/string/v0.0.1/certificate_revocation_list.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'puppet/string/indirector' - -Puppet::String::Indirector.define(:certificate_revocation_list, '0.0.1') do -end diff --git a/lib/puppet/string/v0.0.1/config.rb b/lib/puppet/string/v0.0.1/config.rb deleted file mode 100644 index ae1a408cf..000000000 --- a/lib/puppet/string/v0.0.1/config.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'puppet/string' - -Puppet::String.define(:config, '0.0.1') do - action(:print) do - invoke do |*args| - Puppet.settings[:configprint] = args.join(",") - Puppet.settings.print_config_options - nil - end - end -end diff --git a/lib/puppet/string/v0.0.1/configurer.rb b/lib/puppet/string/v0.0.1/configurer.rb deleted file mode 100644 index a6ea74b6a..000000000 --- a/lib/puppet/string/v0.0.1/configurer.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'puppet/string' - -Puppet::String.define(:configurer, '0.0.1') do - action(:synchronize) do - invoke do |certname| - facts = Puppet::String[:facts, '0.0.1'].find(certname) - catalog = Puppet::String[:catalog, '0.0.1'].download(certname, facts) - report = Puppet::String[:catalog, '0.0.1'].apply(catalog) - report - end - end -end diff --git a/lib/puppet/string/v0.0.1/facts.rb b/lib/puppet/string/v0.0.1/facts.rb deleted file mode 100644 index 73acb0df6..000000000 --- a/lib/puppet/string/v0.0.1/facts.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'puppet/string/indirector' -require 'puppet/node/facts' - -Puppet::String::Indirector.define(:facts, '0.0.1') do - set_default_format :yaml - - # Upload our facts to the server - action(:upload) do - invoke do |*args| - Puppet::Node::Facts.indirection.terminus_class = :facter - facts = Puppet::Node::Facts.indirection.find(Puppet[:certname]) - Puppet::Node::Facts.indirection.terminus_class = :rest - Puppet::Node::Facts.indirection.save(facts) - Puppet.notice "Uploaded facts for '#{Puppet[:certname]}'" - nil - end - end -end diff --git a/lib/puppet/string/v0.0.1/file.rb b/lib/puppet/string/v0.0.1/file.rb deleted file mode 100644 index cc5737f28..000000000 --- a/lib/puppet/string/v0.0.1/file.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'puppet/string/indirector' - -Puppet::String::Indirector.define(:file, '0.0.1') do - set_indirection_name :file_bucket_file -end diff --git a/lib/puppet/string/v0.0.1/key.rb b/lib/puppet/string/v0.0.1/key.rb deleted file mode 100644 index 95aceade5..000000000 --- a/lib/puppet/string/v0.0.1/key.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'puppet/string/indirector' - -Puppet::String::Indirector.define(:key, '0.0.1') do -end diff --git a/lib/puppet/string/v0.0.1/node.rb b/lib/puppet/string/v0.0.1/node.rb deleted file mode 100644 index bc31a2cf3..000000000 --- a/lib/puppet/string/v0.0.1/node.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'puppet/string/indirector' - -Puppet::String::Indirector.define(:node, '0.0.1') do - set_default_format :yaml -end diff --git a/lib/puppet/string/v0.0.1/report.rb b/lib/puppet/string/v0.0.1/report.rb deleted file mode 100644 index 55a008533..000000000 --- a/lib/puppet/string/v0.0.1/report.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'puppet/string/indirector' - -Puppet::String::Indirector.define(:report, '0.0.1') do - action(:submit) do - invoke do |report| - begin - Puppet::Transaction::Report.terminus_class = :rest - report.save - rescue => detail - puts detail.backtrace if Puppet[:trace] - Puppet.err "Could not send report: #{detail}" - end - end - end -end diff --git a/lib/puppet/string/v0.0.1/resource.rb b/lib/puppet/string/v0.0.1/resource.rb deleted file mode 100644 index 9838be0fa..000000000 --- a/lib/puppet/string/v0.0.1/resource.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'puppet/string/indirector' - -Puppet::String::Indirector.define(:resource, '0.0.1') do -end diff --git a/lib/puppet/string/v0.0.1/resource_type.rb b/lib/puppet/string/v0.0.1/resource_type.rb deleted file mode 100644 index 8ca31ea6c..000000000 --- a/lib/puppet/string/v0.0.1/resource_type.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'puppet/string/indirector' - -Puppet::String::Indirector.define(:resource_type, '0.0.1') do -end diff --git a/lib/puppet/string/v0.0.1/status.rb b/lib/puppet/string/v0.0.1/status.rb deleted file mode 100644 index 41de2bb99..000000000 --- a/lib/puppet/string/v0.0.1/status.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'puppet/string/indirector' - -Puppet::String::Indirector.define(:status, '0.0.1') do -end -- cgit