poolparty 0.0.4 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +25 -0
- data/License.txt +20 -0
- data/Manifest.txt +203 -0
- data/PostInstall.txt +18 -0
- data/README.txt +21 -82
- data/Rakefile +25 -18
- data/bin/cloud +31 -0
- data/bin/cloud-add-keypair +23 -0
- data/bin/cloud-configure +31 -0
- data/bin/cloud-contract +27 -0
- data/bin/cloud-expand +27 -0
- data/bin/cloud-list +32 -0
- data/bin/cloud-maintain +36 -0
- data/bin/cloud-osxcopy +22 -0
- data/bin/cloud-provision +31 -0
- data/bin/cloud-refresh +26 -0
- data/bin/cloud-ssh +18 -0
- data/bin/cloud-start +32 -0
- data/bin/cloud-terminate +23 -0
- data/bin/pool +25 -27
- data/bin/pool-console +12 -0
- data/bin/pool-describe +9 -0
- data/bin/pool-list +28 -0
- data/bin/pool-provision +34 -0
- data/bin/pool-spec +17 -0
- data/bin/pool-start +32 -0
- data/bin/pool-start-monitor +1 -0
- data/config/hoe.rb +115 -0
- data/config/requirements.rb +15 -0
- data/examples/basic.rb +20 -0
- data/examples/plugin_without_plugin_directory.rb +13 -0
- data/examples/poolparty.rb +12 -0
- data/examples/with_apache_plugin.rb +22 -0
- data/generators/poolspec/USAGE +5 -0
- data/generators/poolspec/poolspec_generator.rb +65 -0
- data/generators/poolspec/templates/pool_spec_template.erb +9 -0
- data/lib/erlang/eb_server.erl +27 -0
- data/lib/poolparty.rb +56 -0
- data/lib/poolparty/base_packages/haproxy.rb +42 -0
- data/lib/poolparty/base_packages/heartbeat.rb +45 -0
- data/lib/poolparty/base_packages/poolparty.rb +36 -0
- data/lib/poolparty/base_packages/ruby.rb +43 -0
- data/lib/poolparty/core/array.rb +24 -0
- data/lib/{core → poolparty/core}/exception.rb +0 -0
- data/lib/poolparty/core/float.rb +13 -0
- data/lib/poolparty/core/hash.rb +29 -0
- data/lib/poolparty/core/kernel.rb +37 -0
- data/lib/{core → poolparty/core}/module.rb +18 -0
- data/lib/poolparty/core/my_open_struct.rb +18 -0
- data/lib/poolparty/core/object.rb +54 -0
- data/lib/poolparty/core/proc.rb +7 -0
- data/lib/poolparty/core/string.rb +72 -0
- data/lib/poolparty/core/symbol.rb +8 -0
- data/lib/{core → poolparty/core}/time.rb +15 -0
- data/lib/poolparty/exceptions/RemoteException.rb +12 -0
- data/lib/poolparty/exceptions/ResourceException.rb +7 -0
- data/lib/poolparty/exceptions/RuntimeException.rb +7 -0
- data/lib/poolparty/exceptions/SpecException.rb +7 -0
- data/lib/poolparty/exceptions/TemplateNotFound.rb +7 -0
- data/lib/poolparty/helpers/binary.rb +31 -0
- data/lib/poolparty/helpers/console.rb +30 -0
- data/lib/poolparty/helpers/display.rb +34 -0
- data/lib/poolparty/helpers/optioner.rb +64 -0
- data/lib/poolparty/helpers/provisioner_base.rb +250 -0
- data/lib/poolparty/helpers/provisioners/master.rb +136 -0
- data/lib/poolparty/helpers/provisioners/slave.rb +44 -0
- data/lib/poolparty/modules/cloud_resourcer.rb +89 -0
- data/lib/poolparty/modules/configurable.rb +34 -0
- data/lib/poolparty/modules/definable_resource.rb +59 -0
- data/lib/poolparty/modules/file_writer.rb +55 -0
- data/lib/poolparty/modules/method_missing_sugar.rb +53 -0
- data/lib/poolparty/modules/output.rb +13 -0
- data/lib/poolparty/modules/pretty_printer.rb +39 -0
- data/lib/{core/string.rb → poolparty/modules/s3_string.rb} +5 -22
- data/lib/{modules → poolparty/modules}/safe_instance.rb +0 -0
- data/lib/poolparty/monitors/base_monitor.rb +16 -0
- data/lib/poolparty/net/remote.rb +35 -0
- data/lib/poolparty/net/remote_bases/ec2.rb +148 -0
- data/lib/poolparty/net/remote_instance.rb +69 -0
- data/lib/poolparty/net/remoter.rb +224 -0
- data/lib/poolparty/net/remoter_base.rb +117 -0
- data/lib/poolparty/plugins/gem_package.rb +17 -0
- data/lib/poolparty/plugins/git.rb +41 -0
- data/lib/poolparty/plugins/line.rb +76 -0
- data/lib/poolparty/plugins/svn.rb +48 -0
- data/lib/poolparty/pool/base.rb +75 -0
- data/lib/poolparty/pool/cloud.rb +164 -0
- data/lib/poolparty/pool/custom_resource.rb +61 -0
- data/lib/poolparty/pool/loggable.rb +29 -0
- data/lib/poolparty/pool/plugin.rb +41 -0
- data/lib/poolparty/pool/plugin_model.rb +48 -0
- data/lib/poolparty/pool/pool.rb +55 -0
- data/lib/poolparty/pool/resource.rb +248 -0
- data/lib/poolparty/pool/resources/class_package.rb +64 -0
- data/lib/poolparty/pool/resources/conditional.rb +41 -0
- data/lib/poolparty/pool/resources/cron.rb +14 -0
- data/lib/poolparty/pool/resources/directory.rb +23 -0
- data/lib/poolparty/pool/resources/exec.rb +26 -0
- data/lib/poolparty/pool/resources/file.rb +23 -0
- data/lib/poolparty/pool/resources/gem.rb +14 -0
- data/lib/poolparty/pool/resources/host.rb +14 -0
- data/lib/poolparty/pool/resources/package.rb +14 -0
- data/lib/poolparty/pool/resources/remote_file.rb +22 -0
- data/lib/poolparty/pool/resources/service.rb +21 -0
- data/lib/poolparty/pool/resources/sshkey.rb +19 -0
- data/lib/poolparty/pool/resources/variable.rb +27 -0
- data/lib/poolparty/pool/script.rb +44 -0
- data/lib/poolparty/templates/authkeys +2 -0
- data/{config/monit/nginx.monit.conf → lib/poolparty/templates/cib.xml} +0 -0
- data/lib/poolparty/templates/fileserver.conf +4 -0
- data/lib/poolparty/templates/gem +25 -0
- data/{config/heartbeat.conf → lib/poolparty/templates/ha.cf} +3 -2
- data/{config → lib/poolparty/templates}/haproxy.conf +13 -6
- data/lib/poolparty/templates/namespaceauth.conf +19 -0
- data/lib/poolparty/templates/puppet.conf +17 -0
- data/lib/poolparty/version.rb +9 -0
- data/lib/poolpartycl.rb +3 -0
- data/poolparty.gemspec +56 -47
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +82 -0
- data/setup.rb +1585 -0
- data/spec/poolparty/base_packages/haproxy_spec.rb +13 -0
- data/spec/poolparty/base_packages/heartbeat_spec.rb +30 -0
- data/spec/poolparty/bin/console_spec.rb +80 -0
- data/spec/poolparty/core/array_spec.rb +26 -0
- data/spec/poolparty/core/float.rb +13 -0
- data/spec/poolparty/core/hash_spec.rb +63 -0
- data/spec/poolparty/core/kernel_spec.rb +24 -0
- data/spec/poolparty/core/module_spec.rb +15 -0
- data/spec/poolparty/core/object_spec.rb +40 -0
- data/spec/poolparty/core/string_spec.rb +152 -0
- data/spec/poolparty/core/time_spec.rb +52 -0
- data/spec/poolparty/helpers/binary_spec.rb +26 -0
- data/spec/poolparty/helpers/display_spec.rb +13 -0
- data/spec/poolparty/helpers/optioner_spec.rb +39 -0
- data/spec/poolparty/helpers/provisioner_base_spec.rb +121 -0
- data/spec/poolparty/helpers/provisioners/master_spec.rb +54 -0
- data/spec/poolparty/helpers/provisioners/slave_spec.rb +28 -0
- data/spec/poolparty/modules/cloud_resourcer_spec.rb +135 -0
- data/spec/poolparty/modules/configurable_spec.rb +26 -0
- data/spec/poolparty/modules/definable_resource.rb +9 -0
- data/spec/poolparty/modules/file_writer_spec.rb +49 -0
- data/spec/poolparty/modules/s3_string_spec.rb +15 -0
- data/spec/poolparty/modules/tmp/willy/nilly.rb +1 -0
- data/spec/poolparty/net/remote_bases/ec2_spec.rb +92 -0
- data/spec/poolparty/net/remote_instance_spec.rb +70 -0
- data/spec/poolparty/net/remote_spec.rb +286 -0
- data/spec/poolparty/net/remoter_base_spec.rb +80 -0
- data/spec/poolparty/net/remoter_spec.rb +191 -0
- data/spec/poolparty/plugins/git_spec.rb +33 -0
- data/spec/poolparty/plugins/line_spec.rb +16 -0
- data/spec/poolparty/plugins/svn_spec.rb +16 -0
- data/spec/poolparty/pool/base_spec.rb +108 -0
- data/spec/poolparty/pool/cloud_spec.rb +299 -0
- data/spec/poolparty/pool/configurers/files/ruby_basic.rb +17 -0
- data/spec/poolparty/pool/configurers/files/ruby_plugins.rb +16 -0
- data/spec/poolparty/pool/configurers/ruby_spec.rb +58 -0
- data/spec/poolparty/pool/custom_resource_spec.rb +115 -0
- data/spec/poolparty/pool/example_spec.rb +112 -0
- data/spec/poolparty/pool/plugin_model_spec.rb +63 -0
- data/spec/poolparty/pool/plugin_spec.rb +85 -0
- data/spec/poolparty/pool/pool_spec.rb +83 -0
- data/spec/poolparty/pool/resource_spec.rb +224 -0
- data/spec/poolparty/pool/resources/class_package_spec.rb +84 -0
- data/spec/poolparty/pool/resources/conditional_spec.rb +38 -0
- data/spec/poolparty/pool/resources/cron_spec.rb +49 -0
- data/spec/poolparty/pool/resources/directory_spec.rb +40 -0
- data/spec/poolparty/pool/resources/exec_spec.rb +37 -0
- data/spec/poolparty/pool/resources/file_spec.rb +40 -0
- data/spec/poolparty/pool/resources/gem_spec.rb +16 -0
- data/spec/poolparty/pool/resources/host_spec.rb +28 -0
- data/spec/poolparty/pool/resources/package_spec.rb +44 -0
- data/spec/poolparty/pool/resources/remote_file_spec.rb +40 -0
- data/spec/poolparty/pool/resources/service_spec.rb +45 -0
- data/spec/poolparty/pool/resources/sshkey_spec.rb +48 -0
- data/spec/poolparty/pool/resources/variable_spec.rb +20 -0
- data/spec/poolparty/pool/script_spec.rb +51 -0
- data/spec/poolparty/pool/test_plugins/sshkey_test +2 -0
- data/{test/test_pool_party.rb → spec/poolparty/pool/test_plugins/virtual_host_template.erb} +0 -0
- data/spec/poolparty/pool/test_plugins/webserver.rb +46 -0
- data/spec/poolparty/poolparty_spec.rb +33 -0
- data/spec/poolparty/spec_helper.rb +120 -0
- data/tasks/cloud.rake +57 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/development.rake +78 -0
- data/tasks/ec2.rake +20 -0
- data/tasks/environment.rake +7 -0
- data/tasks/instance.rake +63 -0
- data/tasks/server.rake +42 -0
- data/tasks/spec.rake +17 -0
- data/tasks/website.rake +17 -0
- data/test/test_generator_helper.rb +29 -0
- data/test/test_helper.rb +2 -0
- data/test/test_pool_spec_generator.rb +47 -0
- data/test/test_poolparty.rb +11 -0
- data/test_manifest.pp +538 -0
- data/website/index.html +107 -0
- data/website/index.txt +95 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/code.css +29 -0
- data/website/stylesheets/screen.css +147 -0
- data/website/template.html.erb +49 -0
- metadata +282 -101
- data/CHANGELOG +0 -4
- data/Manifest +0 -55
- data/bin/instance +0 -54
- data/config/config.yml +0 -23
- data/config/create_proxy_ami.sh +0 -582
- data/config/heartbeat_authkeys.conf +0 -2
- data/config/monit.conf +0 -8
- data/config/monit/haproxy.monit.conf +0 -7
- data/config/nginx.conf +0 -24
- data/lib/core/array.rb +0 -10
- data/lib/core/kernel.rb +0 -9
- data/lib/core/object.rb +0 -14
- data/lib/modules/callback.rb +0 -55
- data/lib/modules/ec2_wrapper.rb +0 -74
- data/lib/pool_party.rb +0 -69
- data/lib/pool_party/application.rb +0 -133
- data/lib/pool_party/init.rb +0 -4
- data/lib/pool_party/master.rb +0 -189
- data/lib/pool_party/monitors.rb +0 -13
- data/lib/pool_party/monitors/cpu.rb +0 -18
- data/lib/pool_party/monitors/memory.rb +0 -21
- data/lib/pool_party/monitors/web.rb +0 -18
- data/lib/pool_party/optioner.rb +0 -16
- data/lib/pool_party/os.rb +0 -11
- data/lib/pool_party/os/ubuntu.rb +0 -78
- data/lib/pool_party/remote_instance.rb +0 -180
- data/lib/pool_party/remoting.rb +0 -112
- data/lib/pool_party/scheduler.rb +0 -93
- data/lib/pool_party/tasks.rb +0 -220
- data/lib/s3/s3_object_store_folders.rb +0 -44
- data/spec/application_spec.rb +0 -32
- data/spec/callback_spec.rb +0 -65
- data/spec/helpers/ec2_mock.rb +0 -56
- data/spec/helpers/remote_instance_mock.rb +0 -11
- data/spec/kernel_spec.rb +0 -11
- data/spec/master_spec.rb +0 -147
- data/spec/monitor_spec.rb +0 -16
- data/spec/optioner_spec.rb +0 -22
- data/spec/poolparty_spec.rb +0 -8
- data/spec/remote_instance_spec.rb +0 -29
- data/spec/remoting_spec.rb +0 -75
- data/spec/spec_helper.rb +0 -38
- data/spec/string_spec.rb +0 -28
@@ -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={}, parent=self, &block)
|
24
|
+
@str = str
|
25
|
+
super(opts, parent, &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={}, parent=self, &block)
|
36
|
+
@name = name
|
37
|
+
super(opts, parent, &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,41 @@
|
|
1
|
+
module PoolParty
|
2
|
+
|
3
|
+
module Plugin
|
4
|
+
|
5
|
+
class Plugin
|
6
|
+
include Configurable
|
7
|
+
include CloudResourcer
|
8
|
+
include Resources
|
9
|
+
|
10
|
+
attr_accessor :parent
|
11
|
+
class_inheritable_accessor :name
|
12
|
+
|
13
|
+
default_options({})
|
14
|
+
|
15
|
+
def initialize(parent=self, opts={}, &block)
|
16
|
+
set_parent(parent)
|
17
|
+
block ? instance_eval(&block) : enable
|
18
|
+
end
|
19
|
+
|
20
|
+
# Overwrite this method
|
21
|
+
def enable
|
22
|
+
end
|
23
|
+
|
24
|
+
# def method_missing(m, *args, &block)
|
25
|
+
# if block_given?
|
26
|
+
# (args[0].class == self.class) ? args[0].instance_eval(&block) : super
|
27
|
+
# elsif parent && parent.respond_to?(m)
|
28
|
+
# parent.send m, *args, &block
|
29
|
+
# else
|
30
|
+
# get_from_options(m, *args)
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# def get_from_options(m, *args)
|
35
|
+
# args.empty? ? options[m] : options[m] = args[0]
|
36
|
+
# end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
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,248 @@
|
|
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={}, parent=self, &block)
|
21
|
+
returning "PoolParty::Resources::#{type.to_s.camelize}".classify.constantize.new(opts, parent, &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
|
+
attr_accessor :prestring, :poststring
|
47
|
+
|
48
|
+
include CloudResourcer
|
49
|
+
include Configurable
|
50
|
+
|
51
|
+
extend PoolParty::Resources
|
52
|
+
include PoolParty::Resources
|
53
|
+
|
54
|
+
def self.inherited(subclass)
|
55
|
+
subclass = subclass.to_s.split("::")[-1] if subclass.to_s.index("::")
|
56
|
+
lowercase_class_name = subclass.to_s.downcase
|
57
|
+
|
58
|
+
# Add add resource method to the Resources module
|
59
|
+
unless PoolParty::Resources.respond_to?(lowercase_class_name.to_sym)
|
60
|
+
method =<<-EOE
|
61
|
+
def #{lowercase_class_name}(opts={}, parent=self, &blk)
|
62
|
+
add_resource(:#{lowercase_class_name}, opts, parent, &blk)
|
63
|
+
end
|
64
|
+
EOE
|
65
|
+
PoolParty::Resources.module_eval method
|
66
|
+
PoolParty::Resources.add_has_and_does_not_have_methods_for(lowercase_class_name.to_sym)
|
67
|
+
|
68
|
+
available_resources << subclass
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.available_resources
|
73
|
+
@available_resources ||= []
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.available_resource_methods
|
77
|
+
available_resources.map {|a| a.my_methods }
|
78
|
+
end
|
79
|
+
|
80
|
+
# This is set in order of descending precedence
|
81
|
+
# The options are overwritten from the bottom up
|
82
|
+
# and the resource will use those as the values
|
83
|
+
# Then it takes the value of the block and sets whatever is sent there as
|
84
|
+
# the options
|
85
|
+
# Finally, it uses the parent's options as the lowest priority
|
86
|
+
def initialize(opts={}, parent=self, &block)
|
87
|
+
# Take the options of the parents
|
88
|
+
@parent = parent
|
89
|
+
set_vars_from_options(opts) unless opts.empty?
|
90
|
+
self.instance_eval &block if block
|
91
|
+
loaded(opts)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Stub, so you can create virtual resources
|
95
|
+
def loaded(opts={})
|
96
|
+
end
|
97
|
+
|
98
|
+
# DSL Overriders
|
99
|
+
# Overrides for syntax
|
100
|
+
# Allows us to send require to require a resource
|
101
|
+
def require(str="")
|
102
|
+
options[:require]
|
103
|
+
end
|
104
|
+
def requires(str="")
|
105
|
+
options.merge!(:require => str)
|
106
|
+
end
|
107
|
+
def ensures(str="running")
|
108
|
+
if %w(absent running).map {|a| self.send a.to_sym}.include?(str)
|
109
|
+
str == "absent" ? is_absent : is_present
|
110
|
+
else
|
111
|
+
options.merge!(:ensure => str)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
# Allows us to send an ensure to ensure the presence of a resource
|
115
|
+
def is_present(*args)
|
116
|
+
options.merge!(:ensure => present)
|
117
|
+
end
|
118
|
+
# Ensures that what we are sending is absent
|
119
|
+
def is_absent(*args)
|
120
|
+
options.merge!(:ensure => absent)
|
121
|
+
end
|
122
|
+
# Alias for unless
|
123
|
+
def ifnot(str="")
|
124
|
+
options.merge!(:unless => str)
|
125
|
+
end
|
126
|
+
def present
|
127
|
+
"present"
|
128
|
+
end
|
129
|
+
def absent
|
130
|
+
"absent"
|
131
|
+
end
|
132
|
+
|
133
|
+
# Give us a template to work with on the resource
|
134
|
+
# Make sure this template is moved to the tmp directory as well
|
135
|
+
def template(file, opts={})
|
136
|
+
raise TemplateNotFound.new("no template given") unless file
|
137
|
+
raise TemplateNotFound.new("template cannot be found #{file}") unless ::File.file?(file)
|
138
|
+
unless opts[:just_copy]
|
139
|
+
options.merge!({:content => "template(\"#{::File.basename(file)}\")"})
|
140
|
+
options.delete(:source) if options.has_key?(:source)
|
141
|
+
copy_template_to_storage_directory(file)
|
142
|
+
else
|
143
|
+
copy_file_to_storage_directory(file)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
# This way we can subclass resources without worry
|
147
|
+
def class_type_name
|
148
|
+
self.class.to_s.top_level_class
|
149
|
+
end
|
150
|
+
def self.custom_function(str)
|
151
|
+
custom_functions << str
|
152
|
+
end
|
153
|
+
|
154
|
+
def self.custom_function(str)
|
155
|
+
custom_functions << str
|
156
|
+
end
|
157
|
+
def self.custom_functions
|
158
|
+
@custom_functions ||= []
|
159
|
+
end
|
160
|
+
def custom_function(str)
|
161
|
+
self.class.custom_functions << str
|
162
|
+
end
|
163
|
+
|
164
|
+
def self.custom_functions_to_string(prev="")
|
165
|
+
returning Array.new do |output|
|
166
|
+
PoolParty::Resources.available_custom_resources.each do |resource|
|
167
|
+
resource.custom_functions.each do |func|
|
168
|
+
output << "#{prev*2}#{func}"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end.join("\n")
|
172
|
+
end
|
173
|
+
# Some things in puppet aren't allowed, so let's override them here
|
174
|
+
def disallowed_options
|
175
|
+
[]
|
176
|
+
end
|
177
|
+
def key
|
178
|
+
name
|
179
|
+
end
|
180
|
+
def virtual_resource?
|
181
|
+
false
|
182
|
+
end
|
183
|
+
# We want to gather the options, but if the option sent is nil
|
184
|
+
# then we want to override the option value by sending the key as
|
185
|
+
# a method so that we can override this if necessary.
|
186
|
+
# Only runs on objects that have options defined, otherwise
|
187
|
+
# it returns an empty hash
|
188
|
+
def get_modified_options
|
189
|
+
if options
|
190
|
+
opts = options.inject({}) do |sum,h|
|
191
|
+
sum.merge!({h[0].to_sym => ((h[1].nil?) ? self.send(h[0].to_sym) : h[1]) })
|
192
|
+
end
|
193
|
+
else
|
194
|
+
opts = {}
|
195
|
+
end
|
196
|
+
opts.reject {|k,v| disallowed_options.include?(k) }
|
197
|
+
end
|
198
|
+
|
199
|
+
# Generic to_s
|
200
|
+
# Most Resources won't need to extend this
|
201
|
+
def to_string(prev="")
|
202
|
+
opts = get_modified_options
|
203
|
+
returning Array.new do |output|
|
204
|
+
|
205
|
+
output << @prestring || ""
|
206
|
+
|
207
|
+
if resources && !resources.empty?
|
208
|
+
@cp = classpackage_with_self(self)
|
209
|
+
output << @cp.to_string
|
210
|
+
output << "include #{@cp.name.sanitize}"
|
211
|
+
end
|
212
|
+
|
213
|
+
unless virtual_resource?
|
214
|
+
output << "#{prev}#{class_type_name} {"
|
215
|
+
output << "#{prev}\"#{self.key}\":"
|
216
|
+
output << opts.flush_out("#{prev*2}").join(",\n")
|
217
|
+
output << "#{prev}}"
|
218
|
+
end
|
219
|
+
|
220
|
+
output << @poststring || ""
|
221
|
+
|
222
|
+
end.join("\n")
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
# Adds two methods to the module
|
227
|
+
# Adds the method type:
|
228
|
+
# has_
|
229
|
+
# and
|
230
|
+
# does_not_have_
|
231
|
+
# for the type passed
|
232
|
+
# for instance
|
233
|
+
# add_has_and_does_not_have_methods_for(:file)
|
234
|
+
# gives you the methods has_file and does_not_have_file
|
235
|
+
# TODO: Refactor nicely to include other types that don't accept ensure
|
236
|
+
def self.add_has_and_does_not_have_methods_for(type=:file)
|
237
|
+
module_eval <<-EOE
|
238
|
+
def has_#{type}(opts={}, parent=self, &block)
|
239
|
+
#{type}(#{type == :exec ? "opts" : "{:is_present => ''}.merge(opts)"}, parent, &block)
|
240
|
+
end
|
241
|
+
def does_not_have_#{type}(opts={}, parent=self, &block)
|
242
|
+
#{type}(#{type == :exec ? "opts" : "{:is_absent => ''}.merge(opts)"}, parent, &block)
|
243
|
+
end
|
244
|
+
EOE
|
245
|
+
end
|
246
|
+
|
247
|
+
end
|
248
|
+
end
|