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.
- data/History.txt +22 -0
- data/License.txt +20 -0
- data/README.txt +52 -0
- data/Rakefile +4 -109
- data/bin/cloud +31 -0
- data/bin/cloud-add-keypair +23 -0
- data/bin/cloud-configure +35 -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-provision +30 -0
- data/bin/cloud-reconfigure +24 -0
- data/bin/cloud-ssh +18 -0
- data/bin/cloud-start +29 -0
- data/bin/pool +23 -75
- 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/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 +40 -116
- data/lib/poolparty/base_packages/haproxy.rb +41 -0
- data/lib/poolparty/base_packages/heartbeat.rb +43 -0
- data/lib/poolparty/base_packages/poolparty.rb +18 -0
- data/lib/poolparty/base_packages/ruby.rb +27 -0
- data/lib/poolparty/core/array.rb +24 -0
- data/lib/{core → poolparty/core}/exception.rb +0 -0
- data/lib/{core → poolparty/core}/float.rb +0 -0
- data/lib/poolparty/core/hash.rb +29 -0
- data/lib/poolparty/core/kernel.rb +34 -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 +2 -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 +30 -0
- data/lib/poolparty/helpers/console.rb +30 -0
- data/lib/poolparty/helpers/display.rb +25 -0
- data/lib/poolparty/helpers/optioner.rb +61 -0
- data/lib/poolparty/helpers/provisioner_base.rb +226 -0
- data/lib/poolparty/helpers/provisioners/master.rb +120 -0
- data/lib/poolparty/helpers/provisioners/slave.rb +52 -0
- data/lib/poolparty/modules/cloud_resourcer.rb +72 -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 +17 -0
- data/lib/poolparty/modules/output.rb +13 -0
- data/lib/poolparty/modules/pretty_printer.rb +38 -0
- data/lib/{core/string.rb → poolparty/modules/s3_string.rb} +5 -29
- 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 +145 -0
- data/lib/poolparty/net/remote_instance.rb +68 -0
- data/lib/poolparty/net/remoter.rb +209 -0
- data/lib/poolparty/net/remoter_base.rb +117 -0
- data/lib/poolparty/plugins/gem_package.rb +39 -0
- data/lib/poolparty/plugins/line.rb +76 -0
- data/lib/poolparty/plugins/svn.rb +48 -0
- data/lib/poolparty/pool/base.rb +74 -0
- data/lib/poolparty/pool/cloud.rb +132 -0
- data/lib/poolparty/pool/custom_resource.rb +61 -0
- data/lib/poolparty/pool/loggable.rb +29 -0
- data/lib/poolparty/pool/plugin.rb +42 -0
- data/lib/poolparty/pool/plugin_model.rb +48 -0
- data/lib/poolparty/pool/pool.rb +55 -0
- data/lib/poolparty/pool/resource.rb +235 -0
- data/lib/poolparty/pool/resources/class_package.rb +60 -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 +20 -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 +21 -0
- data/{config/heartbeat_authkeys.conf → lib/poolparty/templates/authkeys} +0 -0
- data/lib/poolparty/templates/cib.xml +1 -0
- data/lib/poolparty/templates/fileserver.conf +4 -0
- data/{config/heartbeat.conf → lib/poolparty/templates/ha.cf} +3 -1
- data/{config → lib/poolparty/templates}/haproxy.conf +13 -6
- data/lib/poolparty/templates/namespaceauth.conf +19 -0
- data/lib/poolparty/templates/puppet.conf +13 -0
- data/lib/poolparty/version.rb +9 -0
- data/lib/poolpartycl.rb +3 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +82 -0
- data/{lib/poolparty/tasks → tasks}/cloud.rake +1 -1
- data/tasks/deployment.rake +34 -0
- data/tasks/development.rake +78 -0
- data/{lib/poolparty/tasks → tasks}/ec2.rake +1 -1
- data/tasks/environment.rake +7 -0
- data/{lib/poolparty/tasks → tasks}/instance.rake +0 -0
- data/{lib/poolparty/tasks → tasks}/server.rake +0 -0
- data/tasks/spec.rake +17 -0
- data/tasks/website.rake +17 -0
- metadata +154 -249
- data/CHANGELOG +0 -23
- data/LICENSE +0 -22
- data/README +0 -139
- data/assets/clouds.png +0 -0
- data/bin/instance +0 -68
- data/bin/poolnotify +0 -34
- data/config/cloud_master_takeover +0 -17
- data/config/create_proxy_ami.sh +0 -582
- data/config/installers/ubuntu_install.sh +0 -77
- data/config/monit.conf +0 -9
- data/config/monit/haproxy.monit.conf +0 -8
- data/config/monit/nginx.monit.conf +0 -0
- data/config/nginx.conf +0 -24
- data/config/reconfigure_instances_script.sh +0 -37
- data/config/sample-config.yml +0 -23
- data/config/scp_instances_script.sh +0 -12
- data/lib/core/array.rb +0 -16
- data/lib/core/hash.rb +0 -11
- data/lib/core/kernel.rb +0 -12
- data/lib/core/object.rb +0 -21
- data/lib/core/proc.rb +0 -15
- data/lib/helpers/plugin_spec_helper.rb +0 -58
- data/lib/modules/callback.rb +0 -133
- data/lib/modules/ec2_wrapper.rb +0 -108
- data/lib/modules/file_writer.rb +0 -38
- data/lib/modules/sprinkle_overrides.rb +0 -27
- data/lib/modules/vlad_override.rb +0 -83
- data/lib/poolparty/application.rb +0 -199
- data/lib/poolparty/init.rb +0 -6
- data/lib/poolparty/master.rb +0 -492
- data/lib/poolparty/monitors.rb +0 -11
- data/lib/poolparty/monitors/cpu.rb +0 -23
- data/lib/poolparty/monitors/memory.rb +0 -33
- data/lib/poolparty/monitors/web.rb +0 -29
- data/lib/poolparty/optioner.rb +0 -20
- data/lib/poolparty/plugin.rb +0 -78
- data/lib/poolparty/provider.rb +0 -104
- data/lib/poolparty/provider/essential.rb +0 -6
- data/lib/poolparty/provider/git.rb +0 -8
- data/lib/poolparty/provider/haproxy.rb +0 -9
- data/lib/poolparty/provider/heartbeat.rb +0 -6
- data/lib/poolparty/provider/rsync.rb +0 -8
- data/lib/poolparty/provider/ruby.rb +0 -65
- data/lib/poolparty/provider/s3fuse.rb +0 -22
- data/lib/poolparty/remote_instance.rb +0 -250
- data/lib/poolparty/remoter.rb +0 -171
- data/lib/poolparty/remoting.rb +0 -137
- data/lib/poolparty/scheduler.rb +0 -93
- data/lib/poolparty/tasks.rb +0 -47
- data/lib/poolparty/tasks/development.rake +0 -78
- data/lib/poolparty/tasks/plugins.rake +0 -30
- data/lib/poolparty/thread_pool.rb +0 -94
- data/lib/s3/s3_object_store_folders.rb +0 -44
- data/poolparty.gemspec +0 -71
- data/spec/files/describe_response +0 -37
- data/spec/files/multi_describe_response +0 -69
- data/spec/files/remote_desc_response +0 -37
- data/spec/helpers/ec2_mock.rb +0 -57
- data/spec/lib/core/core_spec.rb +0 -26
- data/spec/lib/core/kernel_spec.rb +0 -24
- data/spec/lib/core/string_spec.rb +0 -28
- data/spec/lib/modules/callback_spec.rb +0 -213
- data/spec/lib/modules/file_writer_spec.rb +0 -74
- data/spec/lib/poolparty/application_spec.rb +0 -135
- data/spec/lib/poolparty/ec2_wrapper_spec.rb +0 -110
- data/spec/lib/poolparty/master_spec.rb +0 -479
- data/spec/lib/poolparty/optioner_spec.rb +0 -34
- data/spec/lib/poolparty/plugin_spec.rb +0 -115
- data/spec/lib/poolparty/poolparty_spec.rb +0 -60
- data/spec/lib/poolparty/provider_spec.rb +0 -74
- data/spec/lib/poolparty/remote_instance_spec.rb +0 -178
- data/spec/lib/poolparty/remoter_spec.rb +0 -72
- data/spec/lib/poolparty/remoting_spec.rb +0 -148
- data/spec/lib/poolparty/scheduler_spec.rb +0 -70
- data/spec/monitors/cpu_monitor_spec.rb +0 -39
- data/spec/monitors/memory_spec.rb +0 -51
- data/spec/monitors/misc_monitor_spec.rb +0 -51
- data/spec/monitors/web_spec.rb +0 -40
- data/spec/spec_helper.rb +0 -53
@@ -0,0 +1,18 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
Create an extended open struct
|
3
|
+
=end
|
4
|
+
require "ostruct"
|
5
|
+
class MyOpenStruct < OpenStruct
|
6
|
+
attr_accessor :keys
|
7
|
+
def initialize(h)
|
8
|
+
@keys = h.keys
|
9
|
+
super
|
10
|
+
end
|
11
|
+
def to_hash
|
12
|
+
m = {}
|
13
|
+
@keys.map do |key|
|
14
|
+
m.update( {key => self.send(key)} )
|
15
|
+
end
|
16
|
+
m
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
Basic, add an alias_method to the object class
|
3
|
+
Add returning to the object
|
4
|
+
=end
|
5
|
+
class Object
|
6
|
+
def my_methods
|
7
|
+
self.methods.sort - (self.class.methods + self.class.superclass.methods)
|
8
|
+
end
|
9
|
+
def to_os
|
10
|
+
self
|
11
|
+
end
|
12
|
+
def alias_method(new_id, original_id)
|
13
|
+
original = self.method(original_id).to_proc
|
14
|
+
define_method(new_id){|*args| original.call(*args)}
|
15
|
+
end
|
16
|
+
def with_options(opts={}, parent=self, &block)
|
17
|
+
@p = parent.clone
|
18
|
+
@p.options.merge!(opts)
|
19
|
+
@p.instance_eval &block if block
|
20
|
+
end
|
21
|
+
def returning(receiver)
|
22
|
+
yield receiver
|
23
|
+
receiver
|
24
|
+
end
|
25
|
+
def extended(&block)
|
26
|
+
block.in_context(self).call
|
27
|
+
self
|
28
|
+
end
|
29
|
+
def to_option_string
|
30
|
+
case self.class
|
31
|
+
when String
|
32
|
+
self.to_option_string
|
33
|
+
when Array
|
34
|
+
self.each {|a| a.to_option_string }.join(" ")
|
35
|
+
else
|
36
|
+
"#{self}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
def block_instance_eval(*args, &block)
|
40
|
+
return instance_eval(*args,&block) unless block_given? && !block.arity.zero?
|
41
|
+
old_method = (self.class.instance_method(:__) rescue nil)
|
42
|
+
self.class.send(:define_method, :__, &block)
|
43
|
+
block_method = self.class.instance_method(:__)
|
44
|
+
if old_method
|
45
|
+
self.class.send(:define_method, :__, old_method)
|
46
|
+
else
|
47
|
+
self.class.send(:remove_method, :__)
|
48
|
+
end
|
49
|
+
block_method.bind(self).call(*args)
|
50
|
+
end
|
51
|
+
def meta_def name, &blk
|
52
|
+
(class << self; self; end).instance_eval { define_method name, &blk }
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
class String
|
2
|
+
def hasherize(format=[])
|
3
|
+
hash = {}
|
4
|
+
i = 0
|
5
|
+
self.split(%r{[\n|\t|\s| ]+}).map {|a| a.strip}.each do |f|
|
6
|
+
next unless format[i]
|
7
|
+
unless f == "" || f.nil?
|
8
|
+
hash[format[i].to_sym] = f
|
9
|
+
i+=1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
hash
|
13
|
+
end
|
14
|
+
def ^(h={})
|
15
|
+
self.gsub(/:([\w]+)/) {h[$1.to_sym] if h.include?($1.to_sym)}
|
16
|
+
end
|
17
|
+
def arrayable
|
18
|
+
self.strip.split(/\n/)
|
19
|
+
end
|
20
|
+
def runnable(quite=true)
|
21
|
+
# map {|l| l << "#{" >/dev/null 2>/dev/null" if quite}" }.
|
22
|
+
self.strip.split(/\n/).join(" && ")
|
23
|
+
end
|
24
|
+
def top_level_class
|
25
|
+
self.split("::")[-1].downcase rescue self
|
26
|
+
end
|
27
|
+
def sanitize
|
28
|
+
self.gsub(/[\.]*/, '')
|
29
|
+
end
|
30
|
+
def nice_runnable(quite=true)
|
31
|
+
self.split(/ && /).join("\n")
|
32
|
+
end
|
33
|
+
def to_option_string(ns=[])
|
34
|
+
a_template = (self =~ /template/) == 0
|
35
|
+
a_service = self =~ /^[A-Z][a-zA-Z]*\[[a-zA-Z0-9\-\.\"\'_\$\{\}\/]*\]/
|
36
|
+
(a_service || a_template) ? "#{self}" : "'#{self}'"
|
37
|
+
end
|
38
|
+
# Refactor this guy to get the class if the class is defined, and not always create a new one
|
39
|
+
# although, it doesn't really matter as ruby will just reopen the class
|
40
|
+
def class_constant(superclass=nil, opts={}, &block)
|
41
|
+
symc = ((opts && opts[:preserve]) ? ("#{self.classify}Classs") : "PoolParty#{self.classify}Classs").classify
|
42
|
+
|
43
|
+
kla=<<-EOE
|
44
|
+
class #{symc} #{"< #{superclass}" if superclass}
|
45
|
+
end
|
46
|
+
EOE
|
47
|
+
|
48
|
+
Kernel.module_eval kla
|
49
|
+
klass = symc.constantize
|
50
|
+
klass.module_eval &block if block
|
51
|
+
|
52
|
+
klass
|
53
|
+
end
|
54
|
+
|
55
|
+
def module_constant(&block)
|
56
|
+
symc = "#{self}_Module".classify
|
57
|
+
mod = Object.const_defined?(symc) ? Object.const_get(symc.to_sym) : Module.new(&block)
|
58
|
+
Object.const_set(symc, mod) unless Object.const_defined?(symc)
|
59
|
+
symc.to_s.constantize
|
60
|
+
end
|
61
|
+
def preserved_module_constant(ext="", from="PoolParty::", &block)
|
62
|
+
symc = "#{self}#{ext}".classify
|
63
|
+
mod = Kernel.const_defined?(symc) ? Kernel.const_get(symc.to_sym) : Module.new(&block)
|
64
|
+
Kernel.const_set(symc, mod) unless Kernel.const_defined?(symc)
|
65
|
+
symc.to_s.constantize
|
66
|
+
end
|
67
|
+
def collect_each_line_with_index(&block)
|
68
|
+
returning [] do |arr|
|
69
|
+
arr << self.split(/\n/).collect_with_index(&block)
|
70
|
+
end.flatten
|
71
|
+
end
|
72
|
+
end
|
@@ -38,4 +38,19 @@ class Numeric
|
|
38
38
|
self * 7.days
|
39
39
|
end
|
40
40
|
alias :week :weeks
|
41
|
+
|
42
|
+
def months
|
43
|
+
self * 31.days
|
44
|
+
end
|
45
|
+
alias :month :months
|
46
|
+
|
47
|
+
def time_ago
|
48
|
+
out = %w(year month week day hour minute).detect {|unit| self > 1.send(unit) }
|
49
|
+
units_ago(out, self) rescue "Less than a minute ago"
|
50
|
+
end
|
51
|
+
|
52
|
+
def units_ago(unit,seconds)
|
53
|
+
in_units = (seconds / 1.send(unit))
|
54
|
+
"#{in_units.to_i} #{in_units != 1 ? unit.to_s.pluralize : unit} ago"
|
55
|
+
end
|
41
56
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class RemoteException < Exception
|
2
|
+
EXCEPTION_MESSAGES = {
|
3
|
+
:method_not_defined => "Method is not defined",
|
4
|
+
:invalid_formatting => "Invalid formatting",
|
5
|
+
:could_not_install => "Could not install"
|
6
|
+
}
|
7
|
+
attr_reader :message
|
8
|
+
|
9
|
+
def initialize(type=:method_not_defined, note="")
|
10
|
+
@message = "Remote Exception: #{EXCEPTION_MESSAGES[type]} #{note}"
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "ftools"
|
2
|
+
module PoolParty
|
3
|
+
module Binary
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def list_binaries_for(ty="pool")
|
8
|
+
available_binaries_for(ty).join(", ")
|
9
|
+
end
|
10
|
+
def available_binaries_for(ty="pool")
|
11
|
+
Dir["#{binary_directory}/#{ty}-*"].map {|a| File.basename(a.gsub(/#{ty}-/, '')) }.sort
|
12
|
+
end
|
13
|
+
def binary_directory
|
14
|
+
"#{::File.dirname(__FILE__)}/../../../bin"
|
15
|
+
end
|
16
|
+
def get_existing_spec_location
|
17
|
+
[
|
18
|
+
"pool.spec",
|
19
|
+
"#{Base.remote_storage_directory}/pool.spec",
|
20
|
+
"#{Base.storage_directory}/pool.spec",
|
21
|
+
ENV["POOL_SPEC"]
|
22
|
+
].reject {|a| a.nil?}.reject do |f|
|
23
|
+
f unless ::File.file?(f)
|
24
|
+
end.first
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/display"
|
2
|
+
|
3
|
+
module PoolParty
|
4
|
+
module Console
|
5
|
+
|
6
|
+
include Display
|
7
|
+
|
8
|
+
# Load a file that contains a pool into memory
|
9
|
+
def load_pool(filename)
|
10
|
+
unless filename && ::File.file?(filename)
|
11
|
+
puts "Could not load pool"
|
12
|
+
exit
|
13
|
+
else
|
14
|
+
PoolParty::Script.inflate(open(filename).read, File.dirname(filename))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Clear all the pools and reload the console
|
19
|
+
# Call within console to reset and reload the entire poolparty base
|
20
|
+
# as well
|
21
|
+
def reload!
|
22
|
+
reset!
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Object
|
29
|
+
include PoolParty::Console
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module PoolParty
|
2
|
+
module Display
|
3
|
+
|
4
|
+
def pool_describe(options={})
|
5
|
+
pools.each do |k,v|
|
6
|
+
print v.pretty_print
|
7
|
+
end
|
8
|
+
puts ""
|
9
|
+
pools.size
|
10
|
+
end
|
11
|
+
|
12
|
+
def available_bases
|
13
|
+
puts Remote.available_bases
|
14
|
+
end
|
15
|
+
|
16
|
+
def header(str="")
|
17
|
+
"*** #{str}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def subheader(str="")
|
21
|
+
"****** #{str}"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'rdoc/usage'
|
3
|
+
require 'ostruct'
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
module PoolParty
|
7
|
+
class Optioner
|
8
|
+
include Configurable
|
9
|
+
|
10
|
+
attr_reader :options
|
11
|
+
|
12
|
+
def initialize(args=[], opts={}, &block)
|
13
|
+
@arguments = args
|
14
|
+
@parse_options = opts[:parse_options] ? opts[:parse_options] : true
|
15
|
+
|
16
|
+
set_default_options
|
17
|
+
parse_options(&block) if @parse_options
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_default_options
|
22
|
+
@options = {}
|
23
|
+
@options[:verbose] = false
|
24
|
+
@options[:quiet] = false
|
25
|
+
@options[:version] = PoolParty::VERSION::STRING
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse_options(&blk)
|
29
|
+
opts = OptionParser.new
|
30
|
+
opts.banner = "Usage: pool [command] [options]"
|
31
|
+
|
32
|
+
opts.separator ""
|
33
|
+
opts.separator "Options:"
|
34
|
+
|
35
|
+
opts.on('-V', '--version', 'Display the version') { output_version ; exit 0 }
|
36
|
+
opts.on('-v', '--verbose', 'Be verbose') { @options[:verbose] = true }
|
37
|
+
opts.on('-s [file]', '--spec-file [file]', 'Set the spec file') { |file| self.spec file }
|
38
|
+
opts.on('-t', '--test', 'Testing mode') { self.testing "true" }
|
39
|
+
|
40
|
+
blk.call(opts, self) if blk
|
41
|
+
|
42
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
43
|
+
puts opts
|
44
|
+
exit
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.parse!(@arguments)
|
48
|
+
|
49
|
+
process_options
|
50
|
+
output_options if verbose
|
51
|
+
end
|
52
|
+
def process_options
|
53
|
+
@options[:verbose] = false if @options[:quiet]
|
54
|
+
end
|
55
|
+
|
56
|
+
def output_version
|
57
|
+
puts version
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,226 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
The Provisioner is responsible for provisioning REMOTE servers
|
3
|
+
This class only comes in to play when calling the setup commands on
|
4
|
+
the development machine
|
5
|
+
=end
|
6
|
+
module PoolParty
|
7
|
+
module Provisioner
|
8
|
+
|
9
|
+
# Provision master
|
10
|
+
# Convenience method to clean
|
11
|
+
def self.provision_master(cloud, testing=false)
|
12
|
+
Provisioner::Master.new(cloud).process_install!(testing)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.configure_master(cloud, testing=false)
|
16
|
+
Provisioner::Master.new(cloud).process_configure!(testing)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.provision_slaves(cloud, testing=false)
|
20
|
+
cloud.nonmaster_nonterminated_instances.each do |sl|
|
21
|
+
provision_slave(sl, cloud, testing)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.configure_slaves(cloud, testing=false)
|
26
|
+
cloud.nonmaster_nonterminated_instances.each do |sl|
|
27
|
+
configure_slave(sl, cloud, testing)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.provision_slave(instance, cloud, testing=false)
|
32
|
+
Provisioner::Slave.new(instance, cloud).process_install!(testing)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.configure_slave(instance, cloud, testing=false)
|
36
|
+
Provisioner::Slave.new(instance, cloud).process_configure!(testing)
|
37
|
+
end
|
38
|
+
|
39
|
+
class ProvisionerBase
|
40
|
+
|
41
|
+
include Configurable
|
42
|
+
include CloudResourcer
|
43
|
+
|
44
|
+
def initialize(instance,cloud=self, os=:ubuntu)
|
45
|
+
@instance = instance
|
46
|
+
@cloud = cloud
|
47
|
+
|
48
|
+
options(cloud.options) if cloud && cloud.respond_to?(:options)
|
49
|
+
set_vars_from_options(instance.options) unless instance.options.empty?
|
50
|
+
options(instance.options) if instance.respond_to?(:options)
|
51
|
+
|
52
|
+
@os = os.to_s.downcase.to_sym
|
53
|
+
loaded
|
54
|
+
end
|
55
|
+
# Callback after initialized
|
56
|
+
def loaded
|
57
|
+
end
|
58
|
+
# This is the actual runner for the installation
|
59
|
+
def install
|
60
|
+
valid? ? install_string : error
|
61
|
+
end
|
62
|
+
def write_install_file
|
63
|
+
error unless valid?
|
64
|
+
provisioner_file = ::File.join(Base.storage_directory, "install_#{name}.sh")
|
65
|
+
::File.open(provisioner_file, "w+") {|f| f << install }
|
66
|
+
end
|
67
|
+
def process_install!(testing=false)
|
68
|
+
error unless valid?
|
69
|
+
write_install_file
|
70
|
+
setup_runner(@cloud)
|
71
|
+
|
72
|
+
unless testing
|
73
|
+
puts "Logging on to #{@instance.ip}"
|
74
|
+
@cloud.rsync_storage_files_to(@instance)
|
75
|
+
|
76
|
+
cmd = "cd #{Base.remote_storage_path}/#{Base.tmp_path} && chmod +x install_#{name}.sh && /bin/sh install_#{name}.sh && rm -rf *"
|
77
|
+
hide_output do
|
78
|
+
@cloud.run_command_on(cmd, @instance)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
def configure
|
83
|
+
valid? ? configure_string : error
|
84
|
+
end
|
85
|
+
def write_configure_file
|
86
|
+
error unless valid?
|
87
|
+
provisioner_file = ::File.join(Base.storage_directory, "configure_#{name}.sh")
|
88
|
+
::File.open(provisioner_file, "w+") {|f| f << configure }
|
89
|
+
end
|
90
|
+
def process_configure!(testing=false)
|
91
|
+
error unless valid?
|
92
|
+
setup_runner(@cloud)
|
93
|
+
write_configure_file
|
94
|
+
|
95
|
+
unless testing
|
96
|
+
@cloud.rsync_storage_files_to(@instance)
|
97
|
+
|
98
|
+
cmd = "cd #{Base.remote_storage_path}/#{Base.tmp_path} && chmod +x configure_#{name}.sh && /bin/sh configure_#{name}.sh && rm -rf *"
|
99
|
+
@cloud.run_command_on(cmd, @instance)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
def setup_runner(cloud)
|
103
|
+
cloud.prepare_to_configuration
|
104
|
+
cloud.build_and_store_new_config_file
|
105
|
+
end
|
106
|
+
def valid?
|
107
|
+
true
|
108
|
+
end
|
109
|
+
def error
|
110
|
+
"Error in installation"
|
111
|
+
end
|
112
|
+
# Gather all the tasks into one string
|
113
|
+
def install_string
|
114
|
+
(default_install_tasks << custom_install_tasks).each do |task|
|
115
|
+
case task.class
|
116
|
+
when String
|
117
|
+
task
|
118
|
+
when Method
|
119
|
+
self.send(task.to_sym)
|
120
|
+
end
|
121
|
+
end.nice_runnable
|
122
|
+
end
|
123
|
+
def configure_string
|
124
|
+
(default_configure_tasks << custom_configure_tasks).each do |task|
|
125
|
+
case task.class
|
126
|
+
when String
|
127
|
+
task
|
128
|
+
when Method
|
129
|
+
self.send(task.to_sym)
|
130
|
+
end
|
131
|
+
end.nice_runnable
|
132
|
+
end
|
133
|
+
# Tasks with default tasks
|
134
|
+
# These are run on all the provisioners, master or slave
|
135
|
+
def default_install_tasks
|
136
|
+
[
|
137
|
+
"export AWS_ACCESS_KEY_ID=#{@cloud.access_key}",
|
138
|
+
"export AWS_SECRET_ACCESS_ID=#{@cloud.secret_access_key}"
|
139
|
+
] << install_tasks
|
140
|
+
end
|
141
|
+
# Tasks with default configuration tasks
|
142
|
+
# This is run on the provisioner, regardless
|
143
|
+
def default_configure_tasks
|
144
|
+
[
|
145
|
+
] << configure_tasks
|
146
|
+
end
|
147
|
+
# Build a list of the tasks to run on the instance
|
148
|
+
def install_tasks(a=[])
|
149
|
+
@install_task ||= a
|
150
|
+
end
|
151
|
+
def configure_tasks(a=[])
|
152
|
+
@configure_tasks ||= a
|
153
|
+
end
|
154
|
+
# Custom installation tasks
|
155
|
+
# Allow the remoter bases to attach their own tasks on the
|
156
|
+
# installation process
|
157
|
+
def custom_install_tasks
|
158
|
+
@cloud.custom_install_tasks_for(@instance) || []
|
159
|
+
end
|
160
|
+
# Custom configure tasks
|
161
|
+
# Allows the remoter bases to attach their own
|
162
|
+
# custom configuration tasks to the configuration process
|
163
|
+
def custom_configure_tasks
|
164
|
+
@cloud.custom_configure_tasks_for(@instance) || []
|
165
|
+
end
|
166
|
+
|
167
|
+
# Get the packages associated with each os
|
168
|
+
def get_puppet_packages_for(os)
|
169
|
+
case os
|
170
|
+
when :fedora
|
171
|
+
"puppet-server puppet factor"
|
172
|
+
else
|
173
|
+
"puppet puppetmaster"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
# Package installers for general *nix operating systems
|
177
|
+
def self.installers
|
178
|
+
@installers ||= {
|
179
|
+
:ubuntu => "apt-get install -y",
|
180
|
+
:fedora => "yum install",
|
181
|
+
:gentoo => "emerge"
|
182
|
+
}
|
183
|
+
end
|
184
|
+
# Convenience method to grab the installer
|
185
|
+
def installer_for(name)
|
186
|
+
self.class.installers[name.to_sym]
|
187
|
+
end
|
188
|
+
# Install from the class-level
|
189
|
+
def self.install(instance, cl=self)
|
190
|
+
new(instance, cl).install
|
191
|
+
end
|
192
|
+
|
193
|
+
def self.configure(instance, cl=self)
|
194
|
+
new(instance, cl).configure
|
195
|
+
end
|
196
|
+
|
197
|
+
def template_directory
|
198
|
+
File.join(File.dirname(__FILE__), "..", "templates")
|
199
|
+
end
|
200
|
+
|
201
|
+
def create_local_node
|
202
|
+
str = <<-EOS
|
203
|
+
node default {
|
204
|
+
include poolparty
|
205
|
+
}
|
206
|
+
EOS
|
207
|
+
@cloud.list_of_running_instances.each do |ri|
|
208
|
+
str << <<-EOS
|
209
|
+
node "#{ri.name}" {}
|
210
|
+
EOS
|
211
|
+
end
|
212
|
+
"echo '#{str}' > /etc/puppet/manifests/nodes/nodes.pp"
|
213
|
+
end
|
214
|
+
|
215
|
+
def create_poolparty_manifest
|
216
|
+
<<-EOS
|
217
|
+
mv #{Base.remote_storage_path}/poolparty.pp /etc/puppet/manifests/classes
|
218
|
+
EOS
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
## Load the provisioners
|
224
|
+
Dir[File.dirname(__FILE__) + "/provisioners/*.rb"].each do |file|
|
225
|
+
require file
|
226
|
+
end
|