auser-poolparty 0.1.2 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. data/History.txt +22 -0
  2. data/License.txt +20 -0
  3. data/README.txt +52 -0
  4. data/Rakefile +4 -109
  5. data/bin/cloud +31 -0
  6. data/bin/cloud-add-keypair +23 -0
  7. data/bin/cloud-configure +35 -0
  8. data/bin/cloud-contract +27 -0
  9. data/bin/cloud-expand +27 -0
  10. data/bin/cloud-list +32 -0
  11. data/bin/cloud-maintain +36 -0
  12. data/bin/cloud-provision +30 -0
  13. data/bin/cloud-reconfigure +24 -0
  14. data/bin/cloud-ssh +18 -0
  15. data/bin/cloud-start +29 -0
  16. data/bin/pool +23 -75
  17. data/bin/pool-console +12 -0
  18. data/bin/pool-describe +9 -0
  19. data/bin/pool-list +28 -0
  20. data/bin/pool-provision +34 -0
  21. data/bin/pool-spec +17 -0
  22. data/bin/pool-start +32 -0
  23. data/examples/basic.rb +20 -0
  24. data/examples/plugin_without_plugin_directory.rb +13 -0
  25. data/examples/poolparty.rb +12 -0
  26. data/examples/with_apache_plugin.rb +22 -0
  27. data/generators/poolspec/USAGE +5 -0
  28. data/generators/poolspec/poolspec_generator.rb +65 -0
  29. data/generators/poolspec/templates/pool_spec_template.erb +9 -0
  30. data/lib/erlang/eb_server.erl +27 -0
  31. data/lib/poolparty.rb +40 -116
  32. data/lib/poolparty/base_packages/haproxy.rb +41 -0
  33. data/lib/poolparty/base_packages/heartbeat.rb +43 -0
  34. data/lib/poolparty/base_packages/poolparty.rb +18 -0
  35. data/lib/poolparty/base_packages/ruby.rb +27 -0
  36. data/lib/poolparty/core/array.rb +24 -0
  37. data/lib/{core → poolparty/core}/exception.rb +0 -0
  38. data/lib/{core → poolparty/core}/float.rb +0 -0
  39. data/lib/poolparty/core/hash.rb +29 -0
  40. data/lib/poolparty/core/kernel.rb +34 -0
  41. data/lib/{core → poolparty/core}/module.rb +18 -0
  42. data/lib/poolparty/core/my_open_struct.rb +18 -0
  43. data/lib/poolparty/core/object.rb +54 -0
  44. data/lib/poolparty/core/proc.rb +2 -0
  45. data/lib/poolparty/core/string.rb +72 -0
  46. data/lib/poolparty/core/symbol.rb +8 -0
  47. data/lib/{core → poolparty/core}/time.rb +15 -0
  48. data/lib/poolparty/exceptions/RemoteException.rb +12 -0
  49. data/lib/poolparty/exceptions/ResourceException.rb +7 -0
  50. data/lib/poolparty/exceptions/RuntimeException.rb +7 -0
  51. data/lib/poolparty/exceptions/SpecException.rb +7 -0
  52. data/lib/poolparty/exceptions/TemplateNotFound.rb +7 -0
  53. data/lib/poolparty/helpers/binary.rb +30 -0
  54. data/lib/poolparty/helpers/console.rb +30 -0
  55. data/lib/poolparty/helpers/display.rb +25 -0
  56. data/lib/poolparty/helpers/optioner.rb +61 -0
  57. data/lib/poolparty/helpers/provisioner_base.rb +226 -0
  58. data/lib/poolparty/helpers/provisioners/master.rb +120 -0
  59. data/lib/poolparty/helpers/provisioners/slave.rb +52 -0
  60. data/lib/poolparty/modules/cloud_resourcer.rb +72 -0
  61. data/lib/poolparty/modules/configurable.rb +34 -0
  62. data/lib/poolparty/modules/definable_resource.rb +59 -0
  63. data/lib/poolparty/modules/file_writer.rb +55 -0
  64. data/lib/poolparty/modules/method_missing_sugar.rb +17 -0
  65. data/lib/poolparty/modules/output.rb +13 -0
  66. data/lib/poolparty/modules/pretty_printer.rb +38 -0
  67. data/lib/{core/string.rb → poolparty/modules/s3_string.rb} +5 -29
  68. data/lib/{modules → poolparty/modules}/safe_instance.rb +0 -0
  69. data/lib/poolparty/monitors/base_monitor.rb +16 -0
  70. data/lib/poolparty/net/remote.rb +35 -0
  71. data/lib/poolparty/net/remote_bases/ec2.rb +145 -0
  72. data/lib/poolparty/net/remote_instance.rb +68 -0
  73. data/lib/poolparty/net/remoter.rb +209 -0
  74. data/lib/poolparty/net/remoter_base.rb +117 -0
  75. data/lib/poolparty/plugins/gem_package.rb +39 -0
  76. data/lib/poolparty/plugins/line.rb +76 -0
  77. data/lib/poolparty/plugins/svn.rb +48 -0
  78. data/lib/poolparty/pool/base.rb +74 -0
  79. data/lib/poolparty/pool/cloud.rb +132 -0
  80. data/lib/poolparty/pool/custom_resource.rb +61 -0
  81. data/lib/poolparty/pool/loggable.rb +29 -0
  82. data/lib/poolparty/pool/plugin.rb +42 -0
  83. data/lib/poolparty/pool/plugin_model.rb +48 -0
  84. data/lib/poolparty/pool/pool.rb +55 -0
  85. data/lib/poolparty/pool/resource.rb +235 -0
  86. data/lib/poolparty/pool/resources/class_package.rb +60 -0
  87. data/lib/poolparty/pool/resources/cron.rb +14 -0
  88. data/lib/poolparty/pool/resources/directory.rb +23 -0
  89. data/lib/poolparty/pool/resources/exec.rb +26 -0
  90. data/lib/poolparty/pool/resources/file.rb +23 -0
  91. data/lib/poolparty/pool/resources/gem.rb +14 -0
  92. data/lib/poolparty/pool/resources/host.rb +14 -0
  93. data/lib/poolparty/pool/resources/package.rb +14 -0
  94. data/lib/poolparty/pool/resources/remote_file.rb +20 -0
  95. data/lib/poolparty/pool/resources/service.rb +21 -0
  96. data/lib/poolparty/pool/resources/sshkey.rb +19 -0
  97. data/lib/poolparty/pool/resources/variable.rb +27 -0
  98. data/lib/poolparty/pool/script.rb +21 -0
  99. data/{config/heartbeat_authkeys.conf → lib/poolparty/templates/authkeys} +0 -0
  100. data/lib/poolparty/templates/cib.xml +1 -0
  101. data/lib/poolparty/templates/fileserver.conf +4 -0
  102. data/{config/heartbeat.conf → lib/poolparty/templates/ha.cf} +3 -1
  103. data/{config → lib/poolparty/templates}/haproxy.conf +13 -6
  104. data/lib/poolparty/templates/namespaceauth.conf +19 -0
  105. data/lib/poolparty/templates/puppet.conf +13 -0
  106. data/lib/poolparty/version.rb +9 -0
  107. data/lib/poolpartycl.rb +3 -0
  108. data/script/destroy +14 -0
  109. data/script/generate +14 -0
  110. data/script/txt2html +82 -0
  111. data/{lib/poolparty/tasks → tasks}/cloud.rake +1 -1
  112. data/tasks/deployment.rake +34 -0
  113. data/tasks/development.rake +78 -0
  114. data/{lib/poolparty/tasks → tasks}/ec2.rake +1 -1
  115. data/tasks/environment.rake +7 -0
  116. data/{lib/poolparty/tasks → tasks}/instance.rake +0 -0
  117. data/{lib/poolparty/tasks → tasks}/server.rake +0 -0
  118. data/tasks/spec.rake +17 -0
  119. data/tasks/website.rake +17 -0
  120. metadata +154 -249
  121. data/CHANGELOG +0 -23
  122. data/LICENSE +0 -22
  123. data/README +0 -139
  124. data/assets/clouds.png +0 -0
  125. data/bin/instance +0 -68
  126. data/bin/poolnotify +0 -34
  127. data/config/cloud_master_takeover +0 -17
  128. data/config/create_proxy_ami.sh +0 -582
  129. data/config/installers/ubuntu_install.sh +0 -77
  130. data/config/monit.conf +0 -9
  131. data/config/monit/haproxy.monit.conf +0 -8
  132. data/config/monit/nginx.monit.conf +0 -0
  133. data/config/nginx.conf +0 -24
  134. data/config/reconfigure_instances_script.sh +0 -37
  135. data/config/sample-config.yml +0 -23
  136. data/config/scp_instances_script.sh +0 -12
  137. data/lib/core/array.rb +0 -16
  138. data/lib/core/hash.rb +0 -11
  139. data/lib/core/kernel.rb +0 -12
  140. data/lib/core/object.rb +0 -21
  141. data/lib/core/proc.rb +0 -15
  142. data/lib/helpers/plugin_spec_helper.rb +0 -58
  143. data/lib/modules/callback.rb +0 -133
  144. data/lib/modules/ec2_wrapper.rb +0 -108
  145. data/lib/modules/file_writer.rb +0 -38
  146. data/lib/modules/sprinkle_overrides.rb +0 -27
  147. data/lib/modules/vlad_override.rb +0 -83
  148. data/lib/poolparty/application.rb +0 -199
  149. data/lib/poolparty/init.rb +0 -6
  150. data/lib/poolparty/master.rb +0 -492
  151. data/lib/poolparty/monitors.rb +0 -11
  152. data/lib/poolparty/monitors/cpu.rb +0 -23
  153. data/lib/poolparty/monitors/memory.rb +0 -33
  154. data/lib/poolparty/monitors/web.rb +0 -29
  155. data/lib/poolparty/optioner.rb +0 -20
  156. data/lib/poolparty/plugin.rb +0 -78
  157. data/lib/poolparty/provider.rb +0 -104
  158. data/lib/poolparty/provider/essential.rb +0 -6
  159. data/lib/poolparty/provider/git.rb +0 -8
  160. data/lib/poolparty/provider/haproxy.rb +0 -9
  161. data/lib/poolparty/provider/heartbeat.rb +0 -6
  162. data/lib/poolparty/provider/rsync.rb +0 -8
  163. data/lib/poolparty/provider/ruby.rb +0 -65
  164. data/lib/poolparty/provider/s3fuse.rb +0 -22
  165. data/lib/poolparty/remote_instance.rb +0 -250
  166. data/lib/poolparty/remoter.rb +0 -171
  167. data/lib/poolparty/remoting.rb +0 -137
  168. data/lib/poolparty/scheduler.rb +0 -93
  169. data/lib/poolparty/tasks.rb +0 -47
  170. data/lib/poolparty/tasks/development.rake +0 -78
  171. data/lib/poolparty/tasks/plugins.rake +0 -30
  172. data/lib/poolparty/thread_pool.rb +0 -94
  173. data/lib/s3/s3_object_store_folders.rb +0 -44
  174. data/poolparty.gemspec +0 -71
  175. data/spec/files/describe_response +0 -37
  176. data/spec/files/multi_describe_response +0 -69
  177. data/spec/files/remote_desc_response +0 -37
  178. data/spec/helpers/ec2_mock.rb +0 -57
  179. data/spec/lib/core/core_spec.rb +0 -26
  180. data/spec/lib/core/kernel_spec.rb +0 -24
  181. data/spec/lib/core/string_spec.rb +0 -28
  182. data/spec/lib/modules/callback_spec.rb +0 -213
  183. data/spec/lib/modules/file_writer_spec.rb +0 -74
  184. data/spec/lib/poolparty/application_spec.rb +0 -135
  185. data/spec/lib/poolparty/ec2_wrapper_spec.rb +0 -110
  186. data/spec/lib/poolparty/master_spec.rb +0 -479
  187. data/spec/lib/poolparty/optioner_spec.rb +0 -34
  188. data/spec/lib/poolparty/plugin_spec.rb +0 -115
  189. data/spec/lib/poolparty/poolparty_spec.rb +0 -60
  190. data/spec/lib/poolparty/provider_spec.rb +0 -74
  191. data/spec/lib/poolparty/remote_instance_spec.rb +0 -178
  192. data/spec/lib/poolparty/remoter_spec.rb +0 -72
  193. data/spec/lib/poolparty/remoting_spec.rb +0 -148
  194. data/spec/lib/poolparty/scheduler_spec.rb +0 -70
  195. data/spec/monitors/cpu_monitor_spec.rb +0 -39
  196. data/spec/monitors/memory_spec.rb +0 -51
  197. data/spec/monitors/misc_monitor_spec.rb +0 -51
  198. data/spec/monitors/web_spec.rb +0 -40
  199. data/spec/spec_helper.rb +0 -53
