=begin rdoc Remote instances =end module CloudProviders class RemoteInstance include Dslify, Connections attr_reader :name, :init_opts, :raw_response attr_accessor :cloud_provider default_options( :instance_id => nil, :image_id => nil, :status => nil ) def initialize(init_opts={}, &block) @init_opts = init_opts set_vars_from_options(init_opts) instance_eval &block if block after_initialized end def keypair(n=nil) @keypair ||= n.nil? ? nil : Keypair.new(n) end def after_initialized end def accessible? ping_port(public_ip, 22, 40) end def rsync_dir(dir) rsync :source => dir/"*", :destination => "/" end def chef_bootstrapped? # do_sudo is false cause we want to capture the return code of the call @chef_bootstrapped ||= cloud.chef.node_bootsrapped?(self) end def bootstrap_chef! <<<<<<< HEAD:lib/cloud_providers/remote_instance.rb unless chef_bootstrapped? ssh([ 'apt-get update', 'apt-get autoremove -y', 'apt-get install -y ruby ruby-dev rubygems git-core libopenssl-ruby', 'gem sources -a http://gems.opscode.com', 'gem install chef ohai --no-rdoc --no-ri' ]) end if bootstrap_gems.size > 0 ssh(bootstrap_gems.collect { |gem| "gem install #{gem} --no-rdoc --no-ri" } ) end end def run_chef! if ENV["CHEF_DEBUG"] debug = "-l debug" else debug = "" end chef_solo_cmd = <<-CMD $GEM_BIN/chef-solo -j /etc/chef/dna.json -c /etc/chef/solo.rb #{debug} CMD envhash = { :GEM_BIN => %q%$(gem env | grep "EXECUTABLE DIRECTORY" | awk "{print \\$4}")% } ssh([chef_solo_cmd.strip.squeeze(' ')], :env => envhash ) ======= cloud.chef.node_bootstrap(self) unless chef_bootstrapped? end def run_chef! cloud.chef.node_run!(self) >>>>>>> 81a7e0df2d02545ff9b22572194a4f115f73906a:lib/cloud_providers/remote_instance.rb end def run warn "#{self.class} does not implement run. Something is wrong" end def default_keypair_path self.class.default_keypair_path end ## provide hash like methods to access and iterate over node attributes def each dsl_options.each{ |k,v| yield k,v } end def [](k) if dsl_options.has_key? k dsl_options[k] else nil end end def []=(k,v) dsl_options[k] = v end def has_key?(key) dsl_options.has_key?(key) end def keys dsl_options.keys end def values dsl_options.values end def to_hash dsl_options end ##end of hash like methods # Is this instance running? def running? !(status =~ /running/).nil? end # Is this instance pending? def pending? !(status =~ /pending/).nil? end # Is this instance terminating? def terminating? !(status =~ /shutting/).nil? end # Has this instance been terminated? def terminated? !(status =~ /terminated/).nil? end # elapsed seconds since node launch time def elapsed_runtime Time.now - Time.parse(launch_time) end def ssh_available? warn "Implemented in cloudprovider instance class. something is wrong" end # def to_s # (cloud ? to_hash.merge(:cloud=>cloud.name) : to_hash) # end private def cloud init_opts.has_key?(:cloud) ? init_opts[:cloud] : nil end def cloud_provider cloud.cloud_provider end end end