auser-poolparty 0.1.2 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. data/History.txt +22 -0
  2. data/License.txt +20 -0
  3. data/README.txt +52 -0
  4. data/Rakefile +4 -109
  5. data/bin/cloud +31 -0
  6. data/bin/cloud-add-keypair +23 -0
  7. data/bin/cloud-configure +35 -0
  8. data/bin/cloud-contract +27 -0
  9. data/bin/cloud-expand +27 -0
  10. data/bin/cloud-list +32 -0
  11. data/bin/cloud-maintain +36 -0
  12. data/bin/cloud-provision +30 -0
  13. data/bin/cloud-reconfigure +24 -0
  14. data/bin/cloud-ssh +18 -0
  15. data/bin/cloud-start +29 -0
  16. data/bin/pool +23 -75
  17. data/bin/pool-console +12 -0
  18. data/bin/pool-describe +9 -0
  19. data/bin/pool-list +28 -0
  20. data/bin/pool-provision +34 -0
  21. data/bin/pool-spec +17 -0
  22. data/bin/pool-start +32 -0
  23. data/examples/basic.rb +20 -0
  24. data/examples/plugin_without_plugin_directory.rb +13 -0
  25. data/examples/poolparty.rb +12 -0
  26. data/examples/with_apache_plugin.rb +22 -0
  27. data/generators/poolspec/USAGE +5 -0
  28. data/generators/poolspec/poolspec_generator.rb +65 -0
  29. data/generators/poolspec/templates/pool_spec_template.erb +9 -0
  30. data/lib/erlang/eb_server.erl +27 -0
  31. data/lib/poolparty.rb +40 -116
  32. data/lib/poolparty/base_packages/haproxy.rb +41 -0
  33. data/lib/poolparty/base_packages/heartbeat.rb +43 -0
  34. data/lib/poolparty/base_packages/poolparty.rb +18 -0
  35. data/lib/poolparty/base_packages/ruby.rb +27 -0
  36. data/lib/poolparty/core/array.rb +24 -0
  37. data/lib/{core → poolparty/core}/exception.rb +0 -0
  38. data/lib/{core → poolparty/core}/float.rb +0 -0
  39. data/lib/poolparty/core/hash.rb +29 -0
  40. data/lib/poolparty/core/kernel.rb +34 -0
  41. data/lib/{core → poolparty/core}/module.rb +18 -0
  42. data/lib/poolparty/core/my_open_struct.rb +18 -0
  43. data/lib/poolparty/core/object.rb +54 -0
  44. data/lib/poolparty/core/proc.rb +2 -0
  45. data/lib/poolparty/core/string.rb +72 -0
  46. data/lib/poolparty/core/symbol.rb +8 -0
  47. data/lib/{core → poolparty/core}/time.rb +15 -0
  48. data/lib/poolparty/exceptions/RemoteException.rb +12 -0
  49. data/lib/poolparty/exceptions/ResourceException.rb +7 -0
  50. data/lib/poolparty/exceptions/RuntimeException.rb +7 -0
  51. data/lib/poolparty/exceptions/SpecException.rb +7 -0
  52. data/lib/poolparty/exceptions/TemplateNotFound.rb +7 -0
  53. data/lib/poolparty/helpers/binary.rb +30 -0
  54. data/lib/poolparty/helpers/console.rb +30 -0
  55. data/lib/poolparty/helpers/display.rb +25 -0
  56. data/lib/poolparty/helpers/optioner.rb +61 -0
  57. data/lib/poolparty/helpers/provisioner_base.rb +226 -0
  58. data/lib/poolparty/helpers/provisioners/master.rb +120 -0
  59. data/lib/poolparty/helpers/provisioners/slave.rb +52 -0
  60. data/lib/poolparty/modules/cloud_resourcer.rb +72 -0
  61. data/lib/poolparty/modules/configurable.rb +34 -0
  62. data/lib/poolparty/modules/definable_resource.rb +59 -0
  63. data/lib/poolparty/modules/file_writer.rb +55 -0
  64. data/lib/poolparty/modules/method_missing_sugar.rb +17 -0
  65. data/lib/poolparty/modules/output.rb +13 -0
  66. data/lib/poolparty/modules/pretty_printer.rb +38 -0
  67. data/lib/{core/string.rb → poolparty/modules/s3_string.rb} +5 -29
  68. data/lib/{modules → poolparty/modules}/safe_instance.rb +0 -0
  69. data/lib/poolparty/monitors/base_monitor.rb +16 -0
  70. data/lib/poolparty/net/remote.rb +35 -0
  71. data/lib/poolparty/net/remote_bases/ec2.rb +145 -0
  72. data/lib/poolparty/net/remote_instance.rb +68 -0
  73. data/lib/poolparty/net/remoter.rb +209 -0
  74. data/lib/poolparty/net/remoter_base.rb +117 -0
  75. data/lib/poolparty/plugins/gem_package.rb +39 -0
  76. data/lib/poolparty/plugins/line.rb +76 -0
  77. data/lib/poolparty/plugins/svn.rb +48 -0
  78. data/lib/poolparty/pool/base.rb +74 -0
  79. data/lib/poolparty/pool/cloud.rb +132 -0
  80. data/lib/poolparty/pool/custom_resource.rb +61 -0
  81. data/lib/poolparty/pool/loggable.rb +29 -0
  82. data/lib/poolparty/pool/plugin.rb +42 -0
  83. data/lib/poolparty/pool/plugin_model.rb +48 -0
  84. data/lib/poolparty/pool/pool.rb +55 -0
  85. data/lib/poolparty/pool/resource.rb +235 -0
  86. data/lib/poolparty/pool/resources/class_package.rb +60 -0
  87. data/lib/poolparty/pool/resources/cron.rb +14 -0
  88. data/lib/poolparty/pool/resources/directory.rb +23 -0
  89. data/lib/poolparty/pool/resources/exec.rb +26 -0
  90. data/lib/poolparty/pool/resources/file.rb +23 -0
  91. data/lib/poolparty/pool/resources/gem.rb +14 -0
  92. data/lib/poolparty/pool/resources/host.rb +14 -0
  93. data/lib/poolparty/pool/resources/package.rb +14 -0
  94. data/lib/poolparty/pool/resources/remote_file.rb +20 -0
  95. data/lib/poolparty/pool/resources/service.rb +21 -0
  96. data/lib/poolparty/pool/resources/sshkey.rb +19 -0
  97. data/lib/poolparty/pool/resources/variable.rb +27 -0
  98. data/lib/poolparty/pool/script.rb +21 -0
  99. data/{config/heartbeat_authkeys.conf → lib/poolparty/templates/authkeys} +0 -0
  100. data/lib/poolparty/templates/cib.xml +1 -0
  101. data/lib/poolparty/templates/fileserver.conf +4 -0
  102. data/{config/heartbeat.conf → lib/poolparty/templates/ha.cf} +3 -1
  103. data/{config → lib/poolparty/templates}/haproxy.conf +13 -6
  104. data/lib/poolparty/templates/namespaceauth.conf +19 -0
  105. data/lib/poolparty/templates/puppet.conf +13 -0
  106. data/lib/poolparty/version.rb +9 -0
  107. data/lib/poolpartycl.rb +3 -0
  108. data/script/destroy +14 -0
  109. data/script/generate +14 -0
  110. data/script/txt2html +82 -0
  111. data/{lib/poolparty/tasks → tasks}/cloud.rake +1 -1
  112. data/tasks/deployment.rake +34 -0
  113. data/tasks/development.rake +78 -0
  114. data/{lib/poolparty/tasks → tasks}/ec2.rake +1 -1
  115. data/tasks/environment.rake +7 -0
  116. data/{lib/poolparty/tasks → tasks}/instance.rake +0 -0
  117. data/{lib/poolparty/tasks → tasks}/server.rake +0 -0
  118. data/tasks/spec.rake +17 -0
  119. data/tasks/website.rake +17 -0
  120. metadata +154 -249
  121. data/CHANGELOG +0 -23
  122. data/LICENSE +0 -22
  123. data/README +0 -139
  124. data/assets/clouds.png +0 -0
  125. data/bin/instance +0 -68
  126. data/bin/poolnotify +0 -34
  127. data/config/cloud_master_takeover +0 -17
  128. data/config/create_proxy_ami.sh +0 -582
  129. data/config/installers/ubuntu_install.sh +0 -77
  130. data/config/monit.conf +0 -9
  131. data/config/monit/haproxy.monit.conf +0 -8
  132. data/config/monit/nginx.monit.conf +0 -0
  133. data/config/nginx.conf +0 -24
  134. data/config/reconfigure_instances_script.sh +0 -37
  135. data/config/sample-config.yml +0 -23
  136. data/config/scp_instances_script.sh +0 -12
  137. data/lib/core/array.rb +0 -16
  138. data/lib/core/hash.rb +0 -11
  139. data/lib/core/kernel.rb +0 -12
  140. data/lib/core/object.rb +0 -21
  141. data/lib/core/proc.rb +0 -15
  142. data/lib/helpers/plugin_spec_helper.rb +0 -58
  143. data/lib/modules/callback.rb +0 -133
  144. data/lib/modules/ec2_wrapper.rb +0 -108
  145. data/lib/modules/file_writer.rb +0 -38
  146. data/lib/modules/sprinkle_overrides.rb +0 -27
  147. data/lib/modules/vlad_override.rb +0 -83
  148. data/lib/poolparty/application.rb +0 -199
  149. data/lib/poolparty/init.rb +0 -6
  150. data/lib/poolparty/master.rb +0 -492
  151. data/lib/poolparty/monitors.rb +0 -11
  152. data/lib/poolparty/monitors/cpu.rb +0 -23
  153. data/lib/poolparty/monitors/memory.rb +0 -33
  154. data/lib/poolparty/monitors/web.rb +0 -29
  155. data/lib/poolparty/optioner.rb +0 -20
  156. data/lib/poolparty/plugin.rb +0 -78
  157. data/lib/poolparty/provider.rb +0 -104
  158. data/lib/poolparty/provider/essential.rb +0 -6
  159. data/lib/poolparty/provider/git.rb +0 -8
  160. data/lib/poolparty/provider/haproxy.rb +0 -9
  161. data/lib/poolparty/provider/heartbeat.rb +0 -6
  162. data/lib/poolparty/provider/rsync.rb +0 -8
  163. data/lib/poolparty/provider/ruby.rb +0 -65
  164. data/lib/poolparty/provider/s3fuse.rb +0 -22
  165. data/lib/poolparty/remote_instance.rb +0 -250
  166. data/lib/poolparty/remoter.rb +0 -171
  167. data/lib/poolparty/remoting.rb +0 -137
  168. data/lib/poolparty/scheduler.rb +0 -93
  169. data/lib/poolparty/tasks.rb +0 -47
  170. data/lib/poolparty/tasks/development.rake +0 -78
  171. data/lib/poolparty/tasks/plugins.rake +0 -30
  172. data/lib/poolparty/thread_pool.rb +0 -94
  173. data/lib/s3/s3_object_store_folders.rb +0 -44
  174. data/poolparty.gemspec +0 -71
  175. data/spec/files/describe_response +0 -37
  176. data/spec/files/multi_describe_response +0 -69
  177. data/spec/files/remote_desc_response +0 -37
  178. data/spec/helpers/ec2_mock.rb +0 -57
  179. data/spec/lib/core/core_spec.rb +0 -26
  180. data/spec/lib/core/kernel_spec.rb +0 -24
  181. data/spec/lib/core/string_spec.rb +0 -28
  182. data/spec/lib/modules/callback_spec.rb +0 -213
  183. data/spec/lib/modules/file_writer_spec.rb +0 -74
  184. data/spec/lib/poolparty/application_spec.rb +0 -135
  185. data/spec/lib/poolparty/ec2_wrapper_spec.rb +0 -110
  186. data/spec/lib/poolparty/master_spec.rb +0 -479
  187. data/spec/lib/poolparty/optioner_spec.rb +0 -34
  188. data/spec/lib/poolparty/plugin_spec.rb +0 -115
  189. data/spec/lib/poolparty/poolparty_spec.rb +0 -60
  190. data/spec/lib/poolparty/provider_spec.rb +0 -74
  191. data/spec/lib/poolparty/remote_instance_spec.rb +0 -178
  192. data/spec/lib/poolparty/remoter_spec.rb +0 -72
  193. data/spec/lib/poolparty/remoting_spec.rb +0 -148
  194. data/spec/lib/poolparty/scheduler_spec.rb +0 -70
  195. data/spec/monitors/cpu_monitor_spec.rb +0 -39
  196. data/spec/monitors/memory_spec.rb +0 -51
  197. data/spec/monitors/misc_monitor_spec.rb +0 -51
  198. data/spec/monitors/web_spec.rb +0 -40
  199. data/spec/spec_helper.rb +0 -53
