auser-poolparty 1.2.7 → 1.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/README.txt +1 -1
  2. data/VERSION.yml +1 -1
  3. data/bin/cloud-configure +1 -1
  4. data/bin/cloud-contract +1 -1
  5. data/bin/cloud-expand +1 -1
  6. data/bin/cloud-list +3 -3
  7. data/bin/cloud-ssh +1 -1
  8. data/bin/cloud-start +1 -1
  9. data/bin/server-cloud-elections +17 -23
  10. data/bin/server-list-active +24 -16
  11. data/bin/server-manage-election +13 -21
  12. data/bin/server-show-stats +1 -1
  13. data/examples/metavirt_cloud.rb +12 -8
  14. data/examples/{poolparty.rb → simple.rb} +0 -0
  15. data/examples/vmrun_cloud.rb +20 -0
  16. data/lib/poolparty/core/proc.rb +0 -7
  17. data/lib/poolparty/dependency_resolver/chef_resolver.rb +1 -1
  18. data/lib/poolparty/dependency_resolver/puppet.rb +0 -1
  19. data/lib/poolparty/helpers/console.rb +0 -5
  20. data/lib/poolparty/modules/callbacks.rb +7 -0
  21. data/lib/poolparty/modules/cloud_dsl.rb +0 -6
  22. data/lib/poolparty/modules/cloud_resourcer.rb +38 -20
  23. data/lib/poolparty/modules/searchable_paths.rb +5 -1
  24. data/lib/poolparty/net/init.rb +17 -4
  25. data/lib/poolparty/net/remoter/interactive.rb +1 -1
  26. data/lib/poolparty/net/remoter_base.rb +40 -19
  27. data/lib/poolparty/net/remoter_bases/ec2/ec2.rb +7 -2
  28. data/lib/poolparty/net/remoter_bases/ec2/ec2_remote_instance.rb +1 -0
  29. data/lib/poolparty/net/remoter_bases/ec2/ec2_response_object.rb +2 -2
  30. data/lib/poolparty/net/remoter_bases/metavirt/metavirt.rb +21 -20
  31. data/lib/poolparty/plugins/apache2/apache.rb +24 -4
  32. data/lib/poolparty/plugins/authorized_key.rb +29 -0
  33. data/lib/poolparty/plugins/chef.rb +2 -2
  34. data/lib/poolparty/plugins/deploy_directory.rb +7 -2
  35. data/lib/poolparty/poolparty/cloud.rb +110 -23
  36. data/lib/poolparty/poolparty/plugin_model.rb +1 -0
  37. data/lib/poolparty/poolparty/poolparty_base_class.rb +25 -3
  38. data/lib/poolparty/poolparty/resource.rb +1 -6
  39. data/lib/poolparty/provision/boot_strapper.rb +5 -1
  40. data/lib/poolparty/resources/directory.rb +1 -1
  41. data/lib/poolparty/resources/symlink.rb +9 -2
  42. data/lib/poolparty/resources/user.rb +16 -1
  43. data/lib/poolparty/schema.rb +3 -4
  44. data/lib/poolparty/templates/haproxy.conf +1 -1
  45. data/lib/poolparty.rb +1 -1
  46. data/spec/poolparty/core/object_spec.rb +0 -24
  47. data/spec/poolparty/fixtures/fake_key.pub +1 -0
  48. data/spec/poolparty/modules/searchable_paths_spec.rb +12 -5
  49. data/spec/poolparty/net/remoter_bases/ec2_spec.rb +1 -1
  50. data/spec/poolparty/plugins/authorized_key_spec.rb +23 -0
  51. data/spec/poolparty/poolparty/cloud_spec.rb +3 -3
  52. data/test/poolparty/dependency_resolver/puppet_resolver_test.rb +1 -1
  53. data/test/poolparty/net/remoter_bases/metavirt/metavirt_test.rb +1 -4
  54. data/test/poolparty/poolparty/cloud_test.rb +40 -0
  55. data/test/test_helper.rb +1 -1
  56. metadata +8 -10
  57. data/lib/poolparty/core/metaid.rb +0 -15
  58. data/lib/poolparty/core/module.rb +0 -40
  59. data/lib/poolparty/helpers/display.rb +0 -30
  60. data/lib/poolparty/net/remote_bases.rb +0 -22
  61. data/spec/poolparty/core/module_spec.rb +0 -15
  62. data/spec/poolparty/helpers/display_spec.rb +0 -13
  63. data/spec/poolparty/id_rsa +0 -27
