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,117 @@
|
|
1
|
+
module PoolParty
|
2
|
+
|
3
|
+
def register_remote_base(*args)
|
4
|
+
args.each do |arg|
|
5
|
+
(remote_bases << "#{arg}".downcase.to_sym)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def remote_bases
|
10
|
+
$remote_bases ||= []
|
11
|
+
end
|
12
|
+
|
13
|
+
module Remote
|
14
|
+
# This class is the base class for all remote types
|
15
|
+
# Everything remoting-wise is derived from this class
|
16
|
+
module RemoterBaseMethods
|
17
|
+
# Required methods
|
18
|
+
# The next methods are required on all RemoteInstance types
|
19
|
+
# If your RemoteInstance type does not overwrite the following methods
|
20
|
+
# An exception will be raised and poolparty will explode into tiny little
|
21
|
+
# pieces. Don't forget to overwrite these methods
|
22
|
+
# Launch a new instance
|
23
|
+
def launch_new_instance!
|
24
|
+
raise RemoteException.new(:method_not_defined, "launch_new_instance!")
|
25
|
+
end
|
26
|
+
# Terminate an instance by id
|
27
|
+
def terminate_instance!(id=nil)
|
28
|
+
raise RemoteException.new(:method_not_defined, "terminate_instance!")
|
29
|
+
end
|
30
|
+
# Describe an instance's status
|
31
|
+
def describe_instance(id=nil)
|
32
|
+
raise RemoteException.new(:method_not_defined, "describe_instance")
|
33
|
+
end
|
34
|
+
# Get instances
|
35
|
+
# The instances must have a status associated with them on the hash
|
36
|
+
def describe_instances
|
37
|
+
raise RemoteException.new(:method_not_defined, "describe_instances")
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
module RemoterBase
|
42
|
+
# The following methods are inherent on the RemoterBase
|
43
|
+
# If you need to overwrite these methods, do so with caution
|
44
|
+
# Listing methods
|
45
|
+
def list_of_running_instances(list = list_of_nonterminated_instances)
|
46
|
+
list.select {|a| a.running? }
|
47
|
+
end
|
48
|
+
# Get a list of the pending instances
|
49
|
+
def list_of_pending_instances(list = list_of_nonterminated_instances)
|
50
|
+
list.select {|a| a.pending? }
|
51
|
+
end
|
52
|
+
# list of shutting down instances
|
53
|
+
def list_of_terminating_instances(list = remote_instances_list)
|
54
|
+
list.reject {|i| true if !i.terminating? }
|
55
|
+
end
|
56
|
+
# Get the instances that are non-master instances
|
57
|
+
def nonmaster_nonterminated_instances(list = list_of_nonterminated_instances)
|
58
|
+
list_of_nonterminated_instances.reject {|i| i.master? }
|
59
|
+
end
|
60
|
+
# list all the nonterminated instances
|
61
|
+
def list_of_nonterminated_instances(list = remote_instances_list)
|
62
|
+
list.reject {|i| i.terminating? || i.terminated? }
|
63
|
+
end
|
64
|
+
# Get instance by number
|
65
|
+
def get_instance_by_number(i=0, list = remote_instances_list)
|
66
|
+
name = (i.zero? ? "master" : "node#{i}")
|
67
|
+
list.select {|i| i.name == name }.first
|
68
|
+
end
|
69
|
+
def remote_instances_list
|
70
|
+
list_of_instances.map {|i| PoolParty::Remote::RemoteInstance.new(i, self) }
|
71
|
+
end
|
72
|
+
# List the instances for the current key pair, regardless of their states
|
73
|
+
# If no keypair is passed, select them all
|
74
|
+
def list_of_instances(keyp=nil)
|
75
|
+
key = keyp ? keyp : keypair
|
76
|
+
describe_instances.select {|a| key ? a[:keypair] == key : true } if describe_instances
|
77
|
+
end
|
78
|
+
# Instances
|
79
|
+
# Get the master from the cloud
|
80
|
+
def master
|
81
|
+
# remote_instances_list.select {|a| a.master }.first
|
82
|
+
@list = list_from_remote
|
83
|
+
@list.reject {|a| a unless a.name =~ /master/ }.first if @list.class != String
|
84
|
+
end
|
85
|
+
# Helpers
|
86
|
+
def create_keypair
|
87
|
+
end
|
88
|
+
# Reset the cache of descriptions
|
89
|
+
def reset!
|
90
|
+
end
|
91
|
+
def self.included(other)
|
92
|
+
PoolParty.register_remote_base(self.class.to_s.downcase.to_sym)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Callback after loaded
|
96
|
+
def loaded_remoter_base
|
97
|
+
end
|
98
|
+
|
99
|
+
# Custom installation tasks
|
100
|
+
# Allow the remoter bases to attach their own tasks on the
|
101
|
+
# installation process
|
102
|
+
def custom_install_tasks_for(a=nil)
|
103
|
+
[]
|
104
|
+
end
|
105
|
+
# Custom configure tasks
|
106
|
+
# Allows the remoter bases to attach their own
|
107
|
+
# custom configuration tasks to the configuration process
|
108
|
+
def custom_configure_tasks_for(a=nil)
|
109
|
+
[]
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
Dir["#{File.dirname(__FILE__)}/remote_bases/*.rb"].each {|base| require base }
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module PoolParty
|
2
|
+
class Gem
|
3
|
+
|
4
|
+
virtual_resource(:gempackage) do
|
5
|
+
|
6
|
+
def loaded(opts={})
|
7
|
+
has_exec(:name => "gem-package-#{name}", :cwd => "/tmp", :path => "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/var/lib/gems/1.8/bin") do
|
8
|
+
command "gem install -y --no-ri --no-rdoc #{"--version \"#{version}\"" if @parent.version} #{"--source #{@parent.source}" if @parent.source} #{@parent.name}"
|
9
|
+
ifnot "gem list --local #{@parent.name} | grep #{@parent.name} #{"| grep #{@parent.version}" if @parent.version}"
|
10
|
+
requires "Package['rubygems']"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module PoolParty
|
2
|
+
class Git
|
3
|
+
|
4
|
+
virtual_resource(:git) do
|
5
|
+
|
6
|
+
def loaded(opts={})
|
7
|
+
install_git
|
8
|
+
has_git_repos
|
9
|
+
end
|
10
|
+
|
11
|
+
def install_git
|
12
|
+
has_package(:name => "git-core")
|
13
|
+
end
|
14
|
+
|
15
|
+
def has_git_repos
|
16
|
+
with_options(:requires => 'Package["git-core"]') do
|
17
|
+
has_directory(:name => "#{path}")
|
18
|
+
|
19
|
+
exec({:name => "git-#{name}"}) do
|
20
|
+
command @parent.user ? "git clone #{@parent.user}@#{@parent.source} #{@parent.path}" : "git clone #{@parent.source} #{@parent.path}"
|
21
|
+
cwd "#{::File.dirname(@parent.path) if @parent.path}"
|
22
|
+
creates ["#{@parent.path}", "#{@parent.path}/.git"]
|
23
|
+
end
|
24
|
+
|
25
|
+
exec(:name => "git-update-#{name}", :cwd => "#{path}") do
|
26
|
+
command "git pull"
|
27
|
+
requires "Exec['git-#{@parent.name}']"
|
28
|
+
end
|
29
|
+
|
30
|
+
if symlink
|
31
|
+
has_file(:name => "#{symlink}") do
|
32
|
+
ensures @parent.path
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module PoolParty
|
2
|
+
class Line
|
3
|
+
|
4
|
+
define_resource(:line_in_file) do
|
5
|
+
# Should refactor
|
6
|
+
def has_line_in_file(line="line_in_file", file="file", opts={})
|
7
|
+
call_function <<-EOE
|
8
|
+
line {
|
9
|
+
'#{file}_line' :
|
10
|
+
file => '#{file}',
|
11
|
+
line => '#{line}',
|
12
|
+
#{opts.flush_out("\t", ",")}
|
13
|
+
ensure => 'present'
|
14
|
+
}
|
15
|
+
EOE
|
16
|
+
end
|
17
|
+
|
18
|
+
def append_if_no_such_line(line="line", file="", refreshonly='false')
|
19
|
+
call_function <<-EOE
|
20
|
+
append_if_no_such_line {
|
21
|
+
'#{file}' :
|
22
|
+
file => '#{file}',
|
23
|
+
line => '#{line}',
|
24
|
+
refreshonly => #{refreshonly}
|
25
|
+
}
|
26
|
+
EOE
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete_lines_from(file="", pattern=//)
|
30
|
+
call_function <<-EOE
|
31
|
+
delete_lines {
|
32
|
+
'#{file}' :
|
33
|
+
file => '#{file}',
|
34
|
+
pattern => '#{pattern}'
|
35
|
+
}
|
36
|
+
EOE
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
custom_function <<-EOF
|
41
|
+
define line($file, $line, $ensure = 'present', $notify=[]) {
|
42
|
+
case $ensure {
|
43
|
+
default: { err ( "unknown ensure value ${ensure}" ) }
|
44
|
+
present: {
|
45
|
+
exec {
|
46
|
+
"/usr/bin/env echo '${line}' >> '${file}'": unless => "/usr/bin/env grep -qFx '${line}' '${file}'",
|
47
|
+
notify => $notify
|
48
|
+
}
|
49
|
+
}
|
50
|
+
absent: {
|
51
|
+
exec {
|
52
|
+
"/usr/bin/env sed -i '' -e '/^${line}\$/d' '${file}'": onlyif => "/usr/bin/env grep -qFx '${line}' '${file}'",
|
53
|
+
notify => $notify
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
define append_if_no_such_line($file, $line, $refreshonly = 'false') {
|
59
|
+
exec { "/bin/echo '$line' >> '$file'":
|
60
|
+
unless => "/bin/grep -Fxqe '$line' '$file'",
|
61
|
+
path => "/bin",
|
62
|
+
refreshonly => $refreshonly,
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
define delete_lines($file, $pattern) {
|
67
|
+
exec { "sed -i -r -e '/$pattern/d' $file":
|
68
|
+
path => "/bin",
|
69
|
+
onlyif => "/bin/grep -E '$pattern' '$file'",
|
70
|
+
}
|
71
|
+
}
|
72
|
+
EOF
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module PoolParty
|
2
|
+
class Svn
|
3
|
+
|
4
|
+
define_resource(:svn) do
|
5
|
+
|
6
|
+
def has_svnpath(opts={})
|
7
|
+
call_function <<-EOE
|
8
|
+
svnserve { #{opts[:name]}:
|
9
|
+
source => "#{opts[:source]}",
|
10
|
+
path => "#{opts[:path]}",
|
11
|
+
user => "#{opts[:user] || false}",
|
12
|
+
password => "#{opts[:password] || ""}"
|
13
|
+
}
|
14
|
+
EOE
|
15
|
+
end
|
16
|
+
|
17
|
+
custom_function <<-EOF
|
18
|
+
# Serve subversion-based code from a local location. The job of this
|
19
|
+
# module is to check the data out from subversion and keep it up to
|
20
|
+
# date, especially useful for providing data to your Puppet server.
|
21
|
+
define svnserve($source, $path, $user = false, $password = false) {
|
22
|
+
file { $path:
|
23
|
+
ensure => directory,
|
24
|
+
owner => root,
|
25
|
+
group => root
|
26
|
+
}
|
27
|
+
$svncmd = $user ? {
|
28
|
+
false => "/usr/bin/svn co --non-interactive $source/$name .",
|
29
|
+
default => "/usr/bin/svn co --non-interactive --username $user --password '$password' $source/$name ."
|
30
|
+
}
|
31
|
+
exec { "svnco-$name":
|
32
|
+
command => $svncmd,
|
33
|
+
cwd => $path,
|
34
|
+
require => File[$path],
|
35
|
+
creates => "$path/.svn"
|
36
|
+
}
|
37
|
+
exec { "svnupdate-$name":
|
38
|
+
command => "/usr/bin/svn update",
|
39
|
+
require => Exec["svnco-$name"],
|
40
|
+
onlyif => '/usr/bin/svn status -u --non-interactive | /bin/grep "\*"',
|
41
|
+
cwd => $path
|
42
|
+
}
|
43
|
+
}
|
44
|
+
EOF
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
Base
|
3
|
+
This handles user interaction, loading the parameters, etc.
|
4
|
+
=end
|
5
|
+
require "open-uri"
|
6
|
+
require "ftools"
|
7
|
+
module PoolParty
|
8
|
+
class Base
|
9
|
+
include Configurable
|
10
|
+
extend MethodMissingSugar
|
11
|
+
|
12
|
+
default_options({
|
13
|
+
:environment => "production",
|
14
|
+
:user => "root", # This should change here
|
15
|
+
:base_keypair_path => "~/.ec2",
|
16
|
+
:tmp_path => "tmp",
|
17
|
+
:remote_storage_path => "/var/poolparty",
|
18
|
+
:storage_directory => File.join(Dir.pwd, "tmp"),
|
19
|
+
:fileserver_base => "puppet:///files",
|
20
|
+
:base_config_directory => "/etc/poolparty",
|
21
|
+
:template_directory => "tmp/templates",
|
22
|
+
:template_path => "/var/lib/puppet/templates",
|
23
|
+
:default_specfile_name => "pool.spec",
|
24
|
+
:port => "80",
|
25
|
+
:forwarding_port => "8080",
|
26
|
+
:proxy_mode => "http",
|
27
|
+
:pool_logger_location => File.join(Dir.pwd, "logs"),
|
28
|
+
# EC2 Options
|
29
|
+
:ami => "ami-1cd73375"
|
30
|
+
})
|
31
|
+
|
32
|
+
# Class methods
|
33
|
+
class << self
|
34
|
+
def options(h={})
|
35
|
+
@options ||= default_options.merge(h)
|
36
|
+
end
|
37
|
+
# Get the access_key
|
38
|
+
def access_key
|
39
|
+
ENV["AWS_ACCESS_KEY_ID"] ? ENV["AWS_ACCESS_KEY_ID"] : load_keys_from_file[:access_key]
|
40
|
+
end
|
41
|
+
def secret_access_key
|
42
|
+
ENV["AWS_SECRET_ACCESS_ID"] ? ENV["AWS_SECRET_ACCESS_ID"] : load_keys_from_file[:secret_access_key]
|
43
|
+
end
|
44
|
+
def load_keys_from_file
|
45
|
+
@keys ||= get_working_key_file_locations ? YAML::load( open(get_working_key_file_locations).read ) : {}
|
46
|
+
end
|
47
|
+
# Store the keys in a yaml format to give the master access
|
48
|
+
# So that the master has access to the files
|
49
|
+
def store_keys_in_file
|
50
|
+
unless access_key.nil? || secret_access_key.nil?
|
51
|
+
write_to_file( key_file_locations.first, YAML::dump({:access_key => access_key, :secret_access_key => secret_access_key}))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
def reset!
|
55
|
+
@keys = nil
|
56
|
+
end
|
57
|
+
# Get the instance first instance file that exists on the system from the expected places
|
58
|
+
# denoted in the local_instances_list_file_locations
|
59
|
+
def get_working_key_file_locations
|
60
|
+
key_file_locations.reject {|f| f unless ::File.file?(f) }.first
|
61
|
+
end
|
62
|
+
# Expected places for the instances.list to be located at on the machine
|
63
|
+
def key_file_locations
|
64
|
+
[
|
65
|
+
".ppkeys",
|
66
|
+
"#{Base.base_config_directory}/.ppkeys",
|
67
|
+
"#{Base.storage_directory}/ppkeys",
|
68
|
+
"~/.ppkeys",
|
69
|
+
"ppkeys"
|
70
|
+
]
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/plugin_model"
|
2
|
+
require File.dirname(__FILE__) + "/resource"
|
3
|
+
|
4
|
+
module PoolParty
|
5
|
+
module Cloud
|
6
|
+
def cloud(name=:main, &block)
|
7
|
+
clouds.has_key?(name) ? clouds[name] : (clouds[name] = Cloud.new(name, self, &block))
|
8
|
+
end
|
9
|
+
|
10
|
+
def clouds
|
11
|
+
$clouds ||= {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def with_cloud(cl, opts={}, &block)
|
15
|
+
cl.options.merge!(opts)
|
16
|
+
cl.instance_eval &block if block
|
17
|
+
end
|
18
|
+
|
19
|
+
class Cloud
|
20
|
+
attr_reader :name, :templates
|
21
|
+
include PoolParty::PluginModel
|
22
|
+
include PoolParty::Resources
|
23
|
+
include PrettyPrinter
|
24
|
+
include Configurable
|
25
|
+
include CloudResourcer
|
26
|
+
# extend CloudResourcer
|
27
|
+
# Net methods
|
28
|
+
include PoolParty::Remote::RemoterBase
|
29
|
+
include Remote
|
30
|
+
|
31
|
+
default_options({
|
32
|
+
:minimum_instances => 2,
|
33
|
+
:maximum_instances => 4,
|
34
|
+
:access_key => Base.access_key,
|
35
|
+
:secret_access_key => Base.secret_access_key,
|
36
|
+
:ec2_dir => ENV["EC2_HOME"],
|
37
|
+
:keypair => (ENV["KEYPAIR_NAME"].nil? || ENV["KEYPAIR_NAME"].empty?) ? nil : ENV["KEYPAIR_NAME"],
|
38
|
+
:ami => 'ami-44bd592d',
|
39
|
+
:polling_time => "30.seconds"
|
40
|
+
})
|
41
|
+
|
42
|
+
def initialize(name, parent, &block)
|
43
|
+
@name = name
|
44
|
+
# store_block(&block)
|
45
|
+
set_parent(parent) if parent
|
46
|
+
self.instance_eval &block if block
|
47
|
+
# this can be overridden in the spec, but ec2 is the default
|
48
|
+
self.using :ec2
|
49
|
+
end
|
50
|
+
|
51
|
+
# Keypairs
|
52
|
+
# If the parent (pool) doesn't have a keypair defined on it, then generate one based on the
|
53
|
+
# pool_name and the cloud_name
|
54
|
+
def keypair(*args)
|
55
|
+
has_keypair? ? options[:keypair] : generate_keypair(*args)
|
56
|
+
end
|
57
|
+
def has_keypair?
|
58
|
+
options.has_key?(:keypair) && options[:keypair]
|
59
|
+
end
|
60
|
+
def generate_keypair(*args)
|
61
|
+
options[:keypair] = args.length > 0 ? args[0] : "#{@parent.respond_to?(:name) ? @parent.name : ""}_#{@name}"
|
62
|
+
end
|
63
|
+
|
64
|
+
# Prepare to send the new configuration to the instances
|
65
|
+
# First, let's make sure that our base directory is made
|
66
|
+
# Then copy the templates that have no other reference in
|
67
|
+
# a spec file. Make sure the keys are stored in a file
|
68
|
+
# For the master to have access to them
|
69
|
+
# Then, send the saved containing cloud instances to give the
|
70
|
+
# remote master access to the cloud options that are required
|
71
|
+
# for the master to run checks
|
72
|
+
def prepare_to_configuration
|
73
|
+
# clear_base_directory
|
74
|
+
make_base_directory
|
75
|
+
copy_misc_templates
|
76
|
+
Base.store_keys_in_file
|
77
|
+
Script.save!
|
78
|
+
copy_ssh_key # not my favorite...
|
79
|
+
end
|
80
|
+
|
81
|
+
def copy_ssh_key
|
82
|
+
copy_file_to_storage_directory(full_keypair_path)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Build the new poolparty manifest
|
86
|
+
# Wrapping all of these requirements into the one
|
87
|
+
# poolparty class.
|
88
|
+
#
|
89
|
+
# TODO: Consider the benefits of moving all the manifest
|
90
|
+
# classes to separate files and keeping the containing
|
91
|
+
# references in the include
|
92
|
+
def build_and_store_new_config_file
|
93
|
+
@manifest = build_manifest
|
94
|
+
config_file = ::File.join(Base.storage_directory, "poolparty.pp")
|
95
|
+
::File.open(config_file, "w+") do |file|
|
96
|
+
file << "class poolparty {"
|
97
|
+
file << @manifest
|
98
|
+
file << "}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def copy_misc_templates
|
103
|
+
["fileserver.conf", "namespaceauth.conf"].each do |f|
|
104
|
+
copy_file_to_storage_directory(::File.join(::File.dirname(__FILE__), "..", "templates", f))
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# Configuration files
|
109
|
+
def build_manifest
|
110
|
+
unless @build_manifest
|
111
|
+
reset_resources!
|
112
|
+
add_poolparty_base_requirements
|
113
|
+
|
114
|
+
@build_manifest = returning Array.new do |str|
|
115
|
+
|
116
|
+
str << resources_string_from_resources(resources)
|
117
|
+
|
118
|
+
# Refactor this into the resources method
|
119
|
+
# TODO
|
120
|
+
services.each do |service|
|
121
|
+
@cp = classpackage_with_self(service)
|
122
|
+
str << @cp.to_string
|
123
|
+
str << @cp.include_string
|
124
|
+
end
|
125
|
+
|
126
|
+
str << "# Custom functions"
|
127
|
+
str << Resources::CustomResource.custom_functions_to_string
|
128
|
+
end.join("\n")
|
129
|
+
end
|
130
|
+
@build_manifest
|
131
|
+
end
|
132
|
+
|
133
|
+
# To allow the remote instances to do their job,
|
134
|
+
# they need a few options to run, these are the required options
|
135
|
+
# to be saved on the remote "master" machine
|
136
|
+
def minimum_runnable_options
|
137
|
+
[:keypair, :minimum_instances, :maximum_instances]
|
138
|
+
end
|
139
|
+
|
140
|
+
# Add all the poolparty requirements here
|
141
|
+
# NOTE: These are written as plugins in the lib/poolparty/base_packages directory
|
142
|
+
# for examples.
|
143
|
+
# Also note that there is no block associated. This is because we have written
|
144
|
+
# all that is necessary in a method called enable
|
145
|
+
# which is called when there is no block
|
146
|
+
def add_poolparty_base_requirements
|
147
|
+
heartbeat
|
148
|
+
haproxy
|
149
|
+
ruby
|
150
|
+
poolparty
|
151
|
+
end
|
152
|
+
|
153
|
+
# Add to the services pool for the manifest listing
|
154
|
+
def add_service(serv)
|
155
|
+
services << serv
|
156
|
+
end
|
157
|
+
# Container for the services
|
158
|
+
def services
|
159
|
+
@services ||= []
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|