class Raca::Server
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
Attributes
server_id[R]
Public Class Methods
new(account, region, server_id)
click to toggle source
# File lib/raca/server.rb 15 def initialize(account, region, server_id) 16 @account = account 17 @region = region 18 @servers_url = @account.public_endpoint("cloudServersOpenStack", region) 19 @server_id = server_id 20 end
Public Instance Methods
delete!()
click to toggle source
# File lib/raca/server.rb 22 def delete! 23 response = servers_client.delete(server_path, json_headers) 24 response.is_a? Net::HTTPSuccess 25 end
details()
click to toggle source
A Hash of various matadata about the server
# File lib/raca/server.rb 51 def details 52 data = servers_client.get(server_path, json_headers).body 53 JSON.parse(data)['server'] 54 end
inspect()
click to toggle source
# File lib/raca/server.rb 56 def inspect 57 "#<Raca::Server:#{__id__} region=#{@region} server_id=#{@server_id}>" 58 end
private_addresses()
click to toggle source
An array of private IP addresses for the server. They can be ipv4 or ipv6
# File lib/raca/server.rb 39 def private_addresses 40 details['addresses']['private'].map { |i| i["addr"] } 41 end
public_addresses()
click to toggle source
An array of public IP addresses for the server. They can be ipv4 or ipv6
# File lib/raca/server.rb 45 def public_addresses 46 details['addresses']['public'].map { |i| i["addr"] } 47 end
wait_for_active()
click to toggle source
Poll Rackspace and return once a server is in an active state. Useful after creating a new server
# File lib/raca/server.rb 30 def wait_for_active 31 until details['status'] == 'ACTIVE' 32 log "Not online yet. Waiting..." 33 sleep 10 34 end 35 end
Private Instance Methods
account_path()
click to toggle source
# File lib/raca/server.rb 73 def account_path 74 @account_path ||= URI.parse(@servers_url).path 75 end
json_headers()
click to toggle source
# File lib/raca/server.rb 62 def json_headers 63 { 64 'Content-Type' => 'application/json', 65 'Accept' => 'application/json' 66 } 67 end
log(msg)
click to toggle source
# File lib/raca/server.rb 85 def log(msg) 86 if defined?(Rails) 87 Rails.logger.info msg 88 else 89 puts msg 90 end 91 end
server_path()
click to toggle source
# File lib/raca/server.rb 77 def server_path 78 @server_path ||= File.join(account_path, "servers", @server_id.to_s) 79 end
servers_client()
click to toggle source
# File lib/raca/server.rb 81 def servers_client 82 @servers_client ||= @account.http_client(servers_host) 83 end
servers_host()
click to toggle source
# File lib/raca/server.rb 69 def servers_host 70 @servers_host ||= URI.parse(@servers_url).host 71 end