This repository has been archived by the owner on Nov 29, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'puppet/application' | ||
require 'puppet/interface' | ||
|
||
class Puppet::Application::Configurer < Puppet::Application | ||
should_parse_config | ||
run_mode :agent | ||
|
||
option("--debug","-d") | ||
option("--verbose","-v") | ||
|
||
def setup | ||
if options[:debug] or options[:verbose] | ||
Puppet::Util::Log.level = options[:debug] ? :debug : :info | ||
end | ||
|
||
Puppet::Util::Log.newdestination(:console) | ||
end | ||
|
||
def run_command | ||
report = Puppet::Interface::Configurer.synchronize(Puppet[:certname]) | ||
Puppet::Interface::Report.submit(report) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,36 @@ | ||
require 'puppet/interface/indirector' | ||
|
||
Puppet::Interface::Indirector.new(:catalog) do | ||
action(:apply) 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 | ||
|
||
action(:download) 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::Interface::Catalog.find(certname, facts_to_upload) | ||
end | ||
catalog = catalog.to_ral | ||
catalog.finalize | ||
catalog.retrieval_duration = retrieval_duration | ||
catalog.write_class_file | ||
catalog | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'puppet/interface' | ||
|
||
Puppet::Interface.new(:configurer) do | ||
action(:synchronize) do |certname| | ||
facts = Puppet::Interface::Facts.find(certname) | ||
|
||
catalog = Puppet::Interface::Catalog.download(certname, facts) | ||
|
||
report = Puppet::Interface::Catalog.apply(catalog) | ||
|
||
report | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
require 'puppet/interface/indirector' | ||
|
||
Puppet::Interface::Indirector.new(:report) do | ||
action(:submit) 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') | ||
require 'puppet/application/configurer' | ||
require 'puppet/indirector/catalog/rest' | ||
require 'puppet/indirector/report/rest' | ||
require 'tempfile' | ||
|
||
describe "Puppet::Application::Configurer" do | ||
it "should retrieve and apply a catalog and submit a report" do | ||
dirname = Dir.mktmpdir("puppetdir") | ||
Puppet[:vardir] = dirname | ||
Puppet[:confdir] = dirname | ||
Puppet[:certname] = "foo" | ||
@catalog = Puppet::Resource::Catalog.new | ||
@file = Puppet::Resource.new(:file, File.join(dirname, "tmp_dir_resource"), :parameters => {:ensure => :present}) | ||
@catalog.add_resource(@file) | ||
|
||
@report = Puppet::Transaction::Report.new("apply") | ||
Puppet::Transaction::Report.stubs(:new).returns(@report) | ||
|
||
Puppet::Resource::Catalog::Rest.any_instance.stubs(:find).returns(@catalog) | ||
@report.expects(:save) | ||
|
||
Puppet::Util::Log.stubs(:newdestination) | ||
|
||
Puppet::Application::Configurer.new.run | ||
|
||
@report.status.should == "changed" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') | ||
require 'puppet/interface/configurer' | ||
require 'puppet/indirector/catalog/rest' | ||
require 'tempfile' | ||
|
||
describe Puppet::Interface::Configurer do | ||
describe "#synchronize" do | ||
it "should retrieve and apply a catalog and return a report" do | ||
dirname = Dir.mktmpdir("puppetdir") | ||
Puppet[:vardir] = dirname | ||
Puppet[:confdir] = dirname | ||
@catalog = Puppet::Resource::Catalog.new | ||
@file = Puppet::Resource.new(:file, File.join(dirname, "tmp_dir_resource"), :parameters => {:ensure => :present}) | ||
@catalog.add_resource(@file) | ||
Puppet::Resource::Catalog::Rest.any_instance.stubs(:find).returns(@catalog) | ||
|
||
report = Puppet::Interface::Configurer.synchronize("foo") | ||
|
||
report.kind.should == "apply" | ||
report.status.should == "changed" | ||
end | ||
end | ||
end |