data/README.txt CHANGED
@@ -44,7 +44,7 @@ sudo gem install auser-poolparty
44
44
 
45
45
  (The MIT License)
46
46
 
47
- Copyright (c) 2008 Ari Lerner
47
+ Copyright (c) 2008 Ari Lerner, CloudTeam
48
48
 
49
49
  Permission is hereby granted, free of charge, to any person obtaining
50
50
  a copy of this software and associated documentation files (the
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 2
3
- :patch: 7
3
+ :patch: 8
4
4
  :major: 1
data/bin/cloud-configure CHANGED
@@ -25,7 +25,7 @@ EOS
25
25
  puts "No nodes to bootstrap"
26
26
  else
27
27
  if command[:inst_num]
28
- vputs "\nConfiguring: #{nodes[o.inst_num]}\n--------------------"
28
+ vputs "\nConfiguring: #{cld.nodes[o.inst_num]}\n--------------------"
29
29
  address = cld.nodes(:status => "running")[ command[:inst_num] ]
30
30
  ::PoolParty::Provision::DrConfigure.new( address[:ip], :cloud => cld )
31
31
  else
data/bin/cloud-contract CHANGED
@@ -17,7 +17,7 @@ EOS
17
17
  run do |command|
18
18
  @loaded_clouds.each do |cld|
19
19
 
20
- puts header("Contracting cloud #{cld.name}")
20
+ puts "Contracting cloud #{cld.name}"
21
21
  puts "#{cld.nodes(:status => "running").size} running instances (#{cld.minimum_instances} minimum instances)"
22
22
  puts testing ? "Not contracting (test mode)" : "Contracting the cloud if possible"
23
23
 
data/bin/cloud-expand CHANGED
@@ -17,7 +17,7 @@ EOS
17
17
  run do |command|
18
18
  @loaded_clouds.each do |cld|
19
19
 
20
- vputs header("Expanding cloud #{cld.name}")
20
+ vputs "Expanding cloud #{cld.name}"
21
21
  vputs "#{cld.nodes(:status => "running").size} running instances of #{cld.maximum_instances} possible instances"
22
22
  vputs testing ? "Not expanding (test mode)" : "Expanding the cloud"
23
23
 
data/bin/cloud-list CHANGED
@@ -23,12 +23,12 @@ EOS
23
23
  require 'pp'
24
24
  pp result = cld.describe_instance(:instance_id=>command[:instance_id])
25
25
  else
26
- puts header("Listing cloud #{cld.name}")
27
- puts subheader("Active instances")
26
+ puts "Listing cloud #{cld.name}"
27
+ puts "Active instances"
28
28
  puts cld.nodes(:status => "running").map{|a| "#{a[:instance_id] || a[:id]}\t#{a[:ip] ||a[:public_ip] }" }.join("\n")
29
29
 
30
30
  if cld.nodes(:status => "pending").size > 0
31
- puts subheader("Pending instances")
31
+ puts "Pending instances"
32
32
  puts cld.nodes(:status => "pending").map{|a| "#{a[:instance_id] || a[:id]}\t#{a[:ip] ||a[:public_ip] }" }.join("\n")
33
33
  end
34
34
  end
data/bin/cloud-ssh CHANGED
@@ -13,7 +13,7 @@ Usage: #{$0} #{all_options_string}
13
13
  EOS
14
14
 
15
15
  short_desc "ssh into an instance of the cloud"
16
- opt :inst_num, "The number of the instance to run bootstrap on", :type => :int
16
+ opt :inst_num, "The number of the instance to ssh to, starts at 0.", :type => :int
17
17
 
18
18
  run do |command|
19
19
  @cloud = @loaded_clouds.first
data/bin/cloud-start CHANGED
@@ -19,7 +19,7 @@ EOS
19
19
  @loaded_clouds.each do |cld|
20
20
 
21
21
  if cld.nodes(:status => "running").size.zero?
22
- puts header("Starting cloud #{cld.name} (#{cld.keypair})")
22
+ puts "Starting cloud #{cld.name} (#{cld.keypair})"
23
23
  puts "#{cld.nodes(:status => "running").size} running instances (#{cld.minimum_instances} - #{cld.maximum_instances})"
24
24
 
25
25
  cld.launch_instance!(:cloud_name => cld.name) do |node|
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
3
  require "poolparty"
4
- require "poolparty/lite"
5
4
 
6
5
  o = PoolParty::Optioner.new(ARGV) do |opts, optioner|
7
6
  opts.on('-n cloudname', '--name name', 'Start cloud by this name') { |c| optioner.cloudname c }
@@ -10,28 +9,23 @@ end
10
9
 
11
10
  vote_for = o.unflagged_args.shift || "none"
12
11
 
13
- schema = ::PoolParty.load_cloud_from_json(o.unflagged_args.shift) #TODO: smarter option parser
14
- remote_base = PoolParty::Remote.module_eval( schema.options.remoter_base.camelcase )
12
+ cld = ::PoolParty::Cloud::Cloud.load_from_json(ENV['CLOUDS_JSON_FILE'] || '/etc/poolparty/clouds.json') #TODO: smarter option parser
15
13
 
16
- o.loaded_clouds.each do |cld|
17
- cld.update_from_schema(schema)
18
- case vote_for
19
- when "expand"
20
- puts "Launching new instance"
21
- `rm /etc/poolparty/neighborhood.json`
22
- cld.send :launch_instance!, schema.options.merge(:cloud_name => cld.name) do |node|
23
- dputs "Started node at #{node[:ip]}"
24
- ::PoolParty::Provision::BootStrapper.new( node[:ip], :cloud => cld )
25
- ::PoolParty::Provision::DrConfigure.new( node[:ip], :cloud => cld )
26
- end
27
-
28
- when "contract"
29
- `rm /etc/poolparty/neighborhood.json`
30
- last_instance_id = %x[server-list-active instance_id].split("\t").last
31
- remote_base.terminate_instance! schema.options.merge(:instance_id => last_instance_id)
32
- else
33
- puts "Unknown action: #{vote_for}"
34
- remote_base.describe_instances
35
- end
14
+ case vote_for
15
+ when "expand"
16
+ puts "Launching new instance"
17
+ cld.launch_instance! do |node|
18
+ dputs "Started node at #{node[:ip]}"
19
+ ::PoolParty::Provision::BootStrapper.new( node[:ip], :cloud => cld )
20
+ ::PoolParty::Provision::DrConfigure.new( node[:ip], :cloud => cld )
21
+ end
36
22
 
23
+ when "contract"
24
+ last_instance_id = %x[server-list-active instance_id].split("\t").last
25
+ cloud.terminate_instance!(:instance_id => last_instance_id)
26
+ when 'none'
27
+ nil
28
+ else
29
+ puts "Unknown action: #{vote_for}"
37
30
  end
31
+
@@ -1,24 +1,32 @@
1
1
  #!/usr/bin/env ruby
2
2
  $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
- require "poolparty/lite"
4
- require "poolparty/core/array"
3
+ # require "poolparty/lite"
4
+ # require "poolparty/core/array"
5
+ require 'poolparty'
5
6
 
6
7
  list_type = ARGV.shift || "ip"
7
8
 
8
- json_file = ARGV[0] || PoolParty::Default.properties_hash_file
9
+ json_file = ARGV[0] || ENV['CLOUD_JSON_FILE'] || PoolParty::Default.properties_hash_file
9
10
  raise "ERROR: no json_file given" if !json_file
10
- schema = PoolParty::Schema.new( ::File.read(json_file) )
11
11
 
12
- inst_array = PoolParty::Neighborhoods.load_default.instances
12
+ cld = Cloud.load_from_json(::File.read(json_file))
13
+ conditions= {:status=>'running', :keypair=>cld.keypair_name}
14
+ inst_array = cld.remote_base.describe_instances.select_with_hash(conditions)
15
+ puts inst_array.collect{|n| n[list_type] || n[list_type.to_sym]}.join("\t")
13
16
 
14
- if !inst_array || inst_array.empty?
15
- remote_base = PoolParty::Remote.module_eval( schema.options.remoter_base.camelcase )
16
- instances = remote_base.send :describe_instances, schema.options
17
- inst_array = instances.map {|inst| inst.send list_type.to_sym }.compact
18
- if ['ip', 'public_id', 'internal_ip'].include? list_type
19
- inst_array.delete_if{|n| !n.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) }
20
- end
21
- print inst_array.compact.join("\t")
22
- else
23
- print inst_array.map {|inst| inst.send list_type.to_sym }.compact.join("\t")
24
- end
17
+
18
+ # schema = PoolParty::Schema.new( ::File.read(json_file) )
19
+ #
20
+ # inst_array = nil #PoolParty::Neighborhoods.load_default.instances
21
+ #
22
+ # if !inst_array || inst_array.empty?
23
+ # remote_base = PoolParty::Remote.module_eval( schema.options.remoter_base.camelcase )
24
+ # instances = remote_base.send :describe_instances, schema.options.keypair_name
25
+ # inst_array = instances.map {|inst| inst.send list_type.to_sym }.compact
26
+ # if ['ip', 'public_id', 'internal_ip'].include? list_type
27
+ # inst_array.delete_if{|n| !n.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) }
28
+ # end
29
+ # print inst_array.compact.join("\t")
30
+ # else
31
+ # print inst_array.map {|inst| inst.send list_type.to_sym }.compact.join("\t")
32
+ # end
@@ -1,29 +1,23 @@
1
1
  #!/usr/bin/env ruby
