Class: CloudProviders::Ssh
- Inherits:
-
CloudProvider
- Object
- CloudProvider
- CloudProviders::Ssh
- Defined in:
- lib/cloud_providers/ssh/ssh.rb
Instance Method Summary collapse
-
#available_hosts ⇒ Object
By default we consider all hosts to be running available_hosts represents those that we are not “running” right now.
-
#describe_instance(opts = {:name=>nil}) ⇒ Object
Returns an instance object for the host.
- #describe_instances(o = {}) ⇒ Object
-
#instance_options(opts) ⇒ Object
Select just the instance options that are relevant to the SshInstance.
- #nodes(hsh = {}) ⇒ Object
-
#run_instance(o = {}) ⇒ Object
Launch a new instance.
- #running_hosts ⇒ Object
-
#terminate_instance!(o = {}) ⇒ Object
Terminate an instance by name, or the last instance.
Methods inherited from CloudProvider
#after_compile, #before_compile, inherited, #initialize, #keypair, #keypair=
Methods included from Callbacks
Constructor Details
This class inherits a constructor from CloudProviders::CloudProvider
Instance Method Details
#available_hosts ⇒ Object
By default we consider all hosts to be running available_hosts represents those that we are not “running” right now
16 17 18 |
# File 'lib/cloud_providers/ssh/ssh.rb', line 16 def available_hosts @available_hosts ||= [] end |
#describe_instance(opts = {:name=>nil}) ⇒ Object
Returns an instance object for the host. You must pass the :name option
53 54 55 56 |
# File 'lib/cloud_providers/ssh/ssh.rb', line 53 def describe_instance(opts={:name=>nil}) raise StandardError.new("you must provide a name") unless opts[:name] SshInstance.new((o.merge(:name=>opts[:name]))) end |
#describe_instances(o = {}) ⇒ Object
58 59 60 |
# File 'lib/cloud_providers/ssh/ssh.rb', line 58 def describe_instances(o={}) hosts.collect{|n| SshInstance.new((o.merge(:name=>n)))} end |
#instance_options(opts) ⇒ Object
Select just the instance options that are relevant to the SshInstance
25 26 27 28 29 |
# File 'lib/cloud_providers/ssh/ssh.rb', line 25 def (opts) i_opts = .merge(opts) # i_opts = SshInstance.default_options.merge(i_opts) # i_opts.choose{|k,v| SshInstance.default_options.keys.include?(k)} end |
#nodes(hsh = {}) ⇒ Object
62 63 64 65 |
# File 'lib/cloud_providers/ssh/ssh.rb', line 62 def nodes(hsh={}) results = running_hosts.collect{|n| SshInstance.new((:name=>n))} results.select_with_hash(hsh) end |
#run_instance(o = {}) ⇒ Object
Launch a new instance
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cloud_providers/ssh/ssh.rb', line 32 def run_instance(o={}) raise StandardError.new("You have no available hosts") if available_hosts.empty? host = available_hosts.first new_host = SshInstance.new((o.merge(:name=>host))) new_host.keypair if new_host && new_host.refresh! available_hosts.delete host new_host else raise StandardError.new("Unable to connect to host #{host}") end end |
#running_hosts ⇒ Object
20 21 22 |
# File 'lib/cloud_providers/ssh/ssh.rb', line 20 def running_hosts hosts - available_hosts end |
#terminate_instance!(o = {}) ⇒ Object
Terminate an instance by name, or the last instance
46 47 48 49 50 |
# File 'lib/cloud_providers/ssh/ssh.rb', line 46 def terminate_instance!(o={}) thost = o[:name] || running_hosts.last available_hosts << thost.clone SshInstance.new((o.merge(:name=>thost, :status=>'terminated'))) end |