lib/poolparty/net/remote_instance.rb in poolparty-0.2.84 vs lib/poolparty/net/remote_instance.rb in poolparty-1.2.2

- old
+ new

@@ -1,21 +1,16 @@ -require File.dirname(__FILE__) + "/remoter" - module PoolParty module Remote class RemoteInstance - include Remote - include Configurable - include CloudResourcer + include Dslify - def initialize(opts, parent=self) - run_setup(parent) + def initialize(opts={}, containing_cloud=nil) + @parent = containing_cloud - set_vars_from_options(parent.options) if parent && parent.respond_to?(:options) - set_vars_from_options(opts) unless opts.nil? || opts.empty? - + set_vars_from_options(containing_cloud.options) if containing_cloud && containing_cloud.respond_to?(:options) + set_vars_from_options(opts) if opts.is_a?(Hash) on_init end def elapsed_runtime Time.now.to_i - launching_time.to_time.to_i @@ -23,78 +18,65 @@ # Callback def on_init end - # Is this remote instance the master? - def master? - name == "master" - end - # The remote instances is only valid if there is an ip and a name def valid? - !(ip.nil? || name.nil?) + (ip.nil? || name.nil?) ? false : true end # Determine if the RemoteInstance is responding def responding? - !responding.nil? + running? + # !responding.nil? #TODO MF this needs to actually ping the node or something similar. stubbed to running? for now end # This is how we get the current load of the instance # The approach of this may change entirely, but the usage of # it will always be the same def load - current_load ||= 0.0 + current_load ||= 0.0 #NOTE MF: returning 0.0 seems like a bad idea here. should return nil if we dont have a real value end - + + # Note, the next 4 methods will be overridden by the cloud specific remoter_base # Is this instance running? def running? - !(status =~ /running/).nil? + true end # Is this instance pending? def pending? - !(status =~ /pending/).nil? + false end # Is this instance terminating? def terminating? - !(status =~ /shutting/).nil? + false end # Has this instance been terminated? def terminated? - !(status =~ /terminated/).nil? + false end # Printing. This is how we extract the instances into the listing on the # local side into the local listing file def to_s - "#{name}\t#{ip}\t#{instance_id}" + "#{name}\t#{ip}\t#{instance_id rescue ""}" end - def puppet_runner_command - self.class.send :puppet_runner_command + # Class method to disect a neighborhood line + def self.hash_from_s(s) + arr = s.split("\t") + {:name => arr[0], :ip => arr[1]} end - # Commands for the servers - def self.puppet_runner_command - ". /etc/profile && puppetrunner" + + def self.to_s(hsh) + new(hsh).to_s end - def self.puppet_master_rerun_command - ". /etc/profile && puppetrerun" - end - def self.puppet_rerun_commad - puppet_runner_command - end - def cloud - @pa = parent - while !(@pa.is_a?(PoolParty::Cloud::Cloud) || @pa.nil? || @pa == self) - @pa = @pa.parent - end - @pa - end + def hosts_file_listing_for(cl) - string = (cl.name == cloud.name) ? "#{name}.#{cloud.name}\t#{name}" : "#{name}.#{cloud.name}" + string = (cl.name == cloud.name) ? "#{name}.#{my_cloud.name}\t#{name}" : "#{name}.#{my_cloud.name}" "#{internal_ip}\t#{string}" end end end -end \ No newline at end of file +end