auser-poolparty 0.2.44 → 0.2.45

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/Manifest.txt +3 -1
  2. data/bin/cloud +11 -21
  3. data/bin/cloud-add-keypair +18 -13
  4. data/bin/cloud-configure +3 -11
  5. data/bin/cloud-contract +7 -12
  6. data/bin/cloud-ensure-provisioning +2 -11
  7. data/bin/cloud-expand +3 -10
  8. data/bin/cloud-handle-load +3 -9
  9. data/bin/cloud-list +3 -9
  10. data/bin/cloud-maintain +2 -9
  11. data/bin/cloud-osxcopy +3 -9
  12. data/bin/cloud-provision +4 -9
  13. data/bin/cloud-refresh +2 -9
  14. data/bin/cloud-run +3 -4
  15. data/bin/cloud-ssh +3 -2
  16. data/bin/cloud-start +7 -13
  17. data/bin/cloud-terminate +4 -7
  18. data/bin/pool +11 -12
  19. data/bin/pool-describe +0 -1
  20. data/bin/pool-list +3 -9
  21. data/bin/pool-start +3 -10
  22. data/generators/poolspec/USAGE +2 -2
  23. data/generators/poolspec/poolspec_generator.rb +2 -1
  24. data/generators/poolspec/templates/pool_spec_template.erb +3 -2
  25. data/lib/erlang/messenger/useful_snippets +2 -2
  26. data/lib/poolparty/aska/aska.rb +5 -6
  27. data/lib/poolparty/base_packages/haproxy.rb +2 -2
  28. data/lib/poolparty/core/string.rb +1 -1
  29. data/lib/poolparty/exceptions/CloudNotFoundException.rb +7 -0
  30. data/lib/poolparty/helpers/binary.rb +1 -1
  31. data/lib/poolparty/helpers/optioner.rb +34 -12
  32. data/lib/poolparty/modules/cloud_dsl.rb +13 -0
  33. data/lib/poolparty/net/messenger.rb +1 -1
  34. data/lib/poolparty/net/remote_bases/ec2.rb +162 -145
  35. data/lib/poolparty/net/remoter.rb +8 -4
  36. data/lib/poolparty/plugins/git.rb +5 -1
  37. data/lib/poolparty/pool/base.rb +1 -1
  38. data/lib/poolparty/pool/cloud.rb +7 -2
  39. data/lib/poolparty/pool/resource.rb +1 -1
  40. data/lib/poolparty/pool/resources/mount.rb +22 -0
  41. data/lib/poolparty/version.rb +1 -1
  42. data/poolparty.gemspec +5 -4
  43. data/spec/poolparty/modules/configurable_spec.rb +4 -1
  44. data/spec/poolparty/pool/base_spec.rb +2 -2
  45. data/spec/poolparty/pool/plugin_model_spec.rb +2 -3
  46. data/website/index.html +1 -1
  47. metadata +5 -4
  48. data/bin/pool-provision +0 -34
data/bin/pool CHANGED
@@ -3,19 +3,18 @@ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
3
  require "poolparty"
4
4
  require "poolpartycl"
5
5
 
6
- # Get the git-style program action
7
- # o = PoolParty::Optioner.new(ARGV) do |opts, optioner|
8
- # opts.on('-n [name]','--name [name]', 'Binary to run') { |o| optioner.name o }
9
- # end
6
+ name = ARGV.select {|arg| arg if Binary.available_binaries_for("pool").include?(arg) }.first
7
+ # If the options include -h and they don't include a valid command, then we can just pass the
8
+ # original options back, but if they do contain a binary, we don't want -h getting through to
9
+ # these options, so we'll strip it if it's included
10
+ DUP_ARG = ARGV.dup
11
+ new_args = DUP_ARG.reject {|arg| Binary.available_binaries_for("pool").include?(arg) }.empty? ? ARGV : (name ? (DUP_ARG.delete("-h"); DUP_ARG) : DUP_ARG)
10
12
 
11
- name = ARGV.shift
13
+ # Let's make sure if no command is passed in that we show the help message
14
+ new_args.push("-h") unless name
12
15
 