@@ -1,250 +0,0 @@
1
- module PoolParty
2
- class RemoteInstance
3
- # ############################
4
- include Remoter
5
- # ############################
6
- include PoolParty
7
- include Callbacks
8
- include FileWriter
9
-
10
- attr_reader :ip, :instance_id, :name, :status, :launching_time, :stack_installed, :keypair
11
- attr_accessor :name, :number, :scp_configure_file, :configure_file, :plugin_string, :keypair
12
-
13
- # CALLBACKS
14
- after :install, :mark_installed
15
- after :configure, :associate_public_ip
16
- def initialize(obj={})
17
- super
18
-
19
- @ip = obj[:ip]
20
- @instance_id = obj[:instance_id]
21
- @name = obj[:name] || "node"
22
- @number = obj[:number] || 0 # Defaults to the master
23
- @status = obj[:status] || "running"
24
- @launching_time = obj[:launching_time] || Time.now
25
- @keypair = obj[:keypair] || Application.keypair rescue ""
26
- end
27
-
28
- # Host entry for this instance
29
- def hosts_entry
30
- "#{@ip} #{name}"
31
- end
32
- # Internal host entry for this instance
33
- def local_hosts_entry
34
- "127.0.0.1 #{name}\n127.0.0.1 localhost.localdomain localhost ubuntu"
35
- end
36
- # Node entry for heartbeat
37
- def node_entry
38
- "node #{name}"
39
- end
40
- # Internal naming scheme
41
- def name
42
- "#{@name}#{@number}"
43
- end
44
- # Entry for the heartbeat config file
45
- def heartbeat_entry
46
- "#{name} #{ip} #{Application.managed_services}"
47
- end
48
- # Entry for haproxy
49
- def haproxy_entry
50
- "\tserver #{name} #{@ip}:#{Application.client_port} weight 1 minconn 3 maxconn 6 check inter 20000 check"
51
- end
52
- def haproxy_resources_entry
53
- "#{name} #{@ip}"
54
- end
55
- # Is this the master?
56
- def master?
57
- @number == 0
58
- end
59
- def secondary?
60
- @number == 1
61
- end
62
- def set_hosts(c)
63
- end
64
- # Let's define some stuff for monit
65
- %w(stop start restart).each do |cmd|
66
- define_method "#{cmd}_with_monit" do
67
- ssh("monit #{cmd} all")
68
- end
69
- end
70
- def configure_tasks(quiet=true)
71
- {
72
- :setup_pems => setup_pems,
73
- :move_hostfile => change_hostname,
74
- :config_master => configure_master,
75
- :move_config_file => move_config_file,
76
- :mount_s3_drive => mount_s3_drive,
77
- :update_plugins => update_plugin_string,
78
- :configure_authkeys => configure_authkeys,
79
- :configure_resource_d => configure_resource_d,
80
- :configure_haproxy => setup_haproxy,
81
- :configure_heartbeat => configure_heartbeat,
82
- :user_tasks => user_tasks,
83
- :node_list => move_node_list
84
- }#.map {|k,v| {k.to_sym => v.nice_runnable(quiet)} }.inject({}) {|a,s| s.merge(a) }
85
- end
86
- def user_tasks
87
- @@user_tasks ||= []
88
- end
89
- def move_config_file
90
- <<-EOC
91
- #{if_exists "config.yml", "mv #{remote_base_tmp_dir}/config.yml ~/.config"}
92
- mkdir -p ~/.ec2
93
- #{if_exists "keypair", "mv #{remote_base_tmp_dir}/keypair ~/.ec2/#{Application.keypair_name}"}
94
- EOC
95
- end
96
- def configure_heartbeat
97
- cmd=<<-EOC
98
- mv #{remote_base_tmp_dir}/ha.cf /etc/ha.d/ha.cf
99
- /etc/init.d/heartbeat start
100
- EOC
101
- Master.requires_heartbeat? ? cmd : ""
102
- end
103
- def configure_authkeys
104
- <<-EOC
105
- mkdir -p /etc/ha.d
106
- #{if_exists "authkeys", "mv #{remote_base_tmp_dir}/authkeys /etc/ha.d/"}
107
- EOC
108
- end
109
-
110
- def configure_master
111
- if master?
112
- <<-EOC
113
- pool maintain -c ~/.config -l ~/plugins
114
- EOC
115
- else
116
- ""
117
- end
118
- end
119
-
120
- def configure_resource_d
121
- <<-EOC
122
- mkdir -p /etc/ha.d/resource.d/
123
- #{if_exists "cloud_master_takeover", "mv #{remote_base_tmp_dir}/cloud_master_takeover /etc/ha.d/resource.d"}
124
- #{if_dir_exists "resource.d/", "mv #{remote_base_tmp_dir}/resource.d/* /etc/ha.d/resource.d"}
125
- EOC
126
- end
127
-
128
- # def configure_monit
129
- # <<-EOC
130
- # mv #{remote_base_tmp_dir}/monitrc /etc/monit/monitrc
131
- # mkdir -p /etc/monit.d/
132
- # mv #{remote_base_tmp_dir}/monit.d/* /etc/monit.d/
133
- # chown #{Application.username} /etc/monit/monitrc
134
- # chmod 700 /etc/monit/monitrc
135
- # EOC
136
- # end
137
-
138
- def setup_pems
139
- <<-EOC
140
- #{if_exists "cert.pem", "mv #{remote_base_tmp_dir}/cert-*.pem #{Application.keypair_path}/cert-CLOUD.pem"}
141
- #{if_exists "pk.pem", "mv #{remote_base_tmp_dir}/pk-*.pem #{Application.keypair_path}/pk-CLOUD.pem"}
142
- EOC
143
- end
144
-
145
- def change_hostname
146
- <<-EOC
147
- #{if_exists "#{name}-hosts", "mv #{remote_base_tmp_dir}/#{name}-hosts /etc/hosts"}
148
- hostname -v #{name}
149
- EOC
150
- end
151
-
152
- def setup_haproxy
153
- <<-EOS
154
- mv #{remote_base_tmp_dir}/haproxy /etc/haproxy.cfg
155
- sed -i "s/ENABLED=0/ENABLED=1/g" /etc/default/haproxy
156
- sed -i 's/SYSLOGD=""/SYSLOGD="-r"/g' /etc/default/syslogd
157
- echo "local0.* /var/log/haproxy.log" >> /etc/syslog.conf && /etc/init.d/sysklogd restart
158
- /etc/init.d/haproxy restart
159
- EOS
160
- end
161
-
162
- def mount_s3_drive
163
- if Application.shared_bucket.empty?
164
- ""
165
- else
166
- <<-EOC
167
- mkdir -p /data && /usr/bin/s3fs #{Application.shared_bucket} -o accessKeyId=#{Application.access_key} -o secretAccessKey=#{Application.secret_access_key} -o nonempty /data
168
- EOC
169
- end
170
- end
171
- def move_node_list
172
- <<-EOC
173
- #{if_exists node_list_name, "mv #{remote_base_tmp_dir}/nodes.lst ~/.#{node_list_name}"}
174
- EOC
175
- end
176
- def node_list_name
177
- self.class.node_list_name
178
- end
179
- def self.node_list_name
180
- "nodes.lst"
181
- end
182
- # Installs with one commandline and an scp, rather than 10
183
- def install
184
- end
185
- # Login to store the authenticity
186
- def login_once
187
- run_now "ls -l"
188
- end
189
- # Associate a public ip if it is set and this is the master
190
- def associate_public_ip(c)
191
- associate_address_with(Application.public_ip, @instance_id) if master? && Application.public_ip && !Application.public_ip.empty?
192
- end
193
- # Become the new master
194
- def become_master
195
- @master = Master.new
196
- @number = 0
197
- @master.nodes[0] = self
198
- @master.configure_cloud
199
- configure
200
- end
201
- # Placeholder
202
- def configure
203
- end
204
- def update_plugin_string
205
- dir = File.basename(Application.plugin_dir)
206
-
207
- if_exists "plugins.tar.gz", "mkdir -p #{dir} && tar -zxf #{remote_base_tmp_dir}/plugins.tar.gz -C #{dir}"
208
- end
209
- def if_exists(file, dothis)
210
- "if [ -f #{remote_base_tmp_dir}/#{file} ]; then #{dothis}; fi"
211
- end
212
- def if_dir_exists(dir, dothis)
213
- "if [ -d #{remote_base_tmp_dir}/#{dir} ]; then #{dothis}; fi"
214
- end
215
- # Is this the master and if not, is the master running?
216
- def is_not_master_and_master_is_not_running?
217
- !master? && !Master.is_master_responding?
218
- end
219
- # User conf file if it exists, or default one
220
- def conf_file(name)
221
- user_conf = File.join(PoolParty.user_dir, "config", name)
222
- if File.file?(user_conf)
223
- File.join(PoolParty.user_dir, "config", name)
224
- else
225
- File.join(PoolParty.root_dir, "config", name)
226
- end
227
- end
228
- # Description in the rake task
229
- def description
230
- case @status
231
- when "running"
232
- "#{@number}: INSTANCE: #{name} - #{@ip} - #{@instance_id} - #{@launching_time}"
233
- when "shutting-down"
234
- "(terminating) INSTANCE: #{name} - #{@ip} - #{@instance_id} - #{@launching_time}"
235
- when "pending"
236
- "(booting) INSTANCE: #{name} - #{@ip} - #{@instance_id} - #{@launching_time}"
237
- end
238
- end
239
- def stack_installed?
240
- @stack_installed ||= run("cat ~/.installed")
241
- end
242
- def mark_installed(caller=nil)
243
- run_now("echo 'installed' > ~/.installed")
244
- @stack_installed = true
245
- end
246
- def base_install_script
247
- "#{root_dir}/config/installers/#{Application.os.downcase}_install.sh"
248
- end
249
- end
250
- end
@@ -1,171 +0,0 @@
1
- =begin rdoc
2
- Handle the remoting aspects of the remote_instances
3
- =end
4
- require 'open4'
5
- module PoolParty
6
- module Remoter
7
- module ClassMethods
8
- def ssh_string
9
- (["ssh"] << ssh_array).join(" ")
10
- end
11
- def ssh_array
12
- ["-o StrictHostKeyChecking=no", "-l '#{Application.username}'", "-i '#{Application.keypair_path}'"]
13
- end
14
- def rsync_string
15
- "rsync --delete -azP -e '#{ssh_string}' "
16
- end
17
- end
18
-
19
- module InstanceMethods
20
- include Callbacks
21
- include Scheduler
22
-
23
- def rsync_tasks local, remote
24
- reset!
25
- returning scp_tasks do |tasks|
26
- target_hosts.each do |ip|
27
- tasks << "#{self.class.rsync_string} #{local} #{ip}:#{remote}"
28
- end
29
- end
30
- end
31
-
32
- def remote_command_tasks commands
33
- reset!
34
- commands = commands.join ' && ' if commands.is_a? Array
35
-
36
- returning ssh_tasks do |tasks|
37
- target_hosts.each do |ip|
38
- ssh_tasks << "#{self.class.ssh_string} #{ip} '#{commands}'"
39
- end
40
- end
41
- end
42
-
43
- def scp local, remote, opts={}
44
- cmd = self.class.rsync_string
45
- arr = []
46
-
47
- target_hosts.each do |ip|
48
- arr << "#{cmd} #{local} #{ip}:#{remote}"
49
- end
50
-
51
- run_array_of_tasks(arr)
52
- end
53
-
54
- def single_scp local, remote, opts={}
55
- scp local, remote, opts.merge({:single => self.ip})
56
- end
57
-
58
- def ssh command="", opts={}, &block
59
- cmd = self.class.ssh_string
60
- arr = []
61
-
62
- if command.empty?
63
- system("#{cmd} #{self.ip}") if self.class == RemoteInstance
64
- else
65
- target_hosts.each do |ip|
66
- arr << "#{cmd} #{ip} '#{command.runnable}'"
67
- end
68
- end
69
-
70
- run_array_of_tasks arr
71
- end
72
-
73
- def run_now command
74
- run command unless command.empty?
75
- end
76
-
77
- def ssh_tasks;@ssh_tasks ||= [];end
78
- def scp_tasks;@scp_tasks ||= [];end
79
-
80
- def reset!
81
- @ssh_tasks = @scp_tasks = nil
82
- @hosts = nil
83
- end
84
-
85
- def execute_tasks(opts={})
86
- # reset!
87
-
88
- set_hosts(nil) unless opts[:dont_set_hosts]
89
-
90
- yield if block_given?
91
-
92
- run_array_of_tasks(scp_tasks)
93
- run_array_of_tasks(ssh_tasks)
94
- end
95
-
96
- def target_hosts
97
- @hosts ||= Master.collect_nodes {|a| a.ip }
98
- end
99
-
100
- def run_array_of_tasks(task_list)
101
- unless task_list.size == 0
102
- task_list.each do |task|
103
- add_task {Kernel.system("#{task}")}
104
- end
105
- run_thread_list
106
- end
107
- end
108
-
109
- def set_hosts(c=nil)
110
- end
111
-
112
- # Nearly Directly from vlad
113
- def run command, on=self
114
- cmd = [self.class.ssh_string, on.ip].compact
115
- result = []
116
-
117
- commander = cmd.join(" ") << " \"#{command.runnable}\""
118
-
119
- pid, inn, out, err = Open4::popen4(commander)
120
-
121
- inn.sync = true
122
- streams = [out, err]
123
- out_stream = {
124
- out => $stdout,
125
- err => $stderr,
126
- }
127
-
128
- # Handle process termination ourselves
129
- status = nil
130
- Thread.start do
131
- status = Process.waitpid2(pid).last
132
- end
133
-
134
- until streams.empty? do
135
- # don't busy loop
136
- selected, = select streams, nil, nil, 0.1
137
-
138
- next if selected.nil? or selected.empty?
139
-
140
- selected.each do |stream|
141
- if stream.eof? then
142
- streams.delete stream if status # we've quit, so no more writing
143
- next
144
- end
145
-
146
- data = stream.readpartial(1024)
147
- out_stream[stream].write data
148
-
149
- if stream == err and data =~ /^Password:/ then
150
- inn.puts sudo_password
151
- data << "\n"
152
- $stderr.write "\n"
153
- end
154
-
155
- result << data
156
- end
157
- end
158
-
159
- PoolParty.message "execution failed with status #{status.exitstatus}: #{cmd.join ' '}" unless status.success?
160
-
161
- result.join
162
- end
163
-
164
- end
165
-
166
- def self.included(receiver)
167
- receiver.extend ClassMethods
168
- receiver.send :include, InstanceMethods
169
- end
170
- end
171
- end
@@ -1,137 +0,0 @@
1
- module PoolParty
2
- extend self
3
-
4
- class Remoting
5
- include PoolParty
6
- include Ec2Wrapper
7
- include Scheduler
8
-
9
- # == GENERAL METHODS
10
- # == LISTING
11
- # List all the running instances associated with this account
12
- def list_of_running_instances(list = list_of_nonterminated_instances)
13
- list.select {|a| a[:status] =~ /running/}
14
- end
15
- # Get a list of the pending instances
16
- def list_of_pending_instances(list = list_of_nonterminated_instances)
17
- list.select {|a| a[:status] =~ /pending/}
18
- end
19
- # list of shutting down instances
20
- def list_of_terminating_instances(list = list_of_nonterminated_instances)
21
- list.select {|a| a[:status] =~ /shutting/}
22
- end
23
- # list all the nonterminated instances
24
- def list_of_nonterminated_instances(list = list_of_instances)
25
- list.reject {|a| a[:status] =~ /terminated/}
26
- end
27
- # List the instances for the current key pair, regardless of their states
28
- def list_of_instances(keypair = Application.keypair)
29
- get_instances_description.select {|a| a[:keypair] == keypair}
30
- end
31
- # List all instances, regardless of their key pairs or states
32
- def list_of_all_instances
33
- a_list = []
34
- cloud_keypairs.each {|keypair| list_of_instances(keypair).each { |inst| a_list << inst } }
35
- a_list
36
- end
37
- # list of keypairs for the current AWS access key and secret key
38
- def cloud_keypairs
39
- get_instances_description.each {|a| a[:keypair] = "no-keypair" unless a[:keypair] } # Get rid of the instances not launched with a keypair
40
- instances = get_instances_description.sort{|x,y| x[:keypair] <=> y[:keypair]}
41
- keypair = nil
42
- instances.map {|a| keypair != a[:keypair] ? (keypair = a[:keypair]; keypair) : nil }.compact
43
- end
44
- # Get number of pending instances
45
- def number_of_pending_instances(list = list_of_pending_instances)
46
- list.size
47
- end
48
- # get the number of running instances
49
- def number_of_running_instances(list = list_of_running_instances)
50
- list.size
51
- end
52
- # get the number of pending and running instances for a list
53
- def number_of_pending_and_running_instances_for_list(a_list = list_of_instances)
54
- running_list = list_of_running_instances( a_list )
55
- pending_list = list_of_pending_instances( a_list )
56
- number_of_running_instances(running_list) + number_of_pending_instances(pending_list)
57
- end
58
- # get the number of pending and running instances for a keypair
59
- def number_of_pending_and_running_instances(keypair = Application.keypair)
60
- a_list = list_of_nonterminated_instances( list_of_instances(keypair) )
61
- number_of_pending_and_running_instances_for_list( a_list )
62
- end
63
- # get the number of pending and running instances
64
- def number_of_all_pending_and_running_instances
65
- a_list = list_of_nonterminated_instances( list_of_all_instances )
66
- number_of_pending_and_running_instances_for_list( a_list )
67
- end
68
- # == LAUNCHING
69
- # Request to launch a new instance
70
- def request_launch_new_instance
71
- if can_start_a_new_instance?
72
- request_launch_one_instance_at_a_time
73
- return true
74
- else
75
- return false
76
- end
77
- end
78
- # Can we start a new instance?
79
- def can_start_a_new_instance?
80
- maximum_number_of_instances_are_not_running?
81
- end
82
- # Are the maximum number of instances running?
83
- def maximum_number_of_instances_are_not_running?
84
- list_of_running_instances.size < Application.maximum_instances
85
- end
86
- # Request to launch a number of instances
87
- def request_launch_new_instances(num=1)
88
- out = []
89
- num.times {out << request_launch_one_instance_at_a_time}
90
- out
91
- end
92
- # Launch one instance at a time
93
- def request_launch_one_instance_at_a_time
94
- reset!
95
- while !number_of_pending_instances.zero?
96
- wait "5.seconds"
97
- reset!
98
- end
99
- return launch_new_instance!
100
- end
101
- # == SHUTDOWN
102
- # Terminate all running instances
103
- def request_termination_of_running_instances
104
- list_of_running_instances.each {|a| terminate_instance!(a[:instance_id])}
105
- end
106
- # Request termination of all instances regardless of their state (includes pending instances)
107
- def request_termination_of_all_instances
108
- list_of_instances.each {|a| terminate_instance!(a[:instance_id])}
109
- end
110
- # Terminate instance by id
111
- def request_termination_of_instance(id)
112
- if can_shutdown_an_instance?
113
- terminate_instance! id
114
- return true
115
- else
116
- return false
117
- end
118
- end
119
- # Can we shutdown an instance?
120
- def can_shutdown_an_instance?
121
- minimum_number_of_instances_are_running?
122
- end
123
- # Are the minimum number of instances running?
124
- def minimum_number_of_instances_are_running?
125
- list_of_running_instances.size > Application.minimum_instances
126
- end
127
- # Get the cached running_instances
128
- def running_instances
129
- @running_instances ||= update_instance_values
130
- end
131
- # Update the instance values
132
- def update_instance_values
133
- @running_instances = list_of_running_instances.collect {|a| RemoteInstance.new(a) }.sort
134
- end
135
- end
136
-
137
- end