Class: Kumo::Server

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/kumo/server.rb

Overview

The server is an EC2 instance

Class Method Summary collapse

Instance Method Summary collapse

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_allObject

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.tags["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

.launchObject

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

#idObject

Get the ID of the instance



41
42
43
# File 'lib/kumo/server.rb', line 41

def id
  @server.id
end

#launch_timeObject

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_dnsObject

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_dnsObject

Get the public DNS of the instance



61
62
63
# File 'lib/kumo/server.rb', line 61

def public_dns
  @server.dns_name
end

#startObject

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

#stateObject

Get the running state of the instance



51
52
53
# File 'lib/kumo/server.rb', line 51

def state
  @server.state
end

#stopObject

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

#tagObject

Get the tag of the instance



56
57
58
# File 'lib/kumo/server.rb', line 56

def tag
  @server.tags['Name']
end

#terminateObject

Terminate the instance



71
72
73
# File 'lib/kumo/server.rb', line 71

def terminate
  @server.destroy
end