Class: PoolParty::PoolPartyBaseClass
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#add_resource(ty, opts = {}, extra_opts = {}, &block) ⇒ Object
Add resource When we are looking to add a resource, we want to make sure the resources isn’t already added.
-
#add_service(serv) ⇒ Object
Add to the services pool for the manifest listing.
-
#add_to_parent_if_parent_exists_and_is_a_service ⇒ Object
Add the parent’s options to my own and add myself as a service if I am not a resource.
-
#get_local_resource(ty, k) ⇒ Object
-
#get_name_from_options_and_extra_options(opts = {}, extra_opts = {}) ⇒ Object
Try to extract the name from the options.
-
#get_resource(ty, n, opts = {}, &block) ⇒ Object
-
#handle_option_values(o) ⇒ Object
-
#in_local_resources?(ty, k) ⇒ Boolean
-
#initialize(opts = {}, extra_opts = {}, &block) ⇒ PoolPartyBaseClass
constructor
A new instance of PoolPartyBaseClass.
-
#inspect ⇒ Object
-
#is_a_resource? ⇒ Boolean
-
#is_plugin? ⇒ Boolean
-
#plugin_store ⇒ Object
Store the call and use of plugins into an array.
-
#resource(type = :file) ⇒ Object
-
#resources ⇒ Object
-
#run_in_context(o = {}, &block) ⇒ Object
Overloading the parent run_in_context.
-
#run_with_callbacks(o, &block) ⇒ Object
-
#search_in_known_locations(filepath, additional_search_paths = []) ⇒ Object
-
#store_in_local_resources(ty, obj) ⇒ Object
-
#to_hash ⇒ Object
-
#to_json ⇒ Object
included
#to_properties_hash
Constructor Details
#initialize(opts = {}, extra_opts = {}, &block) ⇒ PoolPartyBaseClass
Returns a new instance of PoolPartyBaseClass.
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 29
def initialize(opts={}, ={}, &block)
add_to_parent_if_parent_exists_and_is_a_service
@init_block = block
@base_name = get_name_from_options_and_extra_options(opts, )
@init_opts = (opts.is_a?(Hash) ? .merge(opts) : .merge(:name => @base_name))
run_in_context(init_opts, &block)
end
|
Instance Attribute Details
#init_opts ⇒ Object
Returns the value of attribute init_opts.
17
18
19
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 17
def init_opts
@init_opts
end
|
#ordered_resources ⇒ Object
157
158
159
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 157
def ordered_resources
@ordered_resources ||= []
end
|
Class Method Details
.add_has_and_does_not_have_methods_for(typ = :file) ⇒ Object
Adds two methods to the module Adds the method type:
has_
and
does_not_have_
for the type passed for instance add_has_and_does_not_have_methods_for(:file) gives you the methods has_file and does_not_have_file TODO: Refactor nicely to include other types that don’t accept ensure
180
181
182
183
184
185
186
187
188
189
190
191
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 180
def self.add_has_and_does_not_have_methods_for(typ=:file)
method_name = "__#{typ}"
ev=" def has_\#{typ}(opts={}, extra={}, &block)\n \#{method_name}({:ensures => :present}.merge(handle_option_values(opts).merge(extra)), &block)\n end\n def does_not_have_\#{typ}(opts={}, extra={}, &block)\n \#{method_name}({:ensures => :absent}.merge(handle_option_values(opts).merge(extra)), &block)\n end\n EOE\n PoolParty::PoolPartyBaseClass.module_eval ev, ($pool_specfile || \"\")\nend\n"
|
.add_resource_lookup_method(lookup_type = :file) ⇒ Object
193
194
195
196
197
198
199
200
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 193
def self.add_resource_lookup_method(lookup_type=:file)
ev=" def \#{lookup_type}s\n ordered_resources.select {|q| q if q.class.to_s =~ /\#{lookup_type.to_s.classify}/ }\n end\n EOE\n PoolParty::PoolPartyBaseClass.module_eval ev, ($pool_specfile || \"\")\nend\n"
|
Instance Method Details
#add_resource(ty, opts = {}, extra_opts = {}, &block) ⇒ Object
Add resource When we are looking to add a resource, we want to make sure the resources isn’t already added. This way we prevent duplicates as puppet can be finicky about duplicate resource definitions. We’ll look for the resource in either a local or global store If the resource appears in either, return that resource, we’ll just append to the resource config, otherwise instantiate a new resource of the type and store it into the global and local resource stores
A word about stores, the global store stores the entire list of stored resources. The local resource store is available on all clouds and plugins which stores the instance variable’s local resources.
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 107
def add_resource(ty, opts={}, ={}, &block)
temp_name = get_name_from_options_and_extra_options(opts, )
if res = get_resource(ty, temp_name, opts)
res
else
opts = (opts.is_a?(Hash) ? .merge(opts) : ).merge(:name => temp_name)
res = if (PoolParty::Resources::Resource.available_resources.include?(ty.to_s.camelize) ||
PoolParty::Resources::Resource.available_resources.include?("PoolParty::Resources::#{ty.to_s.camelize}".camelize.constantize))
"PoolParty::Resources::#{ty.to_s.camelize}".camelize.constantize.new(opts, &block)
else
"#{ty.to_s.camelize}".camelize.constantize.new(opts.merge(:name), &block)
end
res.after_create
store_in_local_resources(ty, res)
ordered_resources << res
res
end
end
|
#add_service(serv) ⇒ Object
Add to the services pool for the manifest listing
75
76
77
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 75
def add_service(serv)
ordered_resources << serv
end
|
#add_to_parent_if_parent_exists_and_is_a_service ⇒ Object
Add the parent’s options to my own and add myself as a service if I am not a resource
62
63
64
65
66
67
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 62
def add_to_parent_if_parent_exists_and_is_a_service
if parent && !parent.is_a?(PoolParty::Resources::Resource)
dsl_options.merge!(parent.dsl_options) if parent.is_a?(PoolParty::Pool::Pool)
parent.add_service(self) if parent.respond_to?(:add_service) && !is_a_resource?
end
end
|
#get_local_resource(ty, k) ⇒ Object
134
135
136
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 134
def get_local_resource(ty, k)
resource(ty).select {|r| r.name == k }.first
end
|
#get_name_from_options_and_extra_options(opts = {}, extra_opts = {}) ⇒ Object
Try to extract the name from the options
70
71
72
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 70
def get_name_from_options_and_extra_options(opts={}, ={})
opts.is_a?(Hash) ? (opts.has_key?(:name) ? opts[:name] : nil) : dsl_options[:name] = opts
end
|
#get_resource(ty, n, opts = {}, &block) ⇒ Object
138
139
140
141
142
143
144
145
146
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 138
def get_resource(ty, n, opts={}, &block)
if in_local_resources?(ty, n)
get_local_resource(ty, n)
elsif parent && parent != self
parent.get_resource(ty, n)
else
nil
end
end
|
#handle_option_values(o) ⇒ Object
202
203
204
205
206
207
208
209
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 202
def handle_option_values(o)
case o.class.to_s
when "String"
{:name => o}
else
o
end
end
|
#in_local_resources?(ty, k) ⇒ Boolean
131
132
133
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 131
def in_local_resources?(ty, k)
!resource(ty).select {|r| r.name == k }.empty? rescue false
end
|
79
80
81
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 79
def inspect
to_properties_hash.inspect
end
|
#is_a_resource? ⇒ Boolean
166
167
168
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 166
def is_a_resource?
false
end
|
#is_plugin? ⇒ Boolean
162
163
164
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 162
def is_plugin?
false
end
|
#plugin_store ⇒ Object
Store the call and use of plugins into an array
149
150
151
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 149
def plugin_store
@plugin_store ||= []
end
|
#resource(type = :file) ⇒ Object
153
154
155
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 153
def resource(type=:file)
resources[type.to_sym] ||= []
end
|
#resources ⇒ Object
91
92
93
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 91
def resources
@resources ||= OrderedHash.new
end
|
#run_in_context(o = {}, &block) ⇒ Object
Overloading the parent run_in_context
42
43
44
45
46
47
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 42
def run_in_context(o={}, &block)
context_stack.push self
set_vars_from_options(o)
instance_eval &block if block
context_stack.pop
end
|
#run_with_callbacks(o, &block) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 49
def run_with_callbacks(o, &block)
run_in_context(o) do
before_load(o, &block)
yield if block_given?
loaded(o, &block)
end
end
|
#search_in_known_locations(filepath, additional_search_paths = []) ⇒ Object
57
58
59
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 57
def search_in_known_locations(filepath, additional_search_paths=[])
find_file(filepath, [::File.dirname(pool_specfile)])
end
|
#store_in_local_resources(ty, obj) ⇒ Object
128
129
130
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 128
def store_in_local_resources(ty, obj)
resource(ty) << obj
end
|
83
84
85
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 83
def to_hash
to_properties_hash
end
|
87
88
89
|
# File 'lib/poolparty/poolparty/poolparty_base_class.rb', line 87
def to_json
to_hash.to_json
end
|