puppet_agent_mgr 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -56,14 +56,16 @@ module PuppetAgentMgr
56
56
  true
57
57
  end
58
58
 
59
- def create_common_puppet_cli(noop, tags, environment, server)
59
+ def create_common_puppet_cli(noop=nil, tags=[], environment=nil, server=nil, splay=nil, splaylimit=nil)
60
60
  opts = []
61
+ tags = [tags].flatten.compact
61
62
 
62
63
  (host, port) = server.to_s.split(":")
63
64
 
64
65
  raise("Invalid hostname '%s' specified" % host) if host && !(host =~ /\A(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])\Z/)
65
66
  raise("Invalid master port '%s' specified" % port) if port && !(port =~ /\A\d+\Z/)
66
67
  raise("Invalid environment '%s' specified" % environment) if environment && !validate_name(environment)
68
+ raise("Invalid splaylimit '%s' specified" % splaylimit) if splaylimit && !splaylimit.is_a?(Fixnum)
67
69
 
68
70
  unless tags.empty?
69
71
  [tags].flatten.each do |tag|
@@ -75,6 +77,9 @@ module PuppetAgentMgr
75
77
  opts << "--tags %s" % tags.join(",") if !tags.empty?
76
78
  end
77
79
 
80
+ opts << "--splay" if splay == true
81
+ opts << "--no-splay" if splay == false
82
+ opts << "--splaylimit %s" % splaylimit if splaylimit
78
83
  opts << "--noop" if noop
79
84
  opts << "--environment %s" % environment if environment
80
85
  opts << "--server %s" % host if host
@@ -91,11 +96,13 @@ module PuppetAgentMgr
91
96
  # :tags - an array of tags to limit the run to
92
97
  # :environment - the environment to run
93
98
  # :server - the puppet master to use, can be some.host or some.host:port
99
+ # :splay - enables or disables splay based on true/false
100
+ # :splaylimit - set the maximum splay time
94
101
  #
95
102
  # else a single background run will be attempted but this will fail if a idling
96
103
  # daemon is present and :signal_daemon was false
97
104
  def runonce!(options={})
98
- valid_options = [:noop, :signal_daemon, :foreground_run, :tags, :environment, :server]
105
+ valid_options = [:noop, :signal_daemon, :foreground_run, :tags, :environment, :server, :splay, :splaylimit]
99
106
 
100
107
  options.keys.each do |opt|
101
108
  raise("Unknown option %s specified" % opt) unless valid_options.include?(opt)
@@ -104,6 +111,8 @@ module PuppetAgentMgr
104
111
  raise "Puppet is currently applying a catalog, cannot run now" if applying?
105
112
  raise "Puppet is disabled, cannot run now" if disabled?
106
113
 
114
+ splay = options.fetch(:splay, nil)
115
+ splaylimit = options.fetch(:splaylimit, nil)
107
116
  noop = options.fetch(:noop, false)
108
117
  signal_daemon = options.fetch(:signal_daemon, true)
109
118
  foreground_run = options.fetch(:foreground_run, false)
@@ -111,7 +120,7 @@ module PuppetAgentMgr
111
120
  tags = [ options[:tags] ].flatten.compact
112
121
  server = options[:server]
113
122
 
114
- clioptions = create_common_puppet_cli(noop, tags, environment, server)
123
+ clioptions = create_common_puppet_cli(noop, tags, environment, server, splay, splaylimit)
115
124
 
116
125
  if idling? && signal_daemon && !clioptions.empty?
117
126
  raise "Cannot specify any custom puppet options when the daemon is running"
@@ -10,6 +10,14 @@ module PuppetAgentMgr::V3
10
10
 
11
11
  include PuppetAgentMgr::Common
12
12
 
13
+ def initialize
14
+ # there has to be a better way...
15
+ require 'puppet/util/run_mode'
16
+ Puppet.settings.preferred_run_mode = :agent
17
+ run_mode = Puppet::Util::RunMode[ Puppet.settings.preferred_run_mode ]
18
+ Puppet.settings.initialize_app_defaults(Puppet::Settings.app_defaults_for_run_mode(run_mode))
19
+ end
20
+
13
21
  # enables the puppet agent, it can now start applying catalogs again
14
22
  def enable!
15
23
  raise "Already enabled" if enabled?
@@ -1,3 +1,3 @@
1
1
  module PuppetAgentMgr
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet_agent_mgr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - R.I.Pienaar