poolparty 0.0.4 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,136 @@
|
|
|
1
|
+
module PoolParty
|
|
2
|
+
module Provisioner
|
|
3
|
+
class Master < ProvisionerBase
|
|
4
|
+
|
|
5
|
+
def initialize(cloud=self, os=:ubuntu)
|
|
6
|
+
super(cloud.master, cloud, os)
|
|
7
|
+
@master_ip = cloud.master.ip
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def valid?
|
|
11
|
+
!(@cloud.nil? || @cloud.master.nil?)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def error
|
|
15
|
+
raise RemoteException.new(:could_not_install, "Your cloud does not have a master")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def install_tasks
|
|
19
|
+
[
|
|
20
|
+
install_haproxy,
|
|
21
|
+
install_heartbeat,
|
|
22
|
+
create_local_hosts_entry,
|
|
23
|
+
setup_basic_structure,
|
|
24
|
+
setup_configs,
|
|
25
|
+
setup_fileserver,
|
|
26
|
+
setup_autosigning,
|
|
27
|
+
] << configure_tasks
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def configure_tasks
|
|
31
|
+
[
|
|
32
|
+
start_puppetmaster,
|
|
33
|
+
create_local_node,
|
|
34
|
+
move_templates,
|
|
35
|
+
create_poolparty_manifest,
|
|
36
|
+
restart_puppetd
|
|
37
|
+
]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# def install_haproxy
|
|
41
|
+
# "#{installer_for( "haproxy" )}"
|
|
42
|
+
# end
|
|
43
|
+
#
|
|
44
|
+
# def install_heartbeat
|
|
45
|
+
# "#{installer_for( "heartbeat-2" )}"
|
|
46
|
+
# end
|
|
47
|
+
|
|
48
|
+
def create_local_hosts_entry
|
|
49
|
+
<<-EOS
|
|
50
|
+
if [ -z \"$(grep -v '#' /etc/hosts | grep 'master')" ]; then echo '#{@master_ip} puppet master' >> /etc/hosts; fi
|
|
51
|
+
EOS
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def setup_basic_structure
|
|
55
|
+
<<-EOS
|
|
56
|
+
puppetmasterd --mkusers
|
|
57
|
+
mkdir -p #{Base.remote_storage_path}
|
|
58
|
+
echo "import 'nodes/*.pp'" > /etc/puppet/manifests/site.pp
|
|
59
|
+
echo "import 'classes/*.pp'" >> /etc/puppet/manifests/site.pp
|
|
60
|
+
mkdir -p /etc/puppet/manifests/nodes
|
|
61
|
+
mkdir -p /etc/puppet/manifests/classes
|
|
62
|
+
mv #{Base.remote_storage_path}/#{Base.tmp_path}/namespaceauth.conf /etc/puppet/namespaceauth.conf
|
|
63
|
+
EOS
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def setup_configs
|
|
67
|
+
<<-EOS
|
|
68
|
+
echo "#{open(File.join(template_directory, "puppet.conf")).read}" > /etc/puppet/puppet.conf
|
|
69
|
+
EOS
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def setup_fileserver
|
|
73
|
+
<<-EOS
|
|
74
|
+
echo "
|
|
75
|
+
[files]
|
|
76
|
+
path #{Base.remote_storage_path}/#{Base.tmp_path}
|
|
77
|
+
allow *" > /etc/puppet/fileserver.conf
|
|
78
|
+
mkdir -p /var/poolparty/facts
|
|
79
|
+
mkdir -p /var/poolparty/files
|
|
80
|
+
mkdir -p /etc/poolparty
|
|
81
|
+
EOS
|
|
82
|
+
end
|
|
83
|
+
# Change this eventually for better security supportsetup_fileserver
|
|
84
|
+
def setup_autosigning
|
|
85
|
+
<<-EOS
|
|
86
|
+
echo "*" > /etc/puppet/autosign.conf
|
|
87
|
+
EOS
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def create_local_node
|
|
91
|
+
str = <<-EOS
|
|
92
|
+
node default {
|
|
93
|
+
include poolparty
|
|
94
|
+
}
|
|
95
|
+
EOS
|
|
96
|
+
@cloud.list_of_running_instances.each do |ri|
|
|
97
|
+
str << <<-EOS
|
|
98
|
+
node "#{ri.name}" inherits default {}
|
|
99
|
+
EOS
|
|
100
|
+
end
|
|
101
|
+
"echo '#{str}' > /etc/puppet/manifests/nodes/nodes.pp"
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def move_templates
|
|
105
|
+
<<-EOS
|
|
106
|
+
mkdir -p #{Base.template_path}
|
|
107
|
+
mv #{Base.remote_storage_path}/#{Base.template_directory}/* #{Base.template_path}
|
|
108
|
+
EOS
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def create_poolparty_manifest
|
|
112
|
+
<<-EOS
|
|
113
|
+
mv #{Base.remote_storage_path}/#{Base.tmp_path}/poolparty.pp /etc/puppet/manifests/classes/poolparty.pp
|
|
114
|
+
mv #{Base.remote_storage_path}/#{Base.tmp_path}/#{Base.key_file_locations.first} "#{Base.base_config_directory}/.ppkeys"
|
|
115
|
+
mv #{Base.remote_storage_path}/#{Base.tmp_path}/#{Base.default_specfile_name} #{Base.base_config_directory}/#{Base.default_specfile_name}
|
|
116
|
+
mv #{Base.remote_storage_path}/#{Base.tmp_path}/#{@cloud.full_keypair_name} #{@cloud.remote_keypair_path}
|
|
117
|
+
EOS
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def start_puppetmaster
|
|
121
|
+
<<-EOS
|
|
122
|
+
ps aux | grep puppetmasterd | awk '{print $2}' | xargs kill
|
|
123
|
+
rm -rf /etc/puppet/ssl
|
|
124
|
+
puppetmasterd
|
|
125
|
+
EOS
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def restart_puppetd
|
|
129
|
+
<<-EOS
|
|
130
|
+
puppetd --listen --fqdn=#{@instance.name} --server=master
|
|
131
|
+
puppetrun --host #{@instance.name}
|
|
132
|
+
EOS
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module PoolParty
|
|
2
|
+
module Provisioner
|
|
3
|
+
class Slave < ProvisionerBase
|
|
4
|
+
|
|
5
|
+
def install_tasks
|
|
6
|
+
[
|
|
7
|
+
setup_puppet
|
|
8
|
+
] << configure_tasks
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def configure_tasks
|
|
12
|
+
[
|
|
13
|
+
setup_configs,
|
|
14
|
+
start_puppet
|
|
15
|
+
]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def setup_puppet
|
|
19
|
+
<<-EOE
|
|
20
|
+
puppetd --mkusers
|
|
21
|
+
if [ -z "$(grep -v '#' /etc/hosts | grep 'master')" ]; then echo "#{master_ip} puppet master" >> /etc/hosts; else echo "host already set"; fi
|
|
22
|
+
mv #{Base.remote_storage_path}/#{Base.tmp_path}/namespaceauth.conf /etc/puppet/namespaceauth.conf
|
|
23
|
+
EOE
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def setup_configs
|
|
27
|
+
<<-EOS
|
|
28
|
+
echo "#{open(File.join(template_directory, "puppet.conf")).read}" > /etc/puppet/puppet.conf
|
|
29
|
+
EOS
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def start_puppet
|
|
33
|
+
<<-EOS
|
|
34
|
+
puppetd --listen --fqdn=#{@instance.name}
|
|
35
|
+
EOS
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def master_ip
|
|
39
|
+
@cloud.master.ip
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
require "ftools"
|
|
2
|
+
|
|
3
|
+
module PoolParty
|
|
4
|
+
module CloudResourcer
|
|
5
|
+
|
|
6
|
+
# Store block
|
|
7
|
+
def store_block(&block)
|
|
8
|
+
@store_block ||= block
|
|
9
|
+
end
|
|
10
|
+
# Set instances with a range
|
|
11
|
+
def instances(arg)
|
|
12
|
+
if arg.is_a?(Range)
|
|
13
|
+
minimum_instances arg.first
|
|
14
|
+
maximum_instances arg.last
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def full_keypair_path
|
|
19
|
+
unless keypair_path
|
|
20
|
+
raise RuntimeException.new("Keypair cannot be found")
|
|
21
|
+
else
|
|
22
|
+
::File.expand_path(keypair_path)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def keypair_path
|
|
27
|
+
keypair_paths.each do |path|
|
|
28
|
+
possible_keypair_basenames.each do |base|
|
|
29
|
+
full_path = ::File.join( File.expand_path(path), "#{base}#{keypair}")
|
|
30
|
+
return full_path if ::File.exists?(full_path)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
return nil
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def full_keypair_name
|
|
37
|
+
keypair_paths.each do |path|
|
|
38
|
+
possible_keypair_basenames.each do |base|
|
|
39
|
+
full_path = ::File.join( File.expand_path(path), "#{base}#{keypair}")
|
|
40
|
+
return "#{base}#{keypair}" if ::File.exists?(full_path)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
return nil
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def remote_keypair_path
|
|
47
|
+
::File.join( keypair_paths.last, "#{possible_keypair_basenames.first}#{keypair}" )
|
|
48
|
+
end
|
|
49
|
+
def new_keypair_path
|
|
50
|
+
::File.join( keypair_paths.first, "#{possible_keypair_basenames.first}#{keypair}" )
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def possible_keypair_basenames
|
|
54
|
+
[
|
|
55
|
+
"id_rsa-",
|
|
56
|
+
""
|
|
57
|
+
]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def keypair_paths
|
|
61
|
+
[
|
|
62
|
+
Base.base_keypair_path,
|
|
63
|
+
Base.base_config_directory,
|
|
64
|
+
Base.remote_storage_path
|
|
65
|
+
]
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Set the parent on the resource
|
|
69
|
+
def set_parent(pare, sink_options=true)
|
|
70
|
+
@parent = pare
|
|
71
|
+
# Add self as a service on the parent
|
|
72
|
+
pare.add_service(self) if pare.respond_to?(:add_service)
|
|
73
|
+
# Take the options of the parents
|
|
74
|
+
configure(pare.options) if pare.respond_to?(:options) && sink_options
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def number_of_resources
|
|
78
|
+
arr = resources.map do |n, r|
|
|
79
|
+
r.size
|
|
80
|
+
end
|
|
81
|
+
resources.map {|n,r| r.size}.inject(0){|sum,i| sum+=i}
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def parent
|
|
85
|
+
@parent ||= nil
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module PoolParty
|
|
2
|
+
module Configurable
|
|
3
|
+
module ClassMethods
|
|
4
|
+
def default_options(h={})
|
|
5
|
+
@default_options ||= h
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
module InstanceMethods
|
|
10
|
+
def options(h={})
|
|
11
|
+
@options ||= self.class.default_options.merge(h)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def configure(h={})
|
|
15
|
+
options(h).merge!(h)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def reconfigure(h={})
|
|
19
|
+
@options = nil
|
|
20
|
+
options(h)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def set_vars_from_options(opts={})
|
|
24
|
+
opts.each {|k,v| self.send k.to_sym, v } unless opts.empty?
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.included(receiver)
|
|
29
|
+
receiver.extend ClassMethods
|
|
30
|
+
receiver.send :include, InstanceMethods
|
|
31
|
+
receiver.send :include, MethodMissingSugar
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module PoolParty
|
|
2
|
+
module DefinableResource
|
|
3
|
+
# Define a new resource that can be called like any other resource
|
|
4
|
+
# Similar to any other resource (like file or exec)
|
|
5
|
+
# but you define it how you want it to work
|
|
6
|
+
# Example:
|
|
7
|
+
#
|
|
8
|
+
# define_resource(:line_in_file) do
|
|
9
|
+
# end
|
|
10
|
+
#
|
|
11
|
+
# Within the block, you can define any methods you want to run as
|
|
12
|
+
# part of the resource
|
|
13
|
+
#
|
|
14
|
+
# One thing to note is that this is NOT like other resources in the sense
|
|
15
|
+
# that it does not give you any extra methods like the resources do
|
|
16
|
+
#
|
|
17
|
+
# For example usage, see lib/poolparty/plugins/line.rb
|
|
18
|
+
def define_resource(name, &block)
|
|
19
|
+
symc = "#{name}".classify
|
|
20
|
+
klass = symc.class_constant(PoolParty::Resources::CustomResource, {:preserve => true}, &block)
|
|
21
|
+
PoolParty::Resources.module_eval &block
|
|
22
|
+
klass
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Allow us to create virtual resources
|
|
26
|
+
# Generally, in plugins
|
|
27
|
+
# This sets a virtual resource against the Resource class
|
|
28
|
+
# Example:
|
|
29
|
+
#
|
|
30
|
+
# virtual_resource(:virtualhost) do
|
|
31
|
+
# end
|
|
32
|
+
#
|
|
33
|
+
# This defines a virtualhost as a virtual resource
|
|
34
|
+
# and consequently gives the methods has_virtualhost and does_not_have_virtualhost
|
|
35
|
+
#
|
|
36
|
+
# Note that you can define any resources within the virtual resource
|
|
37
|
+
# within the definition or the call.
|
|
38
|
+
# Call example:
|
|
39
|
+
# has_virtualhost do
|
|
40
|
+
# name "xnot.org"
|
|
41
|
+
# end
|
|
42
|
+
#
|
|
43
|
+
# Which sets the virtual host's name as xnot.org
|
|
44
|
+
#
|
|
45
|
+
# An example is included in the poolparty-apache-plugin
|
|
46
|
+
def virtual_resource(name=:virtual_resource, opts={}, &block)
|
|
47
|
+
symc = "#{name}".classify
|
|
48
|
+
eval <<-EOE
|
|
49
|
+
class PoolParty::Resources::#{symc} < PoolParty::Resources::Resource
|
|
50
|
+
end
|
|
51
|
+
EOE
|
|
52
|
+
klass = "PoolParty::Resources::#{symc}".constantize
|
|
53
|
+
klass.module_eval &block if block
|
|
54
|
+
klass.send :define_method, :virtual_resource?, Proc.new{true}
|
|
55
|
+
klass
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module PoolParty
|
|
2
|
+
module FileWriter
|
|
3
|
+
def copy_file_to_storage_directory(file)
|
|
4
|
+
make_base_directory
|
|
5
|
+
path = ::File.join( Base.storage_directory, ::File.basename(file) )
|
|
6
|
+
FileUtils.cp file, path
|
|
7
|
+
end
|
|
8
|
+
def copy_template_to_storage_directory(file)
|
|
9
|
+
make_template_directory
|
|
10
|
+
path = ::File.join( Base.template_directory, ::File.basename(file) )
|
|
11
|
+
FileUtils.cp file, path
|
|
12
|
+
end
|
|
13
|
+
def write_to_file_in_storage_directory(file, str, &block)
|
|
14
|
+
path = ::File.join( Base.storage_directory, ::File.basename(file) )
|
|
15
|
+
write_to_file(path, str, &block)
|
|
16
|
+
end
|
|
17
|
+
def write_to_file(file, str, &block)
|
|
18
|
+
path = ::File.join( Base.storage_directory, ::File.basename(file) )
|
|
19
|
+
make_base_path( Base.storage_directory )
|
|
20
|
+
::File.open(path, "w+") do |f|
|
|
21
|
+
f.print str
|
|
22
|
+
f.flush
|
|
23
|
+
f.print block.call(f) if block
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
# Write a temp file with the content str and return the Tempfile
|
|
27
|
+
# It creates a random file name
|
|
28
|
+
def write_to_temp_file(str="", &block)
|
|
29
|
+
returning Tempfile.new("#{Base.storage_directory}/PoolParty-#{str[0..10].chomp}-#{rand(1000)}") do |fp|
|
|
30
|
+
fp.print str
|
|
31
|
+
fp.flush
|
|
32
|
+
block.call(fp)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
def make_base_path(path)
|
|
36
|
+
unless FileTest.directory?(path)
|
|
37
|
+
begin
|
|
38
|
+
::FileUtils.mkdir_p path
|
|
39
|
+
rescue Errno::ENOTDIR
|
|
40
|
+
rescue Errno::EEXIST
|
|
41
|
+
puts "There was an error"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
def make_base_directory
|
|
46
|
+
FileUtils.mkdir_p Base.storage_directory unless ::File.directory?(Base.storage_directory)
|
|
47
|
+
end
|
|
48
|
+
def make_template_directory
|
|
49
|
+
FileUtils.mkdir_p Base.template_directory unless ::File.directory?(Base.template_directory)
|
|
50
|
+
end
|
|
51
|
+
def clear_base_directory
|
|
52
|
+
FileUtils::rm_rf "#{Base.storage_directory}"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
=begin rdoc
|
|
2
|
+
Using method missing gives us the ability to set any attribute on the object into the options
|
|
3
|
+
such that it can be retrieved later
|
|
4
|
+
=end
|
|
5
|
+
module PoolParty
|
|
6
|
+
module MethodMissingSugar
|
|
7
|
+
# Method_Missing
|
|
8
|
+
# When a method cannot be found on the current object
|
|
9
|
+
# it is sent to method_missing
|
|
10
|
+
# First, we check if there is a block given and if the block
|
|
11
|
+
# is given with a class of the same type, then it is a block to be evaluated on
|
|
12
|
+
# itself, so we instantiate it here, otherwise, don't handle it here and let
|
|
13
|
+
# the super class worry about it.
|
|
14
|
+
# If the block is not given, then we are going to look for it on the
|
|
15
|
+
# options of itself or its parent.
|
|
16
|
+
# See get_from_options for more information
|
|
17
|
+
def method_missing(m, *args, &block)
|
|
18
|
+
if block_given?
|
|
19
|
+
(args[0].class == self.class) ? args[0].instance_eval(&block) : super
|
|
20
|
+
else
|
|
21
|
+
get_from_options(m, *args, &block)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Get the method from the options
|
|
26
|
+
# First, we check to see if any options are being sent to the method
|
|
27
|
+
# of the form:
|
|
28
|
+
# name "Fred"
|
|
29
|
+
# If there are args sent to it, check to see if it is an array
|
|
30
|
+
# If it is, we want to send it an array only if the array is contains more than one element.
|
|
31
|
+
# This becomes important when we are building the manifest
|
|
32
|
+
# If it is not an array of more than one element, then we just send it the first of the args
|
|
33
|
+
# If there are no args sent to it, then we check to see if the method is already in the options
|
|
34
|
+
# which means we are retrieving the property
|
|
35
|
+
# of the form
|
|
36
|
+
# @cloud.name => @cloud.options[:name]
|
|
37
|
+
# Finally, if the method name is not in the options, then we check to make sure it's not set on the
|
|
38
|
+
# parent, we don't want the parent's set option and that the parent isnot itself and send it
|
|
39
|
+
# to the parent to handle. Otherwise, we'll say it's nil instead
|
|
40
|
+
def get_from_options(m, *args, &block)
|
|
41
|
+
if args.empty?
|
|
42
|
+
if options.has_key?(m)
|
|
43
|
+
options[m]
|
|
44
|
+
else
|
|
45
|
+
(parent.nil? || parent.class == self.class || !parent.respond_to?(:options)) ? nil : parent.send(m, *args, &block)
|
|
46
|
+
end
|
|
47
|
+
else
|
|
48
|
+
options[m] = (args.is_a?(Array) && args.size > 1) ? args : args[0]
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
end
|