13
- # If there was no program action given
14
- if !name || name == "-h" || name == "--help"
15
- puts "Usage: pool <specfile> <action> <options>"
16
- puts "Pool actions:"
17
- puts Binary.list_binaries_for("pool")
18
- exit
16
+ o = PoolParty::Optioner.new(new_args, {:extra_help => "\nPool actions\n#{Binary.list_binaries_for("pool")}\n\n", :abstract => true}) do |opts, optioner|
17
+ opts.on('-n poolname', '--name name', 'Address this pool') { |c| optioner.poolname c }
19
18
  end
20
19
 
21
20
  program_name = "#{File.basename($0)}-#{name}"
@@ -27,5 +26,5 @@ command_line = "#{program_location}"
27
26
  if Binary.available_binaries_for("pool").include?(name)
28
27
  system command_line, *ARGV
29
28
  else
30
- puts "Unknown poolparty binary: #{program_name}"
29
+ puts "Unknown poolparty binary: #{name}"
31
30
  end
data/bin/pool-describe CHANGED
@@ -4,6 +4,5 @@ require "poolparty"
4
4
  require "poolpartycl"
5
5
 
6
6
  o = PoolParty::Optioner.new(ARGV)
7
- load_pool(o.spec || Binary.get_existing_spec_location)
8
7
 
9
8
  puts pool_describe
data/bin/pool-list CHANGED
@@ -2,22 +2,16 @@
2
2
  $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
3
  require "poolparty"
4
4
  require "poolpartycl"
5
+
5
6
  o = PoolParty::Optioner.new(ARGV) do |opts, optioner|
6
7
  opts.on('-f [remote|local]', '--from [remote|local]', 'Remote or local (default: local)') { |o| optioner.location o }
7
8
  opts.on('-r', '--remote', 'Remote listing') { optioner.location "remote" }
8
9
  opts.on('-l', '--local', 'Local listing') { optioner.location "local" }
9
10
  opts.on('-n name', '--name name', 'Listing for pool name') { |p| optioner.poolname p }
10
11
  end
11
- load_pool(o.spec || Binary.get_existing_spec_location)
12
-
13
- @location = o.location ? o.location : "remote"
14
-
15
- include Remote
16
-
17
- @pools = o.poolname ? [pool(o.poolname.downcase.to_sym)] : pools
18
12
 
19
- @pools.each do |name, pool|
20
- with_pool(pool, {:location => @location}) do
13
+ o.loaded_pools.each do |pool|
14
+ with_pool(pool) do
21
15
  puts header("Listing pool #{name}")
22
16
  clouds.each do |name, cloud|
23
17
  puts subheader("Cloud: #{name}")
data/bin/pool-start CHANGED
@@ -2,21 +2,14 @@
2
2
  $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
3
  require "poolparty"
4
4
  require "poolpartycl"
5
+
5
6
  o = PoolParty::Optioner.new(ARGV) do |opts, optioner|
6
7
  opts.on('-p poolname', '--pool name', 'Start pool by this name') { |p| optioner.poolname p }
7
8
  end
8
9
 
9
- load_pool(o.spec || Binary.get_existing_spec_location)
10
-
11
- @testing = o.testing
12
-
13
- include Remote
14
-
15
- @pools = o.poolname ? [pool(o.poolname.downcase.to_sym)] : pools
16
-
17
- @pools.each do |name, pl|
10
+ o.loaded_pools.each do |pl|
18
11
 
19
- with_pool(pl, {:testing => @testing}) do
12
+ with_pool(pl) do
20
13
 
21
14
  puts header("Starting pool")
22
15
  clouds.each do |name, cloud|
@@ -1,5 +1,5 @@
1
1
  Description:
2
-
2
+ Create a basic pool.spec template
3
3
 
4
4
  Usage:
5
-
5
+ pool spec [name]
@@ -21,7 +21,7 @@ class PoolspecGenerator < RubiGen::Base
21
21
  m.directory ''
22
22
  BASEDIRS.each { |path| m.directory path }
23
23
 
24
- m.template "pool_spec_template.erb", "#{@name}.rb"
24
+ m.template "pool_spec_template.erb", "pool.spec"
25
25
  # Create stubs
