Class: PoolParty::Remote::RemoterBase
Overview
This class is the base class for all remote types, such as ec2 Everything remoting-wise is derived from this class
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Pinger
included
#are_any_nodes_exceeding_minimum_runtime?, #are_too_few_instances_running?, #are_too_many_instances_running?, available, #commands, #execute!, #list_of_instances, #list_of_nodes_exceeding_minimum_runtime, #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
Constructor Details
#initialize(opts = {}, &block) ⇒ RemoterBase
39
40
41
42
43
|
# File 'lib/poolparty/net/remoter_base.rb', line 39
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
|
Class Method Details
.available_bases ⇒ Object
TODO: deprecate these two methods, use Remote.available
81
82
83
|
# File 'lib/poolparty/net/remoter_base.rb', line 81
def self.available_bases
Remote.available.collect{|b| b.name.split('::').pop.snake_case.to_sym}
end
|
.describe_instance(o = {}) ⇒ Object
Describe an instance’s status. Should return a hash like object Required keys are: :image_id :keypair_name :instance_id :status
125
126
127
|
# File 'lib/poolparty/net/remoter_base.rb', line 125
def self.describe_instance(o={})
new(o).describe_instance(o)
end
|
.describe_instances(o = {}) ⇒ Object
Get instances The instances must return an object responding to each Each yielded object must respond to [:status]
135
136
137
|
# File 'lib/poolparty/net/remoter_base.rb', line 135
def self.describe_instances(o={})
new(o).describe_instances(o)
end
|
.inherited(subclass) ⇒ Object
45
46
47
48
49
|
# File 'lib/poolparty/net/remoter_base.rb', line 45
def self.inherited(subclass)
unless Remote.available.include?(subclass)
Remote.available << subclass
end
end
|
.launch_instance!(o = {}, &block) ⇒ Object
191
192
193
|
# File 'lib/poolparty/net/remoter_base.rb', line 191
def self.launch_instance!(o={}, &block)
new(o, &block).launch_instance!
end
|
.launch_new_instance!(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
104
105
106
|
# File 'lib/poolparty/net/remoter_base.rb', line 104
def self.launch_new_instance!(o={})
new(o).launch_new_instance!(o)
end
|
Returns a :remote_base_name symbol for the remoter base name
86
87
88
|
# File 'lib/poolparty/net/remoter_base.rb', line 86
def self.symbol
name.top_level_class.to_sym
end
|
.terminate_instance!(o = {}) ⇒ Object
Terminate an instance by id
112
113
114
|
# File 'lib/poolparty/net/remoter_base.rb', line 112
def self.terminate_instance!(o={})
new(o).terminate_instance!(o)
end
|
Instance Method Details
#after_launch_instance(instance = nil) ⇒ Object
Called after an instance is launched
200
201
202
|
# File 'lib/poolparty/net/remoter_base.rb', line 200
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
239
240
|
# File 'lib/poolparty/net/remoter_base.rb', line 239
def after_launched(force=false)
end
|
#before_shutdown ⇒ Object
Before shutdown callback This is called before the cloud is contracted
244
245
|
# File 'lib/poolparty/net/remoter_base.rb', line 244
def before_shutdown
end
|
#cloud(n = nil) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/poolparty/net/remoter_base.rb', line 51
def cloud(n=nil)
if n.nil?
@cloud
else
@cloud = n
end
end
|
#describe_instance(o = {}) ⇒ Object
128
129
130
|
# File 'lib/poolparty/net/remoter_base.rb', line 128
def describe_instance(o={})
raise RemoteException.new(:method_not_defined, "describe_instance")
end
|
#describe_instances(o = {}) ⇒ Object
138
139
140
|
# File 'lib/poolparty/net/remoter_base.rb', line 138
def describe_instances(o={})
raise RemoteException.new(:method_not_defined, "describe_instances")
end
|
63
64
65
|
# File 'lib/poolparty/net/remoter_base.rb', line 63
def key_name
keypair.basename
end
|
59
60
61
|
# File 'lib/poolparty/net/remoter_base.rb', line 59
def keypair
cloud.keypair
end
|
#launch_instance!(o = {}, &block) ⇒ Object
TODO: Rename and modularize the @inst.status =~ /pending/ so that it works on all 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 passed &block, if any
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
# File 'lib/poolparty/net/remoter_base.rb', line 149
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)
dputs "#{@cloud.name} launched instance checking for ip..."
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)
dprint "."
else
@inst = describe_instances.last
dprint "."
end
end
dputs "Found an ip"
dputs "#{@cloud.name} Launched instance #{@inst[:ip]}"
dputs " waiting for it to respond"
500.times do |i|
dprint "."
if ping_port(@inst[:ip], 22)
dputs ""
@cloud.started_instance = @inst
@cloud.call_after_launch_instance_callbacks(@inst)
block.call(@inst) if block
return @inst
end
sleep(2)
end
raise "Instance not responding at #{inst.ip}"
end
|
#launch_new_instance!(o = {}) ⇒ Object
107
108
109
|
# File 'lib/poolparty/net/remoter_base.rb', line 107
def launch_new_instance!(o={})
raise RemoteException.new(:method_not_defined, "launch_new_instance!")
end
|
#remoter_base_options(n = nil) ⇒ Object
204
205
206
207
208
209
210
211
212
|
# File 'lib/poolparty/net/remoter_base.rb', line 204
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
|
#terminate_instance!(o = {}) ⇒ Object
115
116
117
|
# File 'lib/poolparty/net/remoter_base.rb', line 115
def terminate_instance!(o={})
raise RemoteException.new(:method_not_defined, "terminate_instance!")
end
|
#terminate_youngest_instance!(o = {}) ⇒ Object
195
196
197
|
# File 'lib/poolparty/net/remoter_base.rb', line 195
def terminate_youngest_instance!(o={})
terminate_instance!(:instance_id => nodes(:status => "running").last.instance_id)
end
|
251
252
253
|
# File 'lib/poolparty/net/remoter_base.rb', line 251
def to_hash
dsl_options
end
|
247
248
249
|
# File 'lib/poolparty/net/remoter_base.rb', line 247
def to_s
self.class.name
end
|