diff options
| author | Jesse Wolfe <jes5199@gmail.com> | 2010-03-18 18:48:46 -0700 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | d8e1b272ec321d5f86558672252de60983751a15 (patch) | |
| tree | 45f4797b3512127b9f4c4400fb444f96bd3e80b9 /lib/puppet | |
| parent | 1603f7363728dc41f67cd189ca0dcbf074ec44b4 (diff) | |
| download | puppet-d8e1b272ec321d5f86558672252de60983751a15.tar.gz puppet-d8e1b272ec321d5f86558672252de60983751a15.tar.xz puppet-d8e1b272ec321d5f86558672252de60983751a15.zip | |
Feature #3394 REST runner, execution
puppetrun uses REST to trigger puppet runs.
Diffstat (limited to 'lib/puppet')
| -rw-r--r-- | lib/puppet/application/run.rb | 24 | ||||
| -rw-r--r-- | lib/puppet/indirector/run/local.rb | 8 | ||||
| -rw-r--r-- | lib/puppet/run.rb | 23 |
3 files changed, 40 insertions, 15 deletions
diff --git a/lib/puppet/application/run.rb b/lib/puppet/application/run.rb index f08fade8d..26ca362ff 100644 --- a/lib/puppet/application/run.rb +++ b/lib/puppet/application/run.rb @@ -112,14 +112,22 @@ Puppet::Application.new(:run) do next end end - client = Puppet::Network::Client.runner.new( - :Server => host, - :Port => Puppet[:puppetport] - ) + + require 'puppet/run' + Puppet::Run.indirection.terminus_class = :rest + port = Puppet[:puppetport] + url = ["https://#{host}:#{port}", "production", "run", host].join('/') print "Triggering %s\n" % host begin - result = client.run(@tags, options[:ignoreschedules] || false, options[:foreground] || false) + request = Puppet::Indirector::Request.new(:run, :save, url) # Yuck. + run_options = { + :tags => @tags, + :background => ! options[:foreground], + :ignoreschedules => options[:ignoreschedules] + } + run = Puppet::Run.new( run_options ).save( request ) + result = run.status rescue => detail puts detail.backtrace if Puppet[:trace] $stderr.puts "Host %s failed: %s\n" % [host, detail] @@ -183,12 +191,6 @@ Puppet::Application.new(:run) do exit(24) end - if @tags.empty? - @tags = "" - else - @tags = @tags.join(",") - end - @children = {} # If we get a signal, then kill all of our children and get out. diff --git a/lib/puppet/indirector/run/local.rb b/lib/puppet/indirector/run/local.rb new file mode 100644 index 000000000..5e8f349ee --- /dev/null +++ b/lib/puppet/indirector/run/local.rb @@ -0,0 +1,8 @@ +require 'puppet/run' +require 'puppet/indirector/code' + +class Puppet::Run::Local < Puppet::Indirector::Code + def save( request ) + request.instance.run + end +end diff --git a/lib/puppet/run.rb b/lib/puppet/run.rb index 1503f5d7f..20e21dc57 100644 --- a/lib/puppet/run.rb +++ b/lib/puppet/run.rb @@ -6,7 +6,7 @@ require 'puppet/indirector' # puppetrun to kick off agents remotely. class Puppet::Run extend Puppet::Indirector - indirects :runner, :terminus_class => :rest + indirects :run, :terminus_class => :local attr_reader :status, :background, :options @@ -26,7 +26,7 @@ class Puppet::Run valid_options = [:tags, :ignoreschedules] options.each do |key, value| - raise ArgumentError, "Runner does not accept %s" % key unless valid_options.include?(key) + raise ArgumentError, "Run does not accept %s" % key unless valid_options.include?(key) end @options = options @@ -36,7 +36,7 @@ class Puppet::Run msg = "" msg += "triggered run" % if options[:tags] - msg += " with tags %s" % options[:tags] + msg += " with tags #{options[:tags].inspect}" end if options[:ignoreschedules] @@ -49,7 +49,7 @@ class Puppet::Run def run if agent.running? @status = "running" - return + return self end log_run() @@ -61,5 +61,20 @@ class Puppet::Run end @status = "success" + + self + end + + def self.from_pson( pson ) + options = {} + pson.each do |key, value| + options[key.to_sym] = value + end + + new(options) + end + + def to_pson + @options.merge(:background => @background).to_pson end end |