26
26
  # m.template "template.rb", "some_file_after_erb.rb"
27
27
  # m.template_copy_each ["template.rb", "template2.rb"]
@@ -61,5 +61,6 @@ EOS
61
61
  # Installation skeleton. Intermediate directories are automatically
62
62
  # created so don't sweat their absence here.
63
63
  BASEDIRS = %w(
64
+ plugins
64
65
  )
65
66
  end
@@ -1,9 +1,10 @@
1
1
  # Basic poolparty template
2
2
 
3
3
  pool :<%= name -%> do
4
-
5
- cloud :app do
4
+ plugin_directory "#{File.dirname(__FILE__)}/plugins"
6
5
 
6
+ cloud :app do
7
+ instances 2..5
7
8
  end
8
9
 
9
10
  end
@@ -6,10 +6,10 @@
6
6
  % erl -pa ./ebin -kernel inet_dist_listen_min 7000 inet_dist_listen_max 7050 -setcookie poolparty -boot pm_node_rel-0.1 -sname node1
7
7
 
8
8
  % Starting the client on the master
9
- % erl -pa /var/lib/gems/1.8/gems/poolparty-0.2.42/lib/erlang/messenger/ebin -kernel inet_dist_listen_min 7000 inet_dist_listen_max 7050 -sname client -setcookie poolparty -run pm_client start
9
+ % erl -pa /var/lib/gems/1.8/gems/poolparty-0.2.44/lib/erlang/messenger/ebin -kernel inet_dist_listen_min 7000 inet_dist_listen_max 7050 -sname client -setcookie poolparty -run pm_client start
10
10
 
11
11
  % Get the load
12
- % erl -pa /var/lib/gems/1.8/gems/poolparty-0.2.42/lib/erlang/messenger/ebin -kernel inet_dist_listen_min 7000 inet_dist_listen_max 7050 -sname client -setcookie poolparty -run pm_client start -run pm_client get_load cpu -run erlang init stop
12
+ % erl -pa /var/lib/gems/1.8/gems/poolparty-0.2.44/lib/erlang/messenger/ebin -kernel inet_dist_listen_min 7000 inet_dist_listen_max 7050 -sname client -setcookie poolparty -run pm_client start -run pm_client get_load cpu -run erlang init stop
13
13
 
14
14
  % cd /var/poolparty && gem uninstall poolparty && wget http://github.com/auser/poolparty/tree/master%2Fpkg%2Fpoolparty-latest.gem?raw=true -O poolparty-latest.gem 2>&1 && gem install --no-ri --no-rdoc poolparty-latest.gem
15
15
 
@@ -54,7 +54,7 @@ module Aska
54
54
  def valid_rules?(name=:rules)
55
55
  self.class.look_up_rules(name).reject {|rule| valid_rule?(rule) }.empty?
56
56
  end
57
- def __aska_aska_stuff(m)
57
+ def __aska_send_value(m)
58
58
  if respond_to?(m.to_sym)
59
59
  self.send(m.to_sym)
60
60
  else
@@ -63,9 +63,8 @@ module Aska
63
63
  end
64
64
  def valid_rule?(rule)
65
65
  rule.each do |key,value|
66
- begin
67
- # puts "#{aska(key)} #{value[0].to_sym} #{get_var(value[1])} (#{attr_accessor?(value[1])})"
68
- return __aska_aska_stuff(key).send(value[0].to_sym, __aska_get_var(value[1]))
66
+ begin
67
+ return __aska_send_value(key).send(value[0].to_sym, __aska_get_var(value[1]))
69
68
  rescue Exception => e
70
69
  return false
71
70
  end
@@ -74,10 +73,10 @@ module Aska
74
73
  def rules_values
75
74
  returning Array.new do |arr|
76
75
  self.class.defined_rules.each do |name,rule_array|
77
- arr << "#{name} : #{valid_rule?(rule_array)}"
76
+ arr << "#{name} : #{valid_rules?(name.to_sym)}"
78
77
  rule_array.each do |rule|
79
78
  rule.map do |k,v|
80
- arr << " #{k} -> #{__aska_aska_stuff(k)} (#{v[0]} #{v[1]})"
79
+ arr << " #{k} -> #{__aska_send_value(k)} (#{v[0]} #{v[1]})"
81
80
  end
