diff options
| author | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-07 17:58:07 -0700 |
|---|---|---|
| committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-07 18:01:33 -0700 |
| commit | 0f24db1c3fd0aa6601ba032aedbe25be36010954 (patch) | |
| tree | 08af1180a4468145af66ee429ce3a80236e08fff /lib/puppet/faces | |
| parent | af792351a62399f8bbeba0d2425f2b88eabb3dff (diff) | |
| parent | 79f4774182046d2fdf392c1eb27ee78505659199 (diff) | |
| download | puppet-0f24db1c3fd0aa6601ba032aedbe25be36010954.tar.gz puppet-0f24db1c3fd0aa6601ba032aedbe25be36010954.tar.xz puppet-0f24db1c3fd0aa6601ba032aedbe25be36010954.zip | |
Merge puppet-interfaces into puppet.
This joins the two repositories, including full history, into a single run, as
well as landing the interfaces work on the next branch ready for release.
Diffstat (limited to 'lib/puppet/faces')
| -rw-r--r-- | lib/puppet/faces/catalog.rb | 40 | ||||
| -rw-r--r-- | lib/puppet/faces/catalog/select.rb | 10 | ||||
| -rw-r--r-- | lib/puppet/faces/certificate.rb | 46 | ||||
| -rw-r--r-- | lib/puppet/faces/certificate_request.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/faces/certificate_revocation_list.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/faces/config.rb | 12 | ||||
| -rw-r--r-- | lib/puppet/faces/configurer.rb | 12 | ||||
| -rw-r--r-- | lib/puppet/faces/facts.rb | 18 | ||||
| -rw-r--r-- | lib/puppet/faces/file.rb | 5 | ||||
| -rw-r--r-- | lib/puppet/faces/indirector.rb | 94 | ||||
| -rw-r--r-- | lib/puppet/faces/key.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/faces/node.rb | 5 | ||||
| -rw-r--r-- | lib/puppet/faces/report.rb | 15 | ||||
| -rw-r--r-- | lib/puppet/faces/resource.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/faces/resource_type.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/faces/status.rb | 4 |
16 files changed, 281 insertions, 0 deletions
diff --git a/lib/puppet/faces/catalog.rb b/lib/puppet/faces/catalog.rb new file mode 100644 index 000000000..3353d5d04 --- /dev/null +++ b/lib/puppet/faces/catalog.rb @@ -0,0 +1,40 @@ +require 'puppet/faces/indirector' + +Puppet::Faces::Indirector.define(:catalog, '0.0.1') do + action(:apply) do + when_invoked do |catalog, options| + 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 + when_invoked do |certname, facts, options| + Puppet::Resource::Catalog.indirection.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::Faces[: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/faces/catalog/select.rb b/lib/puppet/faces/catalog/select.rb new file mode 100644 index 000000000..e29d19970 --- /dev/null +++ b/lib/puppet/faces/catalog/select.rb @@ -0,0 +1,10 @@ +# Select and show a list of resources of a given type. +Puppet::Faces.define(:catalog, '0.0.1') do + action :select do + when_invoked do |host, type, options| + 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/faces/certificate.rb b/lib/puppet/faces/certificate.rb new file mode 100644 index 000000000..b10bee579 --- /dev/null +++ b/lib/puppet/faces/certificate.rb @@ -0,0 +1,46 @@ +require 'puppet/faces/indirector' +require 'puppet/ssl/host' + +Puppet::Faces::Indirector.define(:certificate, '0.0.1') do + # REVISIT: This should use a pre-invoke hook to run the common code that + # needs to happen before we invoke any action; that would be much nicer than + # the "please repeat yourself" stuff found in here right now. + # + # option "--ca-location LOCATION" do + # type [:whatever, :location, :symbols] + # hook :before do |value| + # Puppet::SSL::Host.ca_location = value + # end + # end + # + # ...but should I pass the arguments as well? + # --daniel 2011-04-05 + option "--ca-location LOCATION" + + action :generate do + when_invoked do |name, options| + Puppet::SSL::Host.ca_location = options[:ca_location].to_sym + host = Puppet::SSL::Host.new(name) + host.generate_certificate_request + host.certificate_request.class.indirection.save(host.certificate_request) + end + end + + action :list do + when_invoked do |options| + Puppet::SSL::Host.ca_location = options[:ca_location].to_sym + Puppet::SSL::Host.indirection.search("*", { + :for => :certificate_request, + }).map { |h| h.inspect } + end + end + + action :sign do + when_invoked do |name, options| + Puppet::SSL::Host.ca_location = options[:ca_location].to_sym + host = Puppet::SSL::Host.new(name) + host.desired_state = 'signed' + Puppet::SSL::Host.indirection.save(host) + end + end +end diff --git a/lib/puppet/faces/certificate_request.rb b/lib/puppet/faces/certificate_request.rb new file mode 100644 index 000000000..5e91bdb7f --- /dev/null +++ b/lib/puppet/faces/certificate_request.rb @@ -0,0 +1,4 @@ +require 'puppet/faces/indirector' + +Puppet::Faces::Indirector.define(:certificate_request, '0.0.1') do +end diff --git a/lib/puppet/faces/certificate_revocation_list.rb b/lib/puppet/faces/certificate_revocation_list.rb new file mode 100644 index 000000000..2f2d72874 --- /dev/null +++ b/lib/puppet/faces/certificate_revocation_list.rb @@ -0,0 +1,4 @@ +require 'puppet/faces/indirector' + +Puppet::Faces::Indirector.define(:certificate_revocation_list, '0.0.1') do +end diff --git a/lib/puppet/faces/config.rb b/lib/puppet/faces/config.rb new file mode 100644 index 000000000..647bf5052 --- /dev/null +++ b/lib/puppet/faces/config.rb @@ -0,0 +1,12 @@ +require 'puppet/faces' + +Puppet::Faces.define(:config, '0.0.1') do + action(:print) do + when_invoked do |*args| + options = args.pop + Puppet.settings[:configprint] = args.join(",") + Puppet.settings.print_config_options + nil + end + end +end diff --git a/lib/puppet/faces/configurer.rb b/lib/puppet/faces/configurer.rb new file mode 100644 index 000000000..d40987697 --- /dev/null +++ b/lib/puppet/faces/configurer.rb @@ -0,0 +1,12 @@ +require 'puppet/faces' + +Puppet::Faces.define(:configurer, '0.0.1') do + action(:synchronize) do + when_invoked do |certname, options| + facts = Puppet::Faces[:facts, '0.0.1'].find(certname) + catalog = Puppet::Faces[:catalog, '0.0.1'].download(certname, facts) + report = Puppet::Faces[:catalog, '0.0.1'].apply(catalog) + report + end + end +end diff --git a/lib/puppet/faces/facts.rb b/lib/puppet/faces/facts.rb new file mode 100644 index 000000000..33eacef38 --- /dev/null +++ b/lib/puppet/faces/facts.rb @@ -0,0 +1,18 @@ +require 'puppet/faces/indirector' +require 'puppet/node/facts' + +Puppet::Faces::Indirector.define(:facts, '0.0.1') do + set_default_format :yaml + + # Upload our facts to the server + action(:upload) do + when_invoked do |options| + 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/faces/file.rb b/lib/puppet/faces/file.rb new file mode 100644 index 000000000..e8ad18c17 --- /dev/null +++ b/lib/puppet/faces/file.rb @@ -0,0 +1,5 @@ +require 'puppet/faces/indirector' + +Puppet::Faces::Indirector.define(:file, '0.0.1') do + set_indirection_name :file_bucket_file +end diff --git a/lib/puppet/faces/indirector.rb b/lib/puppet/faces/indirector.rb new file mode 100644 index 000000000..7e4e0f00f --- /dev/null +++ b/lib/puppet/faces/indirector.rb @@ -0,0 +1,94 @@ +require 'puppet' +require 'puppet/faces' + +class Puppet::Faces::Indirector < Puppet::Faces + option "--terminus TERMINUS" do + desc "REVISIT: You can select a terminus, which has some bigger effect +that we should describe in this file somehow." + end + + def self.indirections + Puppet::Indirector::Indirection.instances.collect { |t| t.to_s }.sort + end + + def self.terminus_classes(indirection) + Puppet::Indirector::Terminus.terminus_classes(indirection.to_sym).collect { |t| t.to_s }.sort + end + + def call_indirection_method(method, *args) + options = args.last + options.has_key?(:terminus) and set_terminus(options[:terminus]) + + begin + result = indirection.__send__(method, *args) + rescue => detail + puts detail.backtrace if Puppet[:trace] + raise "Could not call '#{method}' on '#{indirection_name}': #{detail}" + end + + indirection.reset_terminus_class + return result + end + + action :destroy do + when_invoked { |*args| call_indirection_method(:destroy, *args) } + end + + action :find do + when_invoked { |*args| call_indirection_method(:find, *args) } + end + + action :save do + when_invoked { |*args| call_indirection_method(:save, *args) } + end + + action :search do + when_invoked { |*args| call_indirection_method(:search, *args) } + end + + # Print the configuration for the current terminus class + action :info do + when_invoked do |*args| + options = args.pop + options.has_key?(:terminus) and set_terminus(options[:terminus]) + + if t = indirection.terminus_class + puts "Run mode '#{Puppet.run_mode.name}': #{t}" + else + $stderr.puts "No default terminus class for run mode '#{Puppet.run_mode.name}'" + end + + indirection.reset_terminus_class + end + end + + attr_accessor :from + + def indirection_name + @indirection_name || name.to_sym + end + + # Here's your opportunity to override the indirection name. By default it + # will be the same name as the face. + def set_indirection_name(name) + @indirection_name = name + end + + # Return an indirection associated with a face, if one exists; + # One usually does. + def indirection + unless @indirection + @indirection = Puppet::Indirector::Indirection.instance(indirection_name) + @indirection or raise "Could not find terminus for #{indirection_name}" + end + @indirection + end + + def set_terminus(from) + begin + indirection.terminus_class = from + rescue => detail + raise "Could not set '#{indirection.name}' terminus to '#{from}' (#{detail}); valid terminus types are #{self.class.terminus_classes(indirection.name).join(", ") }" + end + end +end diff --git a/lib/puppet/faces/key.rb b/lib/puppet/faces/key.rb new file mode 100644 index 000000000..7b6ad52ac --- /dev/null +++ b/lib/puppet/faces/key.rb @@ -0,0 +1,4 @@ +require 'puppet/faces/indirector' + +Puppet::Faces::Indirector.define(:key, '0.0.1') do +end diff --git a/lib/puppet/faces/node.rb b/lib/puppet/faces/node.rb new file mode 100644 index 000000000..7eed0df91 --- /dev/null +++ b/lib/puppet/faces/node.rb @@ -0,0 +1,5 @@ +require 'puppet/faces/indirector' + +Puppet::Faces::Indirector.define(:node, '0.0.1') do + set_default_format :yaml +end diff --git a/lib/puppet/faces/report.rb b/lib/puppet/faces/report.rb new file mode 100644 index 000000000..23a518981 --- /dev/null +++ b/lib/puppet/faces/report.rb @@ -0,0 +1,15 @@ +require 'puppet/faces/indirector' + +Puppet::Faces::Indirector.define(:report, '0.0.1') do + action(:submit) do + when_invoked do |report, options| + 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/faces/resource.rb b/lib/puppet/faces/resource.rb new file mode 100644 index 000000000..60b0d94db --- /dev/null +++ b/lib/puppet/faces/resource.rb @@ -0,0 +1,4 @@ +require 'puppet/faces/indirector' + +Puppet::Faces::Indirector.define(:resource, '0.0.1') do +end diff --git a/lib/puppet/faces/resource_type.rb b/lib/puppet/faces/resource_type.rb new file mode 100644 index 000000000..4321d65e7 --- /dev/null +++ b/lib/puppet/faces/resource_type.rb @@ -0,0 +1,4 @@ +require 'puppet/faces/indirector' + +Puppet::Faces::Indirector.define(:resource_type, '0.0.1') do +end diff --git a/lib/puppet/faces/status.rb b/lib/puppet/faces/status.rb new file mode 100644 index 000000000..e035f281f --- /dev/null +++ b/lib/puppet/faces/status.rb @@ -0,0 +1,4 @@ +require 'puppet/faces/indirector' + +Puppet::Faces::Indirector.define(:status, '0.0.1') do +end |
