Class: Kumo::Server
Overview
The server is an EC2 instance
Class Method Summary collapse
-
.find_all ⇒ Object
Find all instances.
-
.find_by_id(id) ⇒ Object
Find an instance by id.
-
.launch ⇒ Object
Launch an instance.
Instance Method Summary collapse
-
#<=>(other_server) ⇒ Object
:nodoc:.
-
#id ⇒ Object
Get the ID of the instance.
-
#initialize(fog_server) ⇒ Server
constructor
Create a new instance based on a fog server.
-
#launch_time ⇒ Object
Get the launch time of the instance.
-
#private_dns ⇒ Object
Get the private DNS of the instance.
-
#public_dns ⇒ Object
Get the public DNS of the instance.
-
#start ⇒ Object
Start the instance.
-
#state ⇒ Object
Get the running state of the instance.
-
#stop ⇒ Object
Stop the instance.
-
#tag ⇒ Object
Get the tag of the instance.
-
#terminate ⇒ Object
Terminate the instance.
Constructor Details
#initialize(fog_server) ⇒ Server
Create a new instance based on a fog server
36 37 38 |
# File 'lib/kumo/server.rb', line 36 def initialize(fog_server) @server = fog_server end |
Class Method Details
.find_all ⇒ Object
Find all instances
16 17 18 19 20 21 22 |
# File 'lib/kumo/server.rb', line 16 def self.find_all infra.servers.select do |server| (server.["Name"] == Kumo.config[:tag]) && (server.state != "terminated") end.map do |server| Server.new(server) end.sort end |
.find_by_id(id) ⇒ Object
Find an instance by id
id
-
the id of the instance
11 12 13 |
# File 'lib/kumo/server.rb', line 11 def self.find_by_id(id) Server.new(infra.servers.get(id)) end |
.launch ⇒ Object
Launch an instance
25 26 27 28 29 30 31 32 33 |
# File 'lib/kumo/server.rb', line 25 def self.launch Server.new(infra.servers.create( :image_id => Kumo.config[:'image-id'], :flavor_id => Kumo.config[:'type-id'], :key_name => Kumo.config[:keypair], :groups => Kumo.config[:groups], :tags => { 'Name' => Kumo.config[:tag] } )) end |
Instance Method Details
#<=>(other_server) ⇒ Object
:nodoc:
90 91 92 93 94 95 96 97 98 |
# File 'lib/kumo/server.rb', line 90 def <=>(other_server) if self.launch_time < other_server.launch_time -1 elsif self.launch_time > other_server.launch_time 1 else 0 end end |
#id ⇒ Object
Get the ID of the instance
41 42 43 |
# File 'lib/kumo/server.rb', line 41 def id @server.id end |
#launch_time ⇒ Object
Get the launch time of the instance
46 47 48 |
# File 'lib/kumo/server.rb', line 46 def launch_time @server.created_at end |
#private_dns ⇒ Object
Get the private DNS of the instance
66 67 68 |
# File 'lib/kumo/server.rb', line 66 def private_dns @server.private_dns_name end |
#public_dns ⇒ Object
Get the public DNS of the instance
61 62 63 |
# File 'lib/kumo/server.rb', line 61 def public_dns @server.dns_name end |
#start ⇒ Object
Start the instance
76 77 78 79 80 |
# File 'lib/kumo/server.rb', line 76 def start if @server.state == "stopped" @server.start end end |
#state ⇒ Object
Get the running state of the instance
51 52 53 |
# File 'lib/kumo/server.rb', line 51 def state @server.state end |
#stop ⇒ Object
Stop the instance
83 84 85 86 87 |
# File 'lib/kumo/server.rb', line 83 def stop if @server.state == "running" @server.stop end end |
#tag ⇒ Object
Get the tag of the instance
56 57 58 |
# File 'lib/kumo/server.rb', line 56 def tag @server.['Name'] end |
#terminate ⇒ Object
Terminate the instance
71 72 73 |
# File 'lib/kumo/server.rb', line 71 def terminate @server.destroy end |