82
81
  end
83
82
  end
@@ -12,7 +12,7 @@ module PoolParty
12
12
  end
13
13
 
14
14
  # Template variables
15
- has_variable(:name => "name_haproxy", :value => "#{cloud.name}")
15
+ has_variable(:name => "name_haproxy", :value => "#{cloud.name}")
16
16
  has_variable(:name => "nodenames_haproxy", :value => "generate('/usr/bin/env', '/var/lib/gems/1.8/bin/server-list-active', '-c', 'name')")
17
17
  has_variable(:name => "node_ips_haproxy", :value => "generate('/usr/bin/env', '/var/lib/gems/1.8/bin/server-list-active', '-c', 'ip')")
18
18
 
@@ -34,7 +34,7 @@ module PoolParty
34
34
  has_remotefile(:name => "/etc/haproxy.cfg") do
35
35
  mode 644
36
36
  requires get_package("haproxy")
37
- notify get_exec("reloadhaproxy")
37
+ notify get_service("haproxy")
38
38
  template File.join(File.dirname(__FILE__), "..", "templates/haproxy.conf")
39
39
  end
40
40
  end
@@ -25,7 +25,7 @@ class String
25
25
  self.split("::")[-1].downcase rescue self
26
26
  end
27
27
  def sanitize
28
- self.gsub(/[ \.\/]*/, '')
28
+ self.gsub(/[ \.\/\-]*/, '')
29
29
  end
30
30
  def nice_runnable(quite=true)
31
31
  self.split(/ && /).join("\n")
@@ -0,0 +1,7 @@
1
+ class CloudNotFoundException < Exception
2
+ attr_reader :message
3
+
4
+ def initialize(msg="Cloud not found")
5
+ @message = "Cloud not found: #{msg}"
6
+ end
7
+ end
@@ -21,7 +21,7 @@ module PoolParty
21
21
  "#{Base.default_specfile_name}",
22
22
  "#{Base.storage_directory}/#{Base.default_specfile_name}",
23
23
  ].reject {|a| a.nil?}.reject do |f|
24
- f unless ::File.file?(f)
24
+ f unless ::File.readable?(f)
25
25
  end.first
26
26
  end
27
27
 
@@ -1,4 +1,6 @@
1
1
  require 'optparse'
2
+ require "poolparty"
3
+ require "poolpartycl"
2
4
  require 'rdoc/usage'
3
5
  require 'ostruct'
4
6
  require 'date'
@@ -11,9 +13,12 @@ module PoolParty
11
13
  def initialize(args=[], opts={}, &block)
12
14
  @arguments = parse_args(args)
13
15
  @parse_options = opts[:parse_options] ? opts[:parse_options] : true
16
+ @extra_help = opts.has_key?(:extra_help) ? opts[:extra_help] : ""
17
+ @abstract = opts[:abstract] ? opts[:abstract] : false
18
+ @command = opts[:command] ? opts[:command] : false
14
19
 
15
- set_default_options
16
20
  parse_options(&block) if @parse_options
21
+ set_default_options
17
22
  self
18
23
  end
19
24
 
@@ -26,38 +31,55 @@ module PoolParty
26
31
  end
27
32
 
28
33
  def set_default_options
29
- @options = {}
30
- @options[:verbose] = false
31
- @options[:quiet] = false
32
- @options[:version] = PoolParty::VERSION::STRING
34
+ self.verbose false
35
+ self.quiet false
36
+ self.version PoolParty::VERSION::STRING
33
37
  end
34
38
 
35
39
  def parse_options(&blk)
40
+ progname = $0.include?("-") ? "#{::File.basename($0[/(\w+)-/, 1])} #{::File.basename($0[/-(.*)/, 1])}" : ::File.basename($0)
36
41
  opts = OptionParser.new
37
- opts.banner = "Usage: pool [command] [options]"
42
+ opts.banner = "Usage: #{progname} #{@abstract ? "[command] " : ""}[options]"
38
43
 
39
44
  opts.separator ""
40
45
  opts.separator "Options:"
41
46
 