@@ -0,0 +1,61 @@
1
+ require File.dirname(__FILE__) + "/resource"
2
+
3
+ module PoolParty
4
+ def available_custom_resources
5
+ $available_custom_resources ||= []
6
+ end
7
+ module DefinableFact
8
+ def define_fact(name, string="")
9
+
10
+ end
11
+ end
12
+
13
+ module Resources
14
+
15
+ def call_function(str, opts={}, &block)
16
+ returning PoolParty::Resources::CallFunction.new(str, opts, &block) do |o|
17
+ resource(:call_function) << o
18
+ end
19
+ end
20
+
21
+ # Resources for function call
22
+ class CallFunction < Resource
23
+ def initialize(str="", opts={}, &block)
24
+ @str = str
25
+ super(opts, &block)
26
+ end
27
+ def to_string(prev="")
28
+ returning Array.new do |arr|
29
+ arr << "#{prev}#{@str}"
30
+ end.join("\n")
31
+ end
32
+ end
33
+
34
+ class CustomResource < Resource
35
+ def initialize(name=:custom_method, opts={}, &block)
36
+ @name = name
37
+ super(opts, &block)
38
+ end
39
+
40
+ def self.inherited(subclass)
41
+ PoolParty::Resources.available_custom_resources << subclass
42
+ super(subclass)
43
+ end
44
+
45
+ def to_string(prev="")
46
+ returning Array.new do |output|
47
+ output << "#{prev} # Custom Functions\n"
48
+ output << self.class.custom_functions_to_string(prev)
49
+ end.join("\n")
50
+ end
51
+ end
52
+
53
+ # Stub methods
54
+ # TODO: Find a better solution
55
+ def custom_function(*args, &block)
56
+ end
57
+ def self.custom_function(*args, &block)
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,29 @@
1
+ class Loggable
2
+ def initialize
3
+ Logging.init :debug, :info, :warn, :error, :fatal
4
+
5
+ self.class.loggers << file_logger
6
+ file_logger.level = :warn
7
+
8
+ self.class.loggers << stdout_logger
9
+ stdout_logger.level = :info
10
+ end
11
+ def file_logger
12
+ @file_logger ||= Logging.logger( ::File.join(Base.pool_logger_location, "pool_log.log"), logging_opts )
13
+ end
14
+ def stdout_logger
15
+ @stdout_logger ||= Logging.logger(STDOUT, logging_opts.merge({:pattern => "%m\n"}))
16
+ end
17
+ def logging_opts
18
+ {:pattern => "[%d] %-l : %m\n",
19
+ :date_pattern => "%Y-%m-%d %H:%M:%S.%s"}
20
+ end
21
+ %w(info warn debug notice).each do |meth|
22
+ define_method(meth.to_sym) do |*args|
23
+ self.class.loggers.each {|l| l.send meth.to_sym, args}
24
+ end
25
+ end
26
+ def self.loggers
27
+ @loggers ||= []
28
+ end
29
+ end
@@ -0,0 +1,42 @@
1
+ module PoolParty
2
+
3
+ module Plugin
4
+
5
+ class Plugin
6
+ include Configurable
7
+ include CloudResourcer
8
+ include Resources
9
+ extend Resources
10
+
11
+ attr_accessor :parent
12
+ class_inheritable_accessor :name
13
+
14
+ default_options({})
15
+
16
+ def initialize(parent=self, opts={}, &block)
17
+ set_parent(parent)
18
+ block ? instance_eval(&block) : enable
19
+ end
20
+
21
+ # Overwrite this method
22
+ def enable
23
+ end
24
+
25
+ def method_missing(m, *args, &block)
26
+ if block_given?
27
+ (args[0].class == self.class) ? args[0].instance_eval(&block) : super
28
+ elsif parent && parent.respond_to?(m)
29
+ parent.send m, *args, &block
30
+ else
31
+ get_from_options(m, *args)
32
+ end
33
+ end
34
+
35
+ def get_from_options(m, *args)
36
+ args.empty? ? options[m] : options[m] = args[0]
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,48 @@
1
+ require File.join(File.dirname(__FILE__), "resource")
2
+
3
+ module PoolParty
4
+ module PluginModel
5
+
6
+ def plugin(name=:plugin, cloud=nil, &block)
7
+ plugins.has_key?(name) ? plugins[name] : (plugins[name] = PluginModel.new(name, cloud, &block))
8
+ end
9
+ alias_method :register_plugin, :plugin
10
+
11
+ def plugins
12
+ $plugins ||= {}
13
+ end
14
+
15
+ class PluginModel
16
+ attr_accessor :name, :klass
17
+ attr_reader :parent
18
+ include MethodMissingSugar
19
+ include Configurable
20
+ include PrettyPrinter
21
+
22
+ def initialize(name,cld,&block)
23
+ @name = name
24
+ @parent = cld
25
+ class_string_name = "#{name}"
26
+
27
+ # Create the class to evaluate the plugin on the implemented call
28
+ klass = class_string_name.class_constant(PoolParty::Plugin::Plugin)
29
+ klass.extend PoolParty::Resources
30
+ klass.send :include, PoolParty::Resources
31
+
32
+ # Create the block inside the instantiated plugin
33
+ klass.module_eval &block if block
34
+
35
+ # Store the name of the class for pretty printing later
36
+ klass.name = name
37
+ # Add the plugin definition to the cloud as an instance method
38
+ Cloud::Cloud.module_eval <<-EOE
39
+ def #{name}(parent=self, &block)
40
+ @#{class_string_name.downcase} ||= #{class_string_name.class_constant}.new(parent, &block)
41
+ end
42
+ EOE
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,55 @@
1
+ module PoolParty
2
+ module Pool
3
+
4
+ def pool(name=:main, &block)
5
+ pools.has_key?(name) ? pools[name] : (pools[name] = Pool.new(name, &block))
6
+ end
7
+
8
+ def pools
9
+ $pools ||= {}
10
+ end
11
+
12
+ def with_pool(pool, opts={}, &block)
13
+ pool.options.merge!(opts)
14
+ pool.instance_eval &block if block
15
+ end
16
+
17
+ def reset!
18
+ $pools = $clouds = $plugins = nil
19
+ end
20
+
21
+ class Pool
22
+ attr_accessor :name
23
+ include PoolParty::Cloud
24
+ include MethodMissingSugar
25
+ # include PluginModel
26
+ include Configurable
27
+ include PrettyPrinter
28
+ include CloudResourcer
29
+ include Remote
30
+
31
+ default_options({
32
+ :access_key => Base.access_key,
33
+ :secret_access_key => Base.secret_access_key
34
+ })
35
+
36
+ def initialize(name,&block)
37
+ @name = name
38
+ instance_eval &block if block
39
+ end
40
+
41
+ def plugin_directory(*args)
42
+ args.each {|arg| Dir["#{arg}/*.rb"].each {|f| load f }}
43
+ end
44
+
45
+ # This is where the entire process starts
46
+ def inflate
47
+ end
48
+ end
49
+
50
+ # Helpers
51
+ def remove_pool(name)
52
+ pools.delete(name) if pools.has_key?(name)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,235 @@
1
+ =begin rdoc
2
+ The Container
3
+
4
+ Container holds the various features for the final compilations
5
+ for each pool.
6
+
7
+ Most of the Resources will not need to create their own
8
+ =end
9
+ module PoolParty
10
+ module Resources
11
+
12
+ def resources
13
+ @resources ||= {}
14
+ end
15
+
16
+ def resource(type=:file)
17
+ resources[type] ||= []
18
+ end
19
+
20
+ def add_resource(type, opts={}, &block)
21
+ returning "PoolParty::Resources::#{type.to_s.camelize}".classify.constantize.new(opts, &block) do |o|
22
+ resource(type) << o
23
+ end
24
+ end
25
+
26
+ def get_resource(type, name)
27
+ resource(type).select {|resource| resource.name == name }.first
28
+ end
29
+
30
+ #:nodoc:
31
+ def reset_resources!
32
+ @resources = nil
33
+ end
34
+
35
+ def resources_string(prev="")
36
+ returning Array.new do |output|
37
+ output << resources_string_from_resources(resources)
38
+ end.join("\n")
39
+ end
40
+
41
+ def custom_file(path, str)
42
+ write_to_file_in_storage_directory(path, str)
43
+ end
44
+
45
+ class Resource
46
+ include CloudResourcer
47
+ include Configurable
48
+
49
+ extend PoolParty::Resources
50
+ include PoolParty::Resources
51
+
52
+ def self.inherited(subclass)
53
+ subclass = subclass.to_s.split("::")[-1] if subclass.to_s.index("::")
54
+ lowercase_class_name = subclass.to_s.downcase
55
+
56
+ # Add add resource method to the Resources module
57
+ unless PoolParty::Resources.respond_to?(lowercase_class_name.to_sym)
58
+ method =<<-EOE
59
+ def #{lowercase_class_name}(opts={}, &blk)
60
+ add_resource(:#{lowercase_class_name}, opts, &blk)
61
+ end
62
+ EOE
63
+ PoolParty::Resources.module_eval method
64
+ PoolParty::Resources.add_has_and_does_not_have_methods_for(lowercase_class_name.to_sym)
65
+
66
+ available_resources << subclass
67
+ end
68
+ end
69
+
70
+ def self.available_resources
71
+ @available_resources ||= []
72
+ end
73
+
74
+ def self.available_resource_methods
75
+ available_resources.map {|a| a.my_methods }
76
+ end
77
+
78
+ # This is set in order of descending precedence
79
+ # The options are overwritten from the bottom up
80
+ # and the resource will use those as the values
81
+ # Then it takes the value of the block and sets whatever is sent there as
82
+ # the options
83
+ # Finally, it uses the parent's options as the lowest priority
84
+ def initialize(opts={}, parent=self, &block)
85
+ # Take the options of the parents
86
+ set_parent(parent) if parent
87
+ set_vars_from_options(opts) unless opts.empty?
88
+ self.instance_eval &block if block
89
+ loaded
90
+ end
91
+
92
+ # Stub, so you can create virtual resources
93
+ def loaded
94
+ end
95
+
96
+ # DSL Overriders
97
+ # Overrides for syntax
98
+ # Allows us to send require to require a resource
99
+ def requires(str="")
100
+ options.merge!(:require => str)
101
+ end
102
+ def ensures(str="running")
103
+ str == "absent" ? is_absent : is_present
104
+ end
105
+ # Allows us to send an ensure to ensure the presence of a resource
106
+ def is_present(*args)
107
+ options.merge!(:ensure => present)
108
+ end
109
+ # Ensures that what we are sending is absent
110
+ def is_absent(*args)
111
+ options.merge!(:ensure => absent)
112
+ end
113
+ # Alias for unless
114
+ def ifnot(str="")
115
+ options.merge!(:unless => str)
116
+ end
117
+ def present
118
+ "present"
119
+ end
120
+ def absent
121
+ "absent"
122
+ end
123
+
124
+ # Give us a template to work with on the resource
125
+ # Make sure this template is moved to the tmp directory as well
126
+ def template(file, opts={})
127
+ raise TemplateNotFound.new("no template given") unless file
128
+ raise TemplateNotFound.new("template cannot be found #{file}") unless ::File.file?(file)
129
+ unless opts[:just_copy]
130
+ options.merge!({:content => "template(\"#{::File.basename(file)}\")"})
131
+ options.delete(:source) if options.has_key?(:source)
132
+ copy_template_to_storage_directory(file)
133
+ else
134
+ copy_file_to_storage_directory(file)
135
+ end
136
+ end
137
+ # This way we can subclass resources without worry
138
+ def class_type_name
139
+ self.class.to_s.top_level_class
140
+ end
141
+ def self.custom_function(str)
142
+ custom_functions << str
143
+ end
144
+
145
+ def self.custom_function(str)
146
+ custom_functions << str
147
+ end
148
+ def self.custom_functions
149
+ @custom_functions ||= []
150
+ end
151
+ def custom_function(str)
152
+ self.class.custom_functions << str
153
+ end
154
+
155
+ def self.custom_functions_to_string(prev="")
156
+ returning Array.new do |output|
157
+ PoolParty::Resources.available_custom_resources.each do |resource|
158
+ resource.custom_functions.each do |func|
159
+ output << "#{prev*2}#{func}"
160
+ end
161
+ end
162
+ end.join("\n")
163
+ end
164
+ # Some things in puppet aren't allowed, so let's override them here
165
+ def disallowed_options
166
+ []
167
+ end
168
+ def key
169
+ name
170
+ end
171
+ def virtual_resource?
172
+ false
173
+ end
174
+ # We want to gather the options, but if the option sent is nil
175
+ # then we want to override the option value by sending the key as
176
+ # a method so that we can override this if necessary.
177
+ # Only runs on objects that have options defined, otherwise
178
+ # it returns an empty hash
179
+ def get_modified_options
180
+ if options
181
+ opts = options.inject({}) do |sum,h|
182
+ sum.merge!({h[0].to_sym => ((h[1].nil?) ? self.send(h[0].to_sym) : h[1]) })
183
+ end
184
+ else
185
+ opts = {}
186
+ end
187
+ opts.reject {|k,v| disallowed_options.include?(k) }
188
+ end
189
+
190
+ # Generic to_s
191
+ # Most Resources won't need to extend this
192
+ def to_string(prev="")
193
+ opts = get_modified_options
194
+ returning Array.new do |output|
195
+
196
+ if resources && !resources.empty?
197
+ @cp = classpackage_with_self(self)
198
+ output << @cp.to_string
199
+ output << "include #{@cp.name.sanitize}"
200
+ end
201
+
202
+ unless virtual_resource?
203
+ output << "#{prev}#{class_type_name} {"
204
+ output << "#{prev}\"#{self.key}\":"
205
+ output << opts.flush_out("#{prev*2}").join(",\n")
206
+ output << "#{prev}}"
207
+ end
208
+
209
+ end.join("\n")
210
+ end
211
+ end
212
+
213
+ # Adds two methods to the module
214
+ # Adds the method type:
215
+ # has_
216
+ # and
217
+ # does_not_have_
218
+ # for the type passed
219
+ # for instance
220
+ # add_has_and_does_not_have_methods_for(:file)
221
+ # gives you the methods has_file and does_not_have_file
222
+ # TODO: Refactor nicely to include other types that don't accept ensure
223
+ def self.add_has_and_does_not_have_methods_for(type=:file)
224
+ module_eval <<-EOE
225
+ def has_#{type}(opts={}, &block)
226
+ #{type}(#{type == :exec ? "opts" : "{:is_present => ''}.merge(opts)"}, &block)
227
+ end
228
+ def does_not_have_#{type}(opts={}, &block)
229
+ #{type}(#{type == :exec ? "opts" : "{:is_absent => ''}.merge(opts)"}, &block)
230
+ end
231
+ EOE
232
+ end
233
+
234
+ end
235
+ end