lib/poolparty/net/remoter_base.rb in auser-poolparty-1.2.10 vs lib/poolparty/net/remoter_base.rb in auser-poolparty-1.2.11

- old
+ new

@@ -16,36 +16,56 @@ register_remote_base :remote_base_name =end module PoolParty - module Remote + module Remote + + def self.available + @available ||= [] + end + # This class is the base class for all remote types, such as ec2 # Everything remoting-wise is derived from this class class RemoterBase - include Dslify - include ::PoolParty::Remote - include ::PoolParty::Pinger + include Dslify + include ::PoolParty::Remote + include ::PoolParty::Pinger + # All inheriting remoter bases should override these default_options 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 self.inherited(subclass) + unless Remote.available.include?(subclass) + Remote.available << subclass + end + end + def cloud(n=nil) if n.nil? @cloud else @cloud = n end end + def keypair + cloud.keypair + end + + def key_name + keypair.basename + 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) @@ -55,17 +75,18 @@ # end # end # opts # end + #TODO: deprecate these two methods, use Remote.available def self.available_bases - @available_bases ||= [] + Remote.available.collect{|b| b.name.split('::').pop.snake_case.to_sym} 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) #TODO: Deprecate + + # Returns a :remote_base_name symbol for the remoter base name + def self.symbol + name.top_level_class.to_sym end # def method_missing(meth, *args, &block) # if @cloud # @cloud.send meth, *args, &block rescue super @@ -93,20 +114,26 @@ end def terminate_instance!(o={}) raise RemoteException.new(:method_not_defined, "terminate_instance!") end - # Describe an instance's status + # Describe an instance's status. Should return a hash like object + #Required keys are: + # :image_id + # :keypair_name + # :instance_id + # :status def self.describe_instance(o={}) new(o).describe_instance(o) end def describe_instance(o={}) raise RemoteException.new(:method_not_defined, "describe_instance") end # Get instances - # The instances must have a status associated with them on the hash + # The instances must return an object responding to each + # Each yielded object must respond to [:status] def self.describe_instances(o={}) new(o).describe_instances(o) end def describe_instances(o={}) raise RemoteException.new(:method_not_defined, "describe_instances") @@ -116,10 +143,10 @@ # remoter_bases # 1.) Launches a new instance, # 2.) Waits for the instance to get an ip address # 3.) Waits for port 22 to be open # 4.) Calls call_after_launch_instance callbacks - # 5.) Executes passes block, if any + # 5.) Executes passed &block, if any def launch_instance!(o={}, &block) @cloud = clouds[o[:cloud_name] || o[:name]] o[:keypair_name] = @cloud.keypair.basename @inst = launch_new_instance!( dsl_options.merge(o) ) sleep(2) \ No newline at end of file