42
47
  opts.on('-V', '--version', 'Display the version') { output_version ; exit 0 }
43
- opts.on('-v', '--verbose', 'Be verbose') { @options[:verbose] = true }
48
+ opts.on('-v', '--verbose', 'Be verbose') { self.verbose true }
44
49
  opts.on('-s [file]', '--spec-file [file]', 'Set the spec file') { |file| self.spec file }
45
50
  opts.on('-t', '--test', 'Testing mode') { self.testing true }
46
51
 
47
52
  blk.call(opts, self) if blk
48
53
 
49
- opts.on_tail("-h", "--help", "Show this message") do
50
- puts opts
51
- exit
54
+ unless @abstract
55
+ opts.on_tail("-h", "--help", "Show this message") do
56
+ puts opts
57
+ puts @extra_help
58
+ exit
59
+ end
52
60
  end
53
61
 
54
62
  opts.parse(@arguments.dup)
55
63
 
56
- process_options
64
+ process_options
57
65
  output_options if verbose
66
+ self.loaded_pool load_pool(self.spec || Binary.get_existing_spec_location)
67
+
68
+ self.loaded_clouds extract_cloud_from_options(self)
69
+ self.loaded_pools extract_pool_from_options(self)
70
+
71
+ reject_junk_options!
72
+ raise CloudNotFoundException.new("Please specify your cloud with -s, move it to ./pool.spec or in your POOL_SPEC environment variable") unless loaded_clouds && !loaded_clouds.empty?
73
+ loaded_clouds.each do |cl|
74
+ cl.configure(self.options)
75
+ end
76
+ end
77
+ def reject_junk_options!
78
+ %w(loaded_pool cloudname).each do |opt|
79
+ @options.delete(opt.to_sym)
80
+ end
58
81
  end
59
82
  def process_options
60
- @options[:verbose] = false if @options[:quiet]
61
83
  end
62
84
 
63
85
  def output_version
@@ -0,0 +1,13 @@
1
+ module PoolParty
2
+ module CloudDsl
3
+
4
+ def mount_ebs_volume_at(id="", loc="/data")
5
+ ebs_volume_id id
6
+ ebs_volume_mount_point loc
7
+ ebs_volume_device "/dev/#{id.sanitize}"
8
+ has_directory(:name => loc)
9
+ has_mount(:name => loc, :device => ebs_volume_device)
10
+ end
11
+
12
+ end
13
+ end
@@ -16,7 +16,7 @@ module PoolParty
16
16
  end
17
17
 
18
18
  def self.messenger_send!(cmd="", testing=false)
19
- command = Messenger.erl_command("client#{Time.now.to_i}", "-s pm_client -run pm_client #{cmd} -s erlang halt -noshell")
19
+ command = Messenger.erl_command("client#{Time.now.to_i}", "-hidden -s pm_client -run pm_client #{cmd} -s erlang halt -noshell")
20
20
  testing ? command : %x[#{command}]
21
21
  end
22
22
 
@@ -1,160 +1,177 @@
1
- require 'rubygems'
2
- require 'EC2'
3
-
4
- class String
5
- def convert_from_ec2_to_ip
6
- self.gsub(/.compute-1.amazonaws.com*/, '').gsub(/ec2-/, '').gsub(/-/, '.')
1
+ begin
2
+ require 'EC2'
3
+ class String
4
+ def convert_from_ec2_to_ip
5
+ self.gsub(/.compute-1.amazonaws.com*/, '').gsub(/ec2-/, '').gsub(/-/, '.')
6
+ end
7
7
  end
8
- end
9
- module PoolParty
10
- module Ec2
11
- def launch_new_instance!(num=1)
12
- instance = ec2.run_instances(
13
- :image_id => (ami || Base.ami),
14
- :user_data => "",
15
- :minCount => 1,
16
- :maxCount => num,
17
- :key_name => (keypair || Base.keypair),
18
- :availability_zone => nil,
19
- :size => "#{size || Base.size}")
20
- begin
21
- h = EC2ResponseObject.get_hash_from_response(instance)
22
- h = instance.instancesSet.item.first
23
- rescue Exception => e
24
- h = instance
8
+ module PoolParty
9
+ module Ec2
10
+ def launch_new_instance!(num=1)
11
+ instance = ec2.run_instances(
12
+ :image_id => (ami || Base.ami),
13
+ :user_data => "",
14
+ :minCount => 1,
15
+ :maxCount => num,
16
+ :key_name => (keypair || Base.keypair),
17
+ :availability_zone => nil,
18
+ :size => "#{size || Base.size}")
19
+ begin
20
+ h = EC2ResponseObject.get_hash_from_response(instance)
21
+ h = instance.instancesSet.item.first
22
+ rescue Exception => e
23
+ h = instance
24
+ end
25
+ h
25
26
  end
26
- h
27
- end
28
- # Terminate an instance by id
29
- def terminate_instance!(instance_id=nil)
30
- ec2.terminate_instances(:instance_id => instance_id)
31
- end
32
- # Describe an instance's status
33
- def describe_instance(id=nil)
34
- describe_instances.select {|a| a[:name] == id}[0] rescue nil
35
- end
36
- def describe_instances
37
- @id = 0
38
- get_instances_description.each_with_index do |h,i|
39
- if h[:status] == "running"
40
- @name = @id == 0 ? "master" : "node#{@id}"
41
- @id += 1
42
- else
43
- @name = "#{h[:status]}_node#{i}"
27
+ # Terminate an instance by id
28
+ def terminate_instance!(instance_id=nil)
29
+ ec2.terminate_instances(:instance_id => instance_id)
30
+ end
31
+ # Describe an instance's status
32
+ def describe_instance(id=nil)
33
+ describe_instances.select {|a| a[:name] == id}[0] rescue nil
34
+ end
35
+ def describe_instances
36
+ @id = 0
37
+ get_instances_description.each_with_index do |h,i|
38
+ if h[:status] == "running"
39
+ @name = @id == 0 ? "master" : "node#{@id}"
40
+ @id += 1
41
+ else
42
+ @name = "#{h[:status]}_node#{i}"
43
+ end
44
+ h.merge!({
45
+ :name => @name,
46
+ :hostname => h[:ip],
47
+ :ip => h[:ip].convert_from_ec2_to_ip
48
+ })
44
49
  end
45
- h.merge!({
46
- :name => @name,
47
- :hostname => h[:ip],
48
- :ip => h[:ip].convert_from_ec2_to_ip
49
- })
50
50
  end
51
- end
52
- # Get the s3 description for the response in a hash format
53
- def get_instances_description
54
- EC2ResponseObject.get_descriptions(ec2.describe_instances).sort_by {|a| a[:launching_time]}
55
- end
56
-
57
- def after_launch_master(instance=nil)
58
- begin
59
- when_no_pending_instances do
60
- ec2.associate_address(:instance_id => instance.instanceId, :public_ip => set_master_ip_to) if set_master_ip_to && instance
51
+ # Get the s3 description for the response in a hash format
52
+ def get_instances_description
53
+ EC2ResponseObject.get_descriptions(ec2.describe_instances).sort_by {|a| a[:launching_time]}
54
+ end
55
+
56
+ def after_launch_master(instance=nil)
57
+ begin
58
+ when_no_pending_instances do
59
+ if instance
60
+ ec2.associate_address(:instance_id => instance.instanceId, :public_ip => set_master_ip_to) if set_master_ip_to
61
+ ec2.attach_volume(:volume_id => ebs_volume_id, :instance_id => instance.instanceId, :device => ebs_volume_device) if ebs_volume_id && ebs_volume_mount_point
62
+ end
63
+ end
64
+ rescue Exception => e
61
65
  end
62
- rescue Exception => e
66
+ reset_remoter_base!
67
+ when_all_assigned_ips {wait "2.seconds"}
63
68
  end
64
- reset_remoter_base!
65
- when_all_assigned_ips {wait "2.seconds"}
66
- end
67
-
68
- # Help create a keypair for the cloud
69
- # This is a helper to create the keypair and add them to the cloud for you
70
- def create_keypair
71
- return false unless keypair
72
- unless ::File.exists?( new_keypair_path )
73
- FileUtils.mkdir_p ::File.dirname( new_keypair_path )
74
- Kernel.system "ec2-add-keypair #{keypair} > #{new_keypair_path} && chmod 600 #{new_keypair_path}"
69
+
70
+ # Help create a keypair for the cloud
71
+ # This is a helper to create the keypair and add them to the cloud for you
72
+ def create_keypair
73
+ return false unless keypair
74
+ unless ::File.exists?( new_keypair_path )
75
+ FileUtils.mkdir_p ::File.dirname( new_keypair_path )
76
+ vputs "Creating keypair: #{keypair} in #{new_keypair_path}"
77
+ Kernel.system "ec2-add-keypair #{keypair} > #{new_keypair_path} && chmod 600 #{new_keypair_path}"
78
+ end
79
+ end
80
+ # EC2 connections
81
+ def ec2
82
+ @ec2 ||= EC2::Base.new( :access_key_id => (access_key || Base.access_key),
83
+ :secret_access_key => (secret_access_key || Base.secret_access_key)
84
+ )
85
+ end
86
+
87
+ # Callback
88
+ def custom_install_tasks_for(o)
89
+ [
90
+ "# ec2 installation tasks",
91
+ "# Set hostname",
92
+ # "if [ -z $(grep -v '#' /etc/hosts | grep '#{o.name}') ]; then echo \"$(curl http://169.254.169.254/latest/meta-data/public-ipv4) #{o.name}\" >> /etc/hosts; fi",
93
+ "if [ -z \"$(grep -v '#' /etc/hosts | grep '#{o.name}')\" ]; then echo '127.0.0.1 #{o.name}' >> /etc/hosts; fi",
94
+ "hostname #{o.name}",
95
+ "echo #{o.name} > /etc/hostname",
96
+ "cd /var/poolparty && wget http://rubyforge.org/frs/download.php/43666/amazon-ec2-0.3.1.gem -O amazon-ec2.gem 2>&1 && gem install -y --no-ri --no-rdoc amazon-ec2.gem 2>&1"
97
+ ]
98
+ end
99
+
100
+ def custom_configure_tasks_for(o)
101
+ [
102
+ "# ec2 configuration"
103
+ ]
104
+ end
105
+
106
+ def reset_base!
107
+ @describe_instances = @cached_descriptions = nil
75
108
  end
76
109
  end
77
- # EC2 connections
78
- def ec2
79
- @ec2 ||= EC2::Base.new( :access_key_id => (access_key || Base.access_key),
80
- :secret_access_key => (secret_access_key || Base.secret_access_key)
81
- )
82
- end
83
-
84
- # Callback
85
- def custom_install_tasks_for(o)
86
- [
87
- "# ec2 installation tasks",
88
- "# Set hostname",
89
- # "if [ -z $(grep -v '#' /etc/hosts | grep '#{o.name}') ]; then echo \"$(curl http://169.254.169.254/latest/meta-data/public-ipv4) #{o.name}\" >> /etc/hosts; fi",
90
- "if [ -z \"$(grep -v '#' /etc/hosts | grep '#{o.name}')\" ]; then echo '127.0.0.1 #{o.name}' >> /etc/hosts; fi",
91
- "hostname #{o.name}",
92
- "echo #{o.name} > /etc/hostname",
93
- "cd /var/poolparty && wget http://rubyforge.org/frs/download.php/43666/amazon-ec2-0.3.1.gem -O amazon-ec2.gem 2>&1 && gem install -y --no-ri --no-rdoc amazon-ec2.gem 2>&1"
94
- ]
95
- end
96
-
97
- def custom_configure_tasks_for(o)
98
- [
99
- "# ec2 configuration"
100
- ]
101
- end
102
-
103
- def reset_base!
104
- @describe_instances = @cached_descriptions = nil
105
- end
110
+ register_remote_base :Ec2
106
111
  end
107
- register_remote_base :Ec2
108
- end
109
112
 
110
- # Provides a simple class to wrap around the amazon responses
111
- class EC2ResponseObject
112
- def self.get_descriptions(resp)
113
- rs = get_response_from(resp)
114
-
115
- # puts rs.methods.sort - rs.ancestors.methods
116
- out = begin
117
- if rs.respond_to?(:instancesSet)
118
- [EC2ResponseObject.get_hash_from_response(rs.instancesSet.item)]
119
- else
120
- rs.collect {|r|
121
- if r.instancesSet.item.class == Array
122
- r.instancesSet.item.map {|t| EC2ResponseObject.get_hash_from_response(t)}
123
- else
124
- [EC2ResponseObject.get_hash_from_response(r.instancesSet.item)]
125
- end
126
- }.flatten.reject {|a| a.nil? }
113
+ # Provides a simple class to wrap around the amazon responses
114
+ class EC2ResponseObject
115
+ def self.get_descriptions(resp)
116
+ rs = get_response_from(resp)
117
+
118
+ # puts rs.methods.sort - rs.ancestors.methods
119
+ out = begin
120
+ if rs.respond_to?(:instancesSet)
121
+ [EC2ResponseObject.get_hash_from_response(rs.instancesSet.item)]
122
+ else
123
+ rs.collect {|r|
124
+ if r.instancesSet.item.class == Array
125
+ r.instancesSet.item.map {|t| EC2ResponseObject.get_hash_from_response(t)}
126
+ else
127
+ [EC2ResponseObject.get_hash_from_response(r.instancesSet.item)]
128
+ end
129
+ }.flatten.reject {|a| a.nil? }
130
+ end
131
+ rescue Exception => e
132
+ # Really weird bug with amazon's ec2 gem
133
+ rs.collect {|r| EC2ResponseObject.get_hash_from_response(r)}.reject {|a| a.nil? } rescue []
134
+ end
135
+
136
+ out
137
+ end
138
+ def self.get_response_from(resp)
139
+ begin
140
+ rs = resp.reservationSet.item unless resp.reservationSet.nil?
141
+ rs ||= resp.DescribeInstancesResponse.reservationSet.item
142
+ rs ||= rs.respond_to?(:instancesSet) ? rs.instancesSet : rs
143
+ rs.reject! {|a| a.nil? || a.empty? }
144
+ rescue Exception => e
145
+ resp
127
146
  end
128
- rescue Exception => e
129
- # Really weird bug with amazon's ec2 gem
130
- rs.collect {|r| EC2ResponseObject.get_hash_from_response(r)}.reject {|a| a.nil? } rescue []
147
+ rs
131
148
  end
132
-
133
- out
134
- end
135
- def self.get_response_from(resp)
136
- begin
137
- rs = resp.reservationSet.item unless resp.reservationSet.nil?
138
- rs ||= resp.DescribeInstancesResponse.reservationSet.item
139
- rs ||= rs.respond_to?(:instancesSet) ? rs.instancesSet : rs
140
- rs.reject! {|a| a.nil? || a.empty? }
141
- rescue Exception => e
142
- resp
149
+ def self.get_hash_from_response(resp)
150
+ begin
151
+ {
152
+ :instance_id => resp.instanceId,
153
+ :name => resp.instanceId,
154
+ :ip => resp.dnsName || "not-assigned",
155
+ :status => resp.instanceState.name,
156
+ :launching_time => resp.launchTime,
157
+ :keypair => resp.keyName
158
+ }
159
+ rescue Exception => e
160
+ nil
161
+ end
143
162
  end
144
- rs
145
- end
146
- def self.get_hash_from_response(resp)
147
- begin
148
- {
149
- :instance_id => resp.instanceId,
150
- :name => resp.instanceId,
151
- :ip => resp.dnsName || "not-assigned",
152
- :status => resp.instanceState.name,
153
- :launching_time => resp.launchTime,
154
- :keypair => resp.keyName
155
- }
156
- rescue Exception => e
157
- nil
158
- end
159
163
  end
164
+ rescue LoadError
165
+ puts <<-EOM
166
+ Error: In order to use ec2, you need to install the amazon-ec2 gem
167
+
168
+ Ec2 is the default remoter base for PoolParty. If you intend on using
169
+ a different remoter base, specify it with:
170
+
171
+ using :remoter_name
172
+
173
+ in your config file, otherwise, to continue install amazon-ec2 with
174
+
175
+ gem install amazon-ec2
176
+ EOM
160
177
  end