Class: Raca::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/raca/server.rb

Overview

Represents a single cloud server. Contains methods for deleting a server, listing IP addresses, checking the state, etc.

You probably don’t want to instantiate this directly, see Raca::Account#servers

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account, region, server_id) ⇒ Server

Returns a new instance of Server.



15
16
17
18
19
20
# File 'lib/raca/server.rb', line 15

def initialize(, region, server_id)
  @account = 
  @region = region
  @servers_url = @account.public_endpoint("cloudServersOpenStack", region)
  @server_id = server_id
end

Instance Attribute Details

#server_idObject (readonly)

Returns the value of attribute server_id.



13
14
15
# File 'lib/raca/server.rb', line 13

def server_id
  @server_id
end

Instance Method Details

#delete!Object



22
23
24
25
# File 'lib/raca/server.rb', line 22

def delete!
  response = servers_client.delete(server_path, json_headers)
  response.is_a? Net::HTTPSuccess
end

#detailsObject

A Hash of various matadata about the server



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

def details
  data = servers_client.get(server_path, json_headers).body
  JSON.parse(data)['server']
end

#inspectObject



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

def inspect
  "#<Raca::Server:#{__id__} region=#{@region} server_id=#{@server_id}>"
end

#private_addressesObject

An array of private IP addresses for the server. They can be ipv4 or ipv6



39
40
41
# File 'lib/raca/server.rb', line 39

def private_addresses
  details['addresses']['private'].map { |i| i["addr"] }
end

#public_addressesObject

An array of public IP addresses for the server. They can be ipv4 or ipv6



45
46
47
# File 'lib/raca/server.rb', line 45

def public_addresses
  details['addresses']['public'].map { |i| i["addr"] }
end

#wait_for_activeObject

Poll Rackspace and return once a server is in an active state. Useful after creating a new server



30
31
32
33
34
35
# File 'lib/raca/server.rb', line 30

def wait_for_active
  until details['status'] == 'ACTIVE'
    log "Not online yet. Waiting..."
    sleep 10
  end
end