shadow_puppet 0.1.17 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/shadow_puppet +1 -2
- data/lib/shadow_puppet/core_ext.rb +20 -1
- data/lib/shadow_puppet/manifest.rb +59 -17
- data/lib/shadow_puppet.rb +0 -1
- metadata +2 -12
data/bin/shadow_puppet
CHANGED
@@ -88,8 +88,7 @@ begin
|
|
88
88
|
klass = File.basename(filename, ".rb")
|
89
89
|
require filename
|
90
90
|
manifest = klass.classify.constantize.new
|
91
|
-
execute
|
92
|
-
execute ? exit(0) : exit(1)
|
91
|
+
manifest.execute! && exit(0)
|
93
92
|
rescue Errno::EACCES
|
94
93
|
puts "Please run shadow_puppet as root"
|
95
94
|
rescue Exception => e
|
@@ -2,4 +2,23 @@ require 'active_support/core_ext/class/attribute_accessors'
|
|
2
2
|
require 'active_support/core_ext/array'
|
3
3
|
require 'active_support/inflector'
|
4
4
|
require 'active_support/core_ext/class/inheritable_attributes'
|
5
|
-
require 'active_support/core_ext/duplicable'
|
5
|
+
require 'active_support/core_ext/duplicable'
|
6
|
+
class Hash #:nodoc:
|
7
|
+
def deep_merge(other_hash)
|
8
|
+
self.merge(other_hash) do |key, oldval, newval|
|
9
|
+
oldval = oldval.to_hash if oldval.respond_to?(:to_hash)
|
10
|
+
newval = newval.to_hash if newval.respond_to?(:to_hash)
|
11
|
+
oldval.is_a?(Hash) && newval.is_a?(Hash) ? oldval.deep_merge(newval) : newval
|
12
|
+
end
|
13
|
+
end
|
14
|
+
def deep_merge!(other_hash)
|
15
|
+
replace(deep_merge(other_hash))
|
16
|
+
end
|
17
|
+
def deep_symbolize_keys
|
18
|
+
self.inject({}) { |result, (key, value)|
|
19
|
+
value = value.deep_symbolize_keys if value.is_a?(Hash)
|
20
|
+
result[(key.to_sym rescue key) || key] = value
|
21
|
+
result
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
@@ -76,6 +76,8 @@ module ShadowPuppet
|
|
76
76
|
class_inheritable_accessor :recipes
|
77
77
|
write_inheritable_attribute(:recipes, [])
|
78
78
|
attr_reader :puppet_resources
|
79
|
+
class_inheritable_accessor :__config__
|
80
|
+
write_inheritable_attribute(:__config__, Hash.new)
|
79
81
|
|
80
82
|
# Initialize a new instance of this manifest. This can take a
|
81
83
|
# config hash, which is immediately passed on to the configure
|
@@ -111,7 +113,7 @@ module ShadowPuppet
|
|
111
113
|
return nil if methods.nil? || methods == []
|
112
114
|
options = methods.extract_options!
|
113
115
|
methods.each do |meth|
|
114
|
-
options =
|
116
|
+
options = configuration[meth.to_sym] if options == {}
|
115
117
|
options ||= {}
|
116
118
|
recipes << [meth.to_sym, options]
|
117
119
|
end
|
@@ -125,15 +127,24 @@ module ShadowPuppet
|
|
125
127
|
# end
|
126
128
|
#
|
127
129
|
# >> SampleManifest.configuration
|
128
|
-
# => {
|
130
|
+
# => {:name => 'test'}
|
131
|
+
#
|
132
|
+
# All keys on this hash are coerced into symbols for ease of access.
|
129
133
|
#
|
130
134
|
# Subclasses of the Manifest class properly inherit the parent classes'
|
131
135
|
# configuration.
|
132
136
|
def self.configuration
|
133
|
-
|
137
|
+
__config__.deep_symbolize_keys
|
134
138
|
end
|
135
139
|
|
136
|
-
# Access to the configuration of the
|
140
|
+
# Access to the configuration of the class of this instance.
|
141
|
+
#
|
142
|
+
# class SampleManifest < ShadowPuppet::Manifest
|
143
|
+
# configure(:name => 'test')
|
144
|
+
# end
|
145
|
+
#
|
146
|
+
# @manifest = SampleManifest.new
|
147
|
+
# @manifest.configuration[:name] => "test"
|
137
148
|
def configuration
|
138
149
|
self.class.configuration
|
139
150
|
end
|
@@ -141,24 +152,32 @@ module ShadowPuppet
|
|
141
152
|
# Define configuration on this manifest. This is useful for storing things
|
142
153
|
# such as hostnames, password, or usernames that may change between
|
143
154
|
# different implementations of a shared manifest. Access this hash by
|
144
|
-
# calling configuration
|
155
|
+
# calling <tt>configuration</tt>:
|
145
156
|
#
|
146
157
|
# class SampleManifest < ShadowPuppet::Manifest
|
147
|
-
# configure(
|
158
|
+
# configure('name' => 'test')
|
148
159
|
# end
|
149
160
|
#
|
150
161
|
# >> SampleManifest.configuration
|
151
|
-
# => {
|
162
|
+
# => {:name => 'test'}
|
163
|
+
#
|
164
|
+
# All keys on this hash are coerced into symbols for ease of access.
|
152
165
|
#
|
153
|
-
# Subsequent calls to configure perform a deep_merge of the
|
154
|
-
#
|
166
|
+
# Subsequent calls to configure perform a deep_merge of the provided
|
167
|
+
# <tt>hash</tt> into the pre-existing configuration.
|
155
168
|
def self.configure(hash)
|
156
|
-
|
169
|
+
__config__.deep_merge!(hash)
|
157
170
|
end
|
158
171
|
|
159
|
-
#
|
160
|
-
#
|
161
|
-
#
|
172
|
+
# Update the configuration of this manifest instance's class.
|
173
|
+
#
|
174
|
+
# class SampleManifest < ShadowPuppet::Manifest
|
175
|
+
# configure({})
|
176
|
+
# end
|
177
|
+
#
|
178
|
+
# @manifest = SampleManifest.new
|
179
|
+
# @manifest.configure(:name => "test")
|
180
|
+
# @manifest.configuration[:name] => "test"
|
162
181
|
def configure(hash)
|
163
182
|
self.class.configure(hash)
|
164
183
|
end
|
@@ -201,11 +220,34 @@ module ShadowPuppet
|
|
201
220
|
true
|
202
221
|
end
|
203
222
|
|
204
|
-
|
205
|
-
|
206
|
-
|
223
|
+
def missing_recipes
|
224
|
+
missing = self.class.recipes.each do |meth,args|
|
225
|
+
!respond_to?(meth)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
# Execute this manifest, applying all resources defined. Execute returns
|
230
|
+
# true if successfull, and false if unsucessfull. By default, this
|
231
|
+
# will only execute a manifest that has not already been executed?.
|
232
|
+
# The +force+ argument, if true, removes this check.
|
207
233
|
def execute(force=false)
|
208
|
-
return false
|
234
|
+
return false if executed? && !force
|
235
|
+
evaluate_recipes
|
236
|
+
apply
|
237
|
+
rescue Exception => e
|
238
|
+
false
|
239
|
+
else
|
240
|
+
true
|
241
|
+
ensure
|
242
|
+
@executed = true
|
243
|
+
end
|
244
|
+
|
245
|
+
# Execute this manifest, applying all resources defined. Execute returns
|
246
|
+
# true if successfull, and raises an exception if not. By default, this
|
247
|
+
# will only execute a manifest that has not already been executed?.
|
248
|
+
# The +force+ argument, if true, removes this check.
|
249
|
+
def execute!(force=false)
|
250
|
+
return false if executed? && !force
|
209
251
|
evaluate_recipes
|
210
252
|
apply
|
211
253
|
rescue Exception => e
|
data/lib/shadow_puppet.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shadow_puppet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesse Newland
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-12 00:00:00 -04:00
|
13
13
|
default_executable: shadow_puppet
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -62,16 +62,6 @@ dependencies:
|
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: 2.0.0
|
64
64
|
version:
|
65
|
-
- !ruby/object:Gem::Dependency
|
66
|
-
name: configatron
|
67
|
-
type: :runtime
|
68
|
-
version_requirement:
|
69
|
-
version_requirements: !ruby/object:Gem::Requirement
|
70
|
-
requirements:
|
71
|
-
- - ">="
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
version: 2.2.2
|
74
|
-
version:
|
75
65
|
description: A Ruby Puppet DSL
|
76
66
|
email:
|
77
67
|
- jesse@railsmachine.com
|