lib/poolparty/net/remoter_base.rb in auser-poolparty-1.2.7 vs lib/poolparty/net/remoter_base.rb in auser-poolparty-1.2.8
- old
+ new
@@ -24,21 +24,28 @@
class RemoterBase
include Dslify
include ::PoolParty::Remote
include ::PoolParty::Pinger
- dsl_methods :cloud, # The cloud this remoter_base is a part of
- :keypair,
+ dsl_methods :keypair,
:image_id,
:keypair_name
def initialize(opts={}, &block)
opts.each {|k,v| opts[k] = v.call if v.respond_to?(:call) }
set_vars_from_options opts
instance_eval &block if block
end
+ def cloud(n=nil)
+ if n.nil?
+ @cloud
+ else
+ @cloud = n
+ end
+ end
+
# def evaluate_proc_options(opts)
# if opts.respond_to?(:call)
# opts.call
# elsif opts.respond_to? :each
# if opts.respond_to?(:values) && opts.respond_to?(:keys)
@@ -48,12 +55,16 @@
# end
# end
# opts
# end
+ def self.available_bases
+ @available_bases ||= []
+ end
def self.inherited(arg)
base_name = "#{arg}".downcase.top_level_class.to_sym
+ (available_bases << base_name) unless available_bases.include?(base_name)
(remote_bases << base_name) unless remote_bases.include?(base_name)
end
# def method_missing(meth, *args, &block)
@@ -103,38 +114,38 @@
end
# TODO: Rename and modularize the @inst.status =~ /pending/ so that it works on all
# remoter_bases
def launch_instance!(o={}, &block)
- @cloud = clouds[o[:cloud_name]]
+ @cloud = clouds[o[:cloud_name] || o[:name]]
@inst = launch_new_instance!( dsl_options.merge(o) )
sleep(2)
- @cloud.dputs "#{@cloud.name} launched instance checking for ip..."
+ dputs "#{@cloud.name} launched instance checking for ip..."
# Wait for 10 minutes for the instance to gain an ip if it doesn't already have one
500.times do |i|
if @inst
break if @inst[:ip] && @inst[:ip] =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/
break if @inst[:public_ip] && @inst[:public_ip] =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/
sleep(2)
@inst = describe_instance(@inst)
- @cloud.dprint "."
+ dprint "."
else
@inst = describe_instances.last
- @cloud.dprint "."
+ dprint "."
end
end
dputs "Found an ip"
dputs "#{@cloud.name} Launched instance #{@inst[:ip]}"
dputs " waiting for it to respond"
# Try for 10 minutes to pint port 22
500.times do |i|
- @cloud.dprint "."
+ dprint "."
if ping_port(@inst[:ip], 22)
- @cloud.dputs ""
+ dputs ""
@cloud.started_instance = @inst
@cloud.call_after_launch_instance_callbacks(@inst)
block.call(@inst) if block
@@ -151,10 +162,20 @@
# Called after an instance is launched
def after_launch_instance(instance=nil)
puts "after_launch_instance in remoter_base"
end
+
+ def remoter_base_options(n=nil)
+ if n.nil?
+ dsl_options[:remoter_base_options]
+ else
+ dsl_options[:remoter_base_options] = remote_base.dsl_options.choose do |k,v|
+ v && (v.respond_to?(:empty) ? !v.empty?: true)
+ end
+ end
+ end
#TODO: Remove
# def self.when_instance_is_responding(inst, &block)
# if ping_port(inst.ip, 22)
# block.call if block
@@ -163,20 +184,20 @@
# end
# end
# def when_instance_is_responding(inst, &block);self.class.when_instance_is_responding;end
# TODO: BAD FORM, already defined in connections.rb. Fix this, ASAP
- def self.ping_port(host, port=22, retry_times=400)
- connected = false
- retry_times.times do |i|
- begin
- break if connected = TCPSocket.new(host, port).is_a?(TCPSocket)
- rescue Exception => e
- sleep(2)
- end
- end
- connected
- end
+ # def self.ping_port(host, port=22, retry_times=400)
+ # connected = false
+ # retry_times.times do |i|
+ # begin
+ # break if connected = TCPSocket.new(host, port).is_a?(TCPSocket)
+ # rescue Exception => e
+ # sleep(2)
+ # end
+ # end
+ # connected
+ # end
# After launch callback
# This is called after a new instance is launched
def after_launched(force=false)
end
\ No newline at end of file