shadow_puppet 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/shadow_puppet/manifest.rb +57 -12
- metadata +2 -2
@@ -5,6 +5,7 @@ require 'active_support/core_ext/class/attribute_accessors'
|
|
5
5
|
require 'active_support/core_ext/array'
|
6
6
|
require 'active_support/inflector'
|
7
7
|
require 'active_support/core_ext/hash/indifferent_access'
|
8
|
+
require 'active_support/core_ext/hash/deep_merge'
|
8
9
|
require 'active_support/core_ext/class/inheritable_attributes'
|
9
10
|
require 'active_support/core_ext/duplicable'
|
10
11
|
|
@@ -84,12 +85,13 @@ module ShadowPuppet
|
|
84
85
|
class Manifest
|
85
86
|
|
86
87
|
class_inheritable_accessor :recipes
|
87
|
-
|
88
|
+
write_inheritable_attribute(:recipes, [])
|
88
89
|
attr_reader :puppet_resources
|
89
90
|
|
90
|
-
# Initialize a new instance of this manifest. This can take a
|
91
|
-
#
|
92
|
-
|
91
|
+
# Initialize a new instance of this manifest. This can take a
|
92
|
+
# config hash, which is immediately passed on to the configure
|
93
|
+
# method
|
94
|
+
def initialize(config = {})
|
93
95
|
unless Process.uid == 0
|
94
96
|
Puppet[:confdir] = File.expand_path("~/.puppet")
|
95
97
|
Puppet[:vardir] = File.expand_path("~/.puppet/var")
|
@@ -99,7 +101,7 @@ module ShadowPuppet
|
|
99
101
|
Puppet::Util::Log.newdestination(:console)
|
100
102
|
Puppet::Util::Log.level = :info
|
101
103
|
|
102
|
-
|
104
|
+
configure(config)
|
103
105
|
@executed = false
|
104
106
|
@puppet_resources = Hash.new do |hash, key|
|
105
107
|
hash[key] = {}
|
@@ -119,18 +121,61 @@ module ShadowPuppet
|
|
119
121
|
end
|
120
122
|
end
|
121
123
|
|
124
|
+
# A HashWithIndifferentAccess describing any configuration that has been
|
125
|
+
# performed on the class. Modify this hash by calling configure:
|
126
|
+
#
|
127
|
+
# class SampleManifest < ShadowPuppet::Manifest
|
128
|
+
# configure(:name => 'test')
|
129
|
+
# end
|
130
|
+
#
|
131
|
+
# >> SampleManifest.configuration
|
132
|
+
# => {"name" => 'test'}
|
133
|
+
#
|
134
|
+
# Subclasses of the Manifest class properly inherit the parent classes'
|
135
|
+
# configuration.
|
136
|
+
def self.configuration
|
137
|
+
read_inheritable_attribute(:configuration) || write_inheritable_attribute(:configuration, HashWithIndifferentAccess.new)
|
138
|
+
end
|
139
|
+
|
140
|
+
# Access to the configuration of the creating class.
|
141
|
+
def configuration
|
142
|
+
self.class.configuration
|
143
|
+
end
|
144
|
+
|
145
|
+
# Define configuration on this manifest. This is useful for storing things
|
146
|
+
# such as hostnames, password, or usernames that may change between
|
147
|
+
# different implementations of a shared manifest. Access this hash by
|
148
|
+
# calling configuration:
|
149
|
+
#
|
150
|
+
# class SampleManifest < ShadowPuppet::Manifest
|
151
|
+
# configure(:name => 'test')
|
152
|
+
# end
|
153
|
+
#
|
154
|
+
# >> SampleManifest.configuration
|
155
|
+
# => {"name" => 'test'}
|
156
|
+
#
|
157
|
+
# Subsequent calls to configure perform a <tt>deep_merge</tt> of the
|
158
|
+
# provided <tt>hash</tt> into the pre-existing configuration
|
159
|
+
def self.configure(hash)
|
160
|
+
write_inheritable_attribute(:configuration, configuration.deep_merge(hash))
|
161
|
+
end
|
162
|
+
class << self
|
163
|
+
alias_method :configuration=, :configure
|
164
|
+
end
|
165
|
+
|
166
|
+
# Define configuration on this manifest's creating class. This is useful
|
167
|
+
# for storing things such as hostnames, password, or usernames that may
|
168
|
+
# change between different implementations of a shared manifest.
|
169
|
+
def configure(hash)
|
170
|
+
self.class.configure(hash)
|
171
|
+
end
|
172
|
+
alias_method :configuration=, :configure
|
173
|
+
|
122
174
|
#An array of all methods defined for creation of Puppet Resources
|
123
175
|
def self.puppet_type_methods
|
124
176
|
Puppet::Type.eachtype { |t| t.name }.keys.map { |n| n.to_s }.sort.inspect
|
125
177
|
end
|
126
178
|
|
127
|
-
# A HashWithIndifferentAccess[http://api.rubyonrails.com/classes/HashWithIndifferentAccess.html]
|
128
|
-
# containing the options passed into the initialize method. Useful to pass
|
129
|
-
# things not already in Facter.
|
130
|
-
def options
|
131
|
-
@options
|
132
|
-
end
|
133
|
-
|
134
179
|
def name
|
135
180
|
@name ||= "#{self.class}##{self.object_id}"
|
136
181
|
end
|
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.1.
|
4
|
+
version: 0.1.5
|
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-02-
|
12
|
+
date: 2009-02-19 00:00:00 -05:00
|
13
13
|
default_executable: shadow_puppet
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|