Class: PoolParty::Remote::RemoterBase
- Includes:
- Dslify, PoolParty::Remote
- Defined in:
- lib/poolparty/net/remoter_base.rb
Overview
This class is the base class for all remote types, such as ec2 Everything remoting-wise is derived from this class
Instance Attribute Summary collapse
-
#cloud ⇒ Object
readonly
Returns the value of attribute cloud.
Class Method Summary collapse
-
.describe_instance(cld, o = {}) ⇒ Object
Describe an instance’s status.
-
.describe_instances(cld, o = {}) ⇒ Object
Get instances The instances must have a status associated with them on the hash.
- .launch_instance!(cld, o = {}, &block) ⇒ Object
-
.launch_new_instance!(cld, o = {}) ⇒ Object
Required methods The next methods are required on all RemoteInstance types If your RemoteInstance type does not overwrite the following methods An exception will be raised and poolparty will explode into tiny little pieces.
-
.ping_port(host, port = 22, retry_times = 400) ⇒ Object
TODO: BAD FORM, already defined in connections.rb.
-
.terminate_instance!(cld, o = {}) ⇒ Object
Terminate an instance by id.
Instance Method Summary collapse
-
#after_launch_instance(instance = nil) ⇒ Object
Called after an instance is launched.
-
#after_launched(force = false) ⇒ Object
After launch callback This is called after a new instance is launched.
-
#before_shutdown ⇒ Object
Before shutdown callback This is called before the cloud is contracted.
- #describe_instance(o = {}) ⇒ Object
- #describe_instances(o = {}) ⇒ Object
-
#initialize(prnt, opts = {}, &block) ⇒ RemoterBase
constructor
A new instance of RemoterBase.
-
#launch_instance!(o = {}, &block) ⇒ Object
TODO: Rename and modularize the @inst.status =~ /pending/ so that it works on all remoter_bases.
- #launch_new_instance!(o = {}) ⇒ Object
- #terminate_instance!(o = {}) ⇒ Object
Methods included from PoolParty::Remote
#_nodes, #are_any_nodes_exceeding_minimum_runtime?, #are_too_few_instances_running?, #are_too_many_instances_running?, #commands, #execute!, #is_master_running?, #list_of_instances, #list_of_nodes_exceeding_minimum_runtime, #master, #netssh, #nodes, #remote_rsync_command, #remote_ssh_array, #remote_ssh_string, #rsync, #rsync_command, #rsync_storage_files_to, #rsync_storage_files_to_command, #rsync_to, #rsync_to_command, #run_command_on, #run_command_on_command, #run_command_on_instance_number, #run_local, #run_remote, #scp_array, #scp_to_command, #simplest_run_remote, #ssh_array, #ssh_command, #ssh_into, #ssh_into_instance_number, #ssh_options, #ssh_string, #target_host
Methods included from Pinger
Constructor Details
#initialize(prnt, opts = {}, &block) ⇒ RemoterBase
Returns a new instance of RemoterBase.
31 32 33 34 35 |
# File 'lib/poolparty/net/remoter_base.rb', line 31 def initialize(prnt, opts={}, &block) prnt..merge(opts) if prnt && prnt.respond_to?(:options) instance_eval &block if block @cloud = prnt end |
Instance Attribute Details
#cloud ⇒ Object (readonly)
Returns the value of attribute cloud.
29 30 31 |
# File 'lib/poolparty/net/remoter_base.rb', line 29 def cloud @cloud end |
Class Method Details
.describe_instance(cld, o = {}) ⇒ Object
Describe an instance’s status
68 69 70 |
# File 'lib/poolparty/net/remoter_base.rb', line 68 def self.describe_instance(cld, o={}) new(cld, o).describe_instance(o) end |
.describe_instances(cld, o = {}) ⇒ Object
Get instances The instances must have a status associated with them on the hash
77 78 79 |
# File 'lib/poolparty/net/remoter_base.rb', line 77 def self.describe_instances(cld, o={}) new(cld, o).describe_instances(o) end |
.launch_instance!(cld, o = {}, &block) ⇒ Object
121 122 123 |
# File 'lib/poolparty/net/remoter_base.rb', line 121 def self.launch_instance!(cld, o={}, &block) new(cld, o, &block).launch_instance! end |
.launch_new_instance!(cld, o = {}) ⇒ Object
Required methods The next methods are required on all RemoteInstance types If your RemoteInstance type does not overwrite the following methods An exception will be raised and poolparty will explode into tiny little pieces. Don’t forget to overwrite these methods Launch a new instance
52 53 54 |
# File 'lib/poolparty/net/remoter_base.rb', line 52 def self.launch_new_instance!(cld, o={}) new(cld, o).launch_new_instance!(o) end |
.ping_port(host, port = 22, retry_times = 400) ⇒ Object
TODO: BAD FORM, already defined in connections.rb. Fix this, ASAP
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/poolparty/net/remoter_base.rb', line 141 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 |
.terminate_instance!(cld, o = {}) ⇒ Object
Terminate an instance by id
60 61 62 |
# File 'lib/poolparty/net/remoter_base.rb', line 60 def self.terminate_instance!(cld, o={}) new(cld, o).terminate_instance!(o) end |
Instance Method Details
#after_launch_instance(instance = nil) ⇒ Object
Called after an instance is launched
126 127 128 |
# File 'lib/poolparty/net/remoter_base.rb', line 126 def after_launch_instance(instance=nil) puts "after_launch_instance in remoter_base" end |
#after_launched(force = false) ⇒ Object
After launch callback This is called after a new instance is launched
155 156 |
# File 'lib/poolparty/net/remoter_base.rb', line 155 def after_launched(force=false) end |
#before_shutdown ⇒ Object
Before shutdown callback This is called before the cloud is contracted
160 161 |
# File 'lib/poolparty/net/remoter_base.rb', line 160 def before_shutdown end |
#describe_instance(o = {}) ⇒ Object
71 72 73 |
# File 'lib/poolparty/net/remoter_base.rb', line 71 def describe_instance(o={}) raise RemoteException.new(:method_not_defined, "describe_instance") end |
#describe_instances(o = {}) ⇒ Object
80 81 82 |
# File 'lib/poolparty/net/remoter_base.rb', line 80 def describe_instances(o={}) raise RemoteException.new(:method_not_defined, "describe_instances") end |
#launch_instance!(o = {}, &block) ⇒ Object
TODO: Rename and modularize the @inst.status =~ /pending/ so that it works on all remoter_bases
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/poolparty/net/remoter_base.rb', line 86 def launch_instance!(o={}, &block) @inst = launch_new_instance!( o ) sleep(2) cloud.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| break if @inst[:ip] =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/ sleep(2) @inst = describe_instance(@inst) cloud.dprint "." end cloud.dputs "Found an ip" cloud.dputs "#{@cloud.name} Launched instance #{@inst[:ip]}" cloud.dputs " waiting for it to respond" # Try for 10 minutes to pint port 22 500.times do |i| cloud.dprint "." if ping_port(@inst[:ip], 22) cloud.dputs "" cloud.started_instance = @inst cloud.call_after_launch_instance_callbacks(@inst) block.call(@inst) if block # after_launch_instance(@inst) cloud.call_after_launch_instance_callbacks(@inst) return @inst end sleep(2) end raise "Instance not responding at #{inst.ip}" end |
#launch_new_instance!(o = {}) ⇒ Object
55 56 57 |
# File 'lib/poolparty/net/remoter_base.rb', line 55 def launch_new_instance!(o={}) raise RemoteException.new(:method_not_defined, "launch_new_instance!") end |
#terminate_instance!(o = {}) ⇒ Object
63 64 65 |
# File 'lib/poolparty/net/remoter_base.rb', line 63 def terminate_instance!(o={}) raise RemoteException.new(:method_not_defined, "terminate_instance!") end |