2
- # Call server-list-active and get the neighborhood ips back
3
- # then call each of those at the port of butterfly and retain the json
4
- # From there, mash it up together and call server-handle-election
5
- # to handle the election process
6
-
7
- # Error codes
8
- # 1 -> clouds.json was not loaded
9
- # 2 -> server-list-active didn't run
10
2
  $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
11
3
  require "rubygems"
12
4
  require 'net/http'
13
5
  require 'json'
14
- require "poolparty/lite"
6
+ #require "poolparty/lite"
7
+ require 'poolparty'
15
8
 
16
9
  status = ARGV.shift || "running" # or pending or terminated
17
- schema = ::PoolParty.load_cloud_from_json(ARGV.shift) #TODO: smarter option parser
10
+ schema = ::PoolParty::Cloud::Cloud.load_from_json(ENV['CLOUDS_JSON_FILE'] || '/etc/poolparty/clouds.json')
18
11
 
19
12
  def get_json_stats_from(ip, port)
20
- Net::HTTP.start(ip, port) {|http| http.get('/stats.json') }.body rescue "{}"
13
+ Net::HTTP.start(ip, port) {|http| http.get('/stats') }.body rescue "{}"
21
14
  end
22
-
23
- ips = %x[server-list-active internal_ip].split("\t")
24
15
 
25
- minimum_instances = schema.options.minimum_instances
26
- maximum_instances = schema.options.maximum_instances
16
+ #ips = %x[server-list-active internal_ip].split("\t")
17
+ ips = schema.describe_instances.select_with_hash(:status=>'running').collect{|n| n.ip} #TODO: needs to filter to only this cloud
18
+
19
+ minimum_instances = schema.dsl_options.minimum_instances
20
+ maximum_instances = schema.dsl_options.maximum_instances
27
21
 
28
22
  if ips.size < minimum_instances
29
23
  puts "Cloud is too small, need to expand"
@@ -31,7 +25,7 @@ if ips.size < minimum_instances
31
25
  exit(0)
32
26
  elsif ips.size > maximum_instances
33
27
  puts "Cloud is too big, need to contract"
34
- %x[n/server-cloud-elections contract]
28
+ %x[server-cloud-elections contract]
35
29
  exit(0)
36
30
  end
37
31
 
@@ -49,17 +43,15 @@ candidates.each do |action, ballots|
49
43
  end
50
44
  end
51
45
 
52
- puts total_json_hash.inspect
53
- puts candidates.inspect
54
-
55
46
  # Expand the cloud if 50+% of the votes are for expansion
56
47
  # Contract the cloud if 51+% of the votes are for contraction
57
48
  @elected_action = candidates[:elected_action] || "none"
49
+ puts "checking nominations"
58
50
  if (candidates[:expand] - candidates[:contract])/total_json_hash.size > 0.5
59
- %x[/usr/bin/server-cloud-elections expand] unless @elected_action == "expand"
51
+ %x[server-cloud-elections expand] unless @elected_action == "expand"
60
52
  @elected_action = "expand"
61
53
  elsif (candidates[:contract] - candidates[:expand])/total_json_hash.size > 0.5
62
- %x[/usr/bin/server-cloud-elections contract] unless @elected_action == "contract"
54
+ %x[server-cloud-elections contract] unless @elected_action == "contract"
63
55
  @elected_action = "contract"
64
56
  end
65
57
 
@@ -10,7 +10,7 @@ end
10
10
  o.loaded_clouds.each do |cloud|
11
11
 
12
12
  with_cloud(cloud) do
13
- puts header("Stats")
13
+ puts "Stats"
14
14
  puts rules_values
15
15
  end
16
16
 
@@ -1,18 +1,22 @@
1
- require File.dirname(__FILE__)+"/../lib/poolparty"
1
+ require 'rubygems'
2
+ $:.unshift File.dirname(__FILE__)+'/../lib/'
3
+ require "poolparty"
2
4
 
3
- pool :poolparty do
5
+ pool :multiverse do
4
6
 
5
- cloud :metavirt do
7
+ cloud :vv do
6
8
  keypair "front"
7
- instances 1
9
+ instances 2
10
+ has_file "/etc/motd", :content => "Welcome to your poolparty instance!"
8
11
  using :metavirt do
12
+ server_config({:host=>"172.16.68.1", :port=>3000})
9
13
  authorized_keys 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCTppECfx7Tb0zoviRfqFaePyAek6+ZktKkHiTHu/jkhG1s4q1oHEe89no21xLxuReyJrDlNe8rLxxZzoYCaAWRdhcqMR3BNqb2w2jpF4pH+bFj0557KrwWP6HSNpRRkyYhxLqZbuH/2t3TzkPevZbcfSYa09jIzqnmTruh9l1s+n5E3cNr/RDdDn7tv3Ok7mKN7GEjkK7F83Pt9xviHevg22xqzm99nS+hg6Kl/fQUTO6pOmC5x+9V47RJz1+9WdhGJ7M83zijX9rMnAwrR5LFoL6aZyyU0G71SpoIL5e8XD/jt1WNKFJOfG8YMLb3i03UABm/Q5Q30+R7UoRxSWRX'
10
- server_config = {:host=>'localhost', :port=>3000}
11
14
  using :vmrun do
15
+ # vmx_files Dir[::File.expand_path("~/Documents/Virtual Machines.localized/metavirts/*/*.vmx")]
12
16
  vmx_files [
13
- ::File.expand_path("~/Documents/Virtual\ Machines.localized/Ubuntu-jaunty.vmwarevm/Ubuntu-jaunty.vmx")
14
- ]
15
- puts "i am in the vmrun block"
17
+ "/Users/mfairchild/Documents/Virtual\ Machines.localized/Ubuntu-jaunty.vmwarevm/Ubuntu-jaunty.vmx",
18
+ "/Users/mfairchild/Documents/Virtual\ Machines.localized/metavirts/Ubuntu32bitVM copy.vmwarevm/Ubuntu32bitVM.vmx"
19
+ ]
16
20
  end
17
21
  end
18
22
  end
File without changes
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ $:.unshift File.dirname(__FILE__)+'/../lib/'
3
+ require "poolparty"
4
+
5
+ pool :multiverse do
6
+
7
+ cloud :vv do
8
+ keypair "front"
9
+ instances 2
10
+ has_file "/etc/motd", :content => "Welcome to your poolparty instance!"
11
+ using :vmrun do
12
+ vmx_files [
13
+ "/Users/mfairchild/Documents/Virtual\ Machines.localized/Ubuntu-jaunty.vmwarevm/Ubuntu-jaunty.vmx",
14
+ "/Users/mfairchild/Documents/Virtual\ Machines.localized/metavirts/Ubuntu32bitVM copy.vmwarevm/Ubuntu32bitVM.vmx"
15
+ ]
16
+ end
17
+ end
18
+
19
+ end
20
+
@@ -1,7 +0,0 @@
1
- require 'ruby2ruby'
2
-
3
- class Proc
4
- def to_ruby(opts={})
5
- Ruby2Ruby.new.process(self.to_sexp).gsub(/proc \{/, "do \n#{opts.map {|k,v| "#{k} \"#{v}\""}.join("\n")}\n").sub(/\}/, "\nend")
6
- end
7
- end
@@ -20,7 +20,7 @@
20
20
  =end
21
21
  module PoolParty
22
22
 
23
- class ChefResolver< DependencyResolver
23
+ class ChefResolver < DependencyResolver
24
24
 
25
25
  # Compile and add to the zipper
26
26
  def compile(props=@properties_hash, tabs=0, default_namespace="poolparty")
@@ -30,7 +30,6 @@ module PoolParty
30
30
 
31
31
  returning Array.new do |output|
32
32
  unless cancelled?
33
- output << @prestring || ""
34
33
 
35
34
  if resources && !resources.empty?
36
35
  output << resources_string_from_resources(resources, pre)
@@ -1,10 +1,5 @@
1
- require File.dirname(__FILE__) + "/display"
2
-
3
1
  module PoolParty
4
2
  module Console
5
-
6
- include Display
7
-
8
3
  # Print help commands for the console
9
4
  # level 0 - Basic help
10
5
  # level 1 - Commands
@@ -22,6 +22,13 @@ module PoolParty
22
22
  end
23
23
 
24
24
  # Callbacks on bootstrap and configuration
25
+ # Defines the callback accessors:
26
+ # call_before/after_bootstrap/configure_callbacks
27
+ #
28
+ # When called, this method will first check to see if there
29
+ # are plugins and call those plugin's callbacks when called
30
+ # The method (before/after_bootstrap/configure) is called
31
+ # on self if the callback method is defined on self
25
32
  def setup_callbacks
26
33
  defined_callbacks.each do |meth|
27
34
  unless respond_to?("call_#{meth}_callbacks".to_sym)
@@ -11,12 +11,6 @@ module PoolParty
11
11
  # has_directory(:name => loc)
12
12
  # end
13
13
 
14
- def set_dependency_resolver(name='chef')
15
- klass = name.preserved_class_constant("Resolver")
16
- raise DependencyResolverException.new("Unknown resolver") unless klass
17
- self.dependency_resolver = klass unless dsl_options[:dependency_resolver]
18
- end
19
-
20
14
  # Enable a service package
21
15
  def enable(*services)
22
16
  services.each do |service|
@@ -59,35 +59,53 @@ module PoolParty
59
59
  # Check to make sure the available_bases is available, otherwise raise
60
60
  # Give access to the cloud the remote_base and instantiate a new
61
61
  # instance of the remote base
62
- def using(t, &block)
62
+ def using(t, o={}, &block)
63
63
  return self.send(t) if self.respond_to?(t)
64
- if self.class.available_bases.include?(t.to_sym)
64
+ if ::PoolParty::Remote::RemoterBase.available_bases.include?(t.to_sym)
65
65
  klass_string = "#{t}".classify
66
66
  remote_base_klass = "::PoolParty::Remote::#{klass_string}".constantize
67
67
  set_default_options(remote_base_klass.default_options)
68
- self.remote_base = remote_base_klass.send(:new, dsl_options, &block)
69
- self.remoter_base t.to_sym
70
- instance_eval "def #{t};remote_base;end"
68
+
69
+ @remote_base = remote_base_klass.send(:new, o.merge(:cloud=>self), &block)
70
+ self.remoter_base t.to_sym
71
+ instance_eval "def #{t};@remote_base;end"
72
+
73
+ # instance_eval "def launch_new_instance!(o={}); remote_base.launch_new_instance!;end"
74
+ # instance_eval "def terminate_instance!(o={}); remote_base.terminate_instance!(o);end"
75
+ # instance_eval "def describe_instances(o={}); remote_base.describe_instances;end"
76
+ # instance_eval "def describe_instance(o={}); remote_base.describe_instance(o);end"
71
77
  else
72
78
  raise "Unknown remote base: #{t}"
73
79
  end
74
80
  end
75
-
76
- def update_from_schema(schema)
77
- self.dsl_options.merge! schema.options.to_hash
78
- self.dependency_resolver = schema.options.dependency_resolver.split("::")[-1].gsub(/Resolver/, '').preserved_class_constant("Resolver") rescue PoolParty::Chef
79
- keypair schema.options.keypair_name
80
- remote_base_class = PoolParty::Remote.module_eval( schema.options.remoter_base.camelcase )
81
- self.remote_base = remote_base_class.new schema.options.remote_base.to_hash
82
-
83
- # self.keypair = PoolParty::Key.new schema.options.keypair.basename
84
- # keypair = schema.options.delete(:keypairs).map {|a| PoolParty::Key.new(a.basename) }
85
- # options.merge! schema.options.to_hash
86
- # dsl_options[:keypairs] = keypairs
87
- #
88
- # dsl_options[:dependency_resolver] = schema.options.dependency_resolver.split("::")[-1].gsub(/Resolver/, '').preserved_class_constant("Resolver") rescue PoolParty::Chef
89
-
81
+
82
+ def dependency_resolver(name=nil)
83
+ if !name.nil?
84
+ ext = name=~/Resolver$/ ? nil : 'Resolver'
85
+ klass = ::PoolParty.module_eval("#{name.camelcase}#{ext}")
86
+ raise DependencyResolverException.new("Unknown resolver") unless klass
87
+ dsl_options[:dependency_resolver] = "#{name.camelcase}#{ext}"
88
+ @dependency_resolver = klass
89
+ else
90
+ @dependency_resolver
91
+ end
90
92
  end
93
+
94
+ # def update_from_schema(schema)
95
+ # self.dsl_options.merge! schema.options.to_hash
96
+ # self.dependency_resolver = schema.options.dependency_resolver.split("::")[-1].gsub(/Resolver/, '').preserved_class_constant("Resolver") rescue PoolParty::Chef
97
+ # keypair schema.options.keypair_name
98
+ # remote_base_class = PoolParty::Remote.module_eval( schema.options.remoter_base.camelcase )
99
+ # self.remote_base = remote_base_class.new schema.options.remote_base.to_hash
100
+ #
101
+ # # self.keypair = PoolParty::Key.new schema.options.keypair.basename
102
+ # # keypair = schema.options.delete(:keypairs).map {|a| PoolParty::Key.new(a.basename) }
103
+ # # options.merge! schema.options.to_hash
104
+ # # dsl_options[:keypairs] = keypairs
105
+ # #
106
+ # # dsl_options[:dependency_resolver] = schema.options.dependency_resolver.split("::")[-1].gsub(/Resolver/, '').preserved_class_constant("Resolver") rescue PoolParty::Chef
107
+ #
108
+ # end
91
109
 
92
110
  end
93
111
  end
@@ -73,8 +73,12 @@ module PoolParty
73
73
  # in the searchable_paths.
74
74
  #
75
75
  # Returns +nil+ if the file cannot be found.
76
- def search_in_known_locations(filepath)
76
+ def search_in_known_locations(filepath, additional_search_paths=[])
77
77
  return filepath if ::File.exists?(filepath) # return the file if its an absolute path
78
+ additional_search_paths.each do |path|
79
+ full_path = ::File.expand_path(path / filepath)
80
+ return full_path if ::File.exists?(full_path)
81
+ end
78
82
  self.class.searchable_paths.each do |path|
79
83
  self.class.searchable_paths_dirs.each do |dir|
80
84
  full_path = ::File.expand_path(path / dir / filepath)
@@ -1,10 +1,23 @@
1
+ class Object
2
+ #TODO: deprecate. use RemoterBase.available_bases instead
3
+ def remote_bases
4
+ $remote_bases ||= []
5
+ end
6
+ end
7
+
1
8
  # Load the core net libraries. These are neccessary for any of the remoter_bases to function.
2
- %w(remote_instance remote_bases remoter_base).each do |file|
9
+ %w(remote_instance remoter_base).each do |file|
3
10
  require File.join(::File.dirname(__FILE__),file+'.rb')
4
11
  end
12
+ #
13
+ # # Register available remoter_bases
14
+ # Dir["#{::File.dirname(__FILE__)}/remoter_bases/*/*.rb"].each do |base|
15
+ # name = File.join(::File.basename(base, ::File.extname(base)))
16
+ # require base
17
+ # end
18
+
5
19
 
6
- # Register available remoter_bases
7
- Dir["#{::File.dirname(__FILE__)}/remoter_bases/*/*.rb"].each do |base|
8
- name = File.join(::File.basename(base, ::File.extname(base)))
20
+ Dir["#{::File.dirname(__FILE__)}/remoter_bases/*/*.rb"].each do |base|
21
+ name = ::File.basename(base, ::File.extname(base))
9
22
  require base
10
23
  end
@@ -12,7 +12,7 @@ module PoolParty
12
12
  def list_of_instances(with_neighborhood_default=true)
13
13
  return @list_of_instances if @list_of_instances
14
14
  @containing_cloud = self
15
- n = with_neighborhood_default ? Neighborhoods.load_default : nil
15
+ n = false ? Neighborhoods.load_default : nil
16
16
  @list_of_instances = ((n.nil? || n.instances.empty?) ? _list_of_instances : n.instances)
17
17
  end
18
18
 
@@ -26,8 +26,7 @@ module PoolParty
26
26
  include ::PoolParty::Remote
27
27
  include ::PoolParty::Pinger
28
28
 
29
- dsl_methods :cloud, # The cloud this remoter_base is a part of
30
- :keypair,
29
+ dsl_methods :keypair,
31
30
  :image_id,
32
31
  :keypair_name
33
32
 
@@ -37,6 +36,14 @@ module PoolParty
37
36
  instance_eval &block if block
38
37
  end
39
38
 
39
+ def cloud(n=nil)
40
+ if n.nil?
41
+ @cloud
42
+ else
43
+ @cloud = n
44
+ end
45
+ end
46
+
40
47
  # def evaluate_proc_options(opts)
41
48
  # if opts.respond_to?(:call)
42
49
  # opts.call
@@ -50,8 +57,12 @@ module PoolParty
50
57
  # opts
51
58
  # end
52
59
 
60
+ def self.available_bases
61
+ @available_bases ||= []
62
+ end
53
63
  def self.inherited(arg)
54
64
  base_name = "#{arg}".downcase.top_level_class.to_sym
65
+ (available_bases << base_name) unless available_bases.include?(base_name)
55
66
  (remote_bases << base_name) unless remote_bases.include?(base_name)
56
67
  end
57
68
 
@@ -105,11 +116,11 @@ module PoolParty
105
116
  # TODO: Rename and modularize the @inst.status =~ /pending/ so that it works on all
106
117
  # remoter_bases
107
118
  def launch_instance!(o={}, &block)
108
- @cloud = clouds[o[:cloud_name]]
119
+ @cloud = clouds[o[:cloud_name] || o[:name]]
109
120
  @inst = launch_new_instance!( dsl_options.merge(o) )
110
121
  sleep(2)
111
122
 
112
- @cloud.dputs "#{@cloud.name} launched instance checking for ip..."
123
+ dputs "#{@cloud.name} launched instance checking for ip..."
113
124
 
114
125
  # Wait for 10 minutes for the instance to gain an ip if it doesn't already have one
115
126
  500.times do |i|
@@ -118,10 +129,10 @@ module PoolParty
118
129
  break if @inst[:public_ip] && @inst[:public_ip] =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/
119
130
  sleep(2)
120
131
  @inst = describe_instance(@inst)
121
- @cloud.dprint "."
132
+ dprint "."
122
133
  else
123
134
  @inst = describe_instances.last
124
- @cloud.dprint "."
135
+ dprint "."
125
136
  end
126
137
  end
127
138
  dputs "Found an ip"
@@ -130,9 +141,9 @@ module PoolParty
130
141
 
131
142
  # Try for 10 minutes to pint port 22
132
143
  500.times do |i|
133
- @cloud.dprint "."
144
+ dprint "."
134
145
  if ping_port(@inst[:ip], 22)
135
- @cloud.dputs ""
146
+ dputs ""
136
147
  @cloud.started_instance = @inst
137
148
 
138
149
  @cloud.call_after_launch_instance_callbacks(@inst)
@@ -153,6 +164,16 @@ module PoolParty
153
164
  def after_launch_instance(instance=nil)
154
165
  puts "after_launch_instance in remoter_base"
155
166
  end
167
+
168
+ def remoter_base_options(n=nil)
169
+ if n.nil?
170
+ dsl_options[:remoter_base_options]
171
+ else
172
+ dsl_options[:remoter_base_options] = remote_base.dsl_options.choose do |k,v|
173
+ v && (v.respond_to?(:empty) ? !v.empty?: true)
174
+ end
175
+ end
176
+ end
156
177
 
157
178
  #TODO: Remove
158
179
  # def self.when_instance_is_responding(inst, &block)
@@ -165,17 +186,17 @@ module PoolParty
165
186
  # def when_instance_is_responding(inst, &block);self.class.when_instance_is_responding;end
166
187
 
167
188
  # TODO: BAD FORM, already defined in connections.rb. Fix this, ASAP
168
- def self.ping_port(host, port=22, retry_times=400)
169
- connected = false
170
- retry_times.times do |i|
171
- begin
172
- break if connected = TCPSocket.new(host, port).is_a?(TCPSocket)
173
- rescue Exception => e
174
- sleep(2)
175
- end
176
- end
177
- connected
178
- end
189
+ # def self.ping_port(host, port=22, retry_times=400)
190
+ # connected = false
191
+ # retry_times.times do |i|
192
+ # begin
193
+ # break if connected = TCPSocket.new(host, port).is_a?(TCPSocket)
194
+ # rescue Exception => e
195
+ # sleep(2)
196
+ # end
197
+ # end
198
+ # connected
199
+ # end
179
200
 
180
201
  # After launch callback
181
202
  # This is called after a new instance is launched