diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-05-18 20:41:54 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-05-18 20:41:54 +0000 |
commit | b3ea53cd99df84a93fe2f093d2224e711f49e5dd (patch) | |
tree | 848e3b2bc03865709e4b6e38f1536ebec99ba8b0 /lib/puppet/server | |
parent | 93771b7935e544630c3416fda928a3820c615df2 (diff) | |
download | puppet-b3ea53cd99df84a93fe2f093d2224e711f49e5dd.tar.gz puppet-b3ea53cd99df84a93fe2f093d2224e711f49e5dd.tar.xz puppet-b3ea53cd99df84a93fe2f093d2224e711f49e5dd.zip |
Adding a lot of structure to puppet.rb to make it easier to manage multiple objects in a single process, including making it easy to add threads. Added some testing for all of that.
Also added a "runner" server, meant to be started within puppetd, so that clients can have runs triggered from a central host
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1212 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/server')
-rwxr-xr-x | lib/puppet/server/runner.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/puppet/server/runner.rb b/lib/puppet/server/runner.rb new file mode 100755 index 000000000..d53b6c9b1 --- /dev/null +++ b/lib/puppet/server/runner.rb @@ -0,0 +1,63 @@ +module Puppet +class Server + class MissingMasterError < RuntimeError # Cannot find the master client + end + # A simple server for triggering a new run on a Puppet client. + class Runner < Handler + @interface = XMLRPC::Service::Interface.new("puppetrunner") { |iface| + iface.add_method("string run(string, string)") + } + + # Run the client configuration right now, optionally specifying + # tags and whether to ignore schedules + def run(tags = [], ignoreschedules = false, bg = true, client = nil, clientip = nil) + # We need to retrieve the client + master = Puppet::Client::MasterClient.instance + + unless master + raise MissingMasterError, "Could not find the master client" + end + + if master.locked? + Puppet.notice "Could not trigger run; already running" + return "running" + end + + if tags == "" + tags = nil + end + + if ignoreschedules == "" + ignoreschedules == nil + end + + if client + msg = "%s(%s) triggered run" % [client, clientip] + if tags + msg += " with tags %s" % tags.join(", ") + end + + if ignoreschedules + msg += " without schedules" + end + + Puppet.notice msg + end + + # And then we need to tell it to run, with this extra info. + # By default, stick it in a thread + if bg + Puppet.newthread do + master.run(tags, ignoreschedules) + end + else + master.run(tags, ignoreschedules) + end + + return "success" + end + end +end +end + +# $Id$ |