2012-07-30 18:22:16 -04:00
|
|
|
require 'fog/core/collection'
|
|
|
|
require 'fog/rackspace/models/compute_v2/server'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class RackspaceV2
|
2012-11-01 16:24:43 -04:00
|
|
|
|
2012-07-30 18:22:16 -04:00
|
|
|
class Servers < Fog::Collection
|
|
|
|
|
|
|
|
model Fog::Compute::RackspaceV2::Server
|
|
|
|
|
2013-01-30 10:05:10 -05:00
|
|
|
# Returns list of servers
|
2013-03-27 10:50:30 -04:00
|
|
|
# @return [Fog::Compute::RackspaceV2::Servers] Retrieves a list servers.
|
2013-04-15 14:12:14 -04:00
|
|
|
# @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::ServiceError]
|
2013-01-30 10:05:10 -05:00
|
|
|
# @note Fog's current implementation only returns 1000 servers
|
2013-07-23 10:57:57 -04:00
|
|
|
# @note The filter parameter on the method is just to maintain compatability with other providers that support filtering.
|
2013-01-30 10:05:10 -05:00
|
|
|
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Servers-d1e2078.html
|
2013-07-23 10:57:57 -04:00
|
|
|
def all(filters = {})
|
2012-12-22 18:24:03 -05:00
|
|
|
data = service.list_servers.body['servers']
|
2012-07-30 18:22:16 -04:00
|
|
|
load(data)
|
|
|
|
end
|
|
|
|
|
2013-01-30 10:05:10 -05:00
|
|
|
# Creates a new server and populates ssh keys
|
2013-03-27 10:50:30 -04:00
|
|
|
# @return [Fog::Compute::RackspaceV2::Server]
|
2013-04-15 14:12:14 -04:00
|
|
|
# @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::ServiceError]
|
2013-05-21 16:56:29 -04:00
|
|
|
# @note This method is incompatible with Cloud Servers utlizing RackConnect. RackConnect users
|
2013-02-14 09:12:20 -05:00
|
|
|
# should use server personalization to install keys. Please see Server#personality for more information.
|
2013-01-30 10:05:10 -05:00
|
|
|
# @example
|
2013-02-26 17:59:48 -05:00
|
|
|
# service.servers.bootstrap :name => 'bootstrap-server',
|
|
|
|
# :flavor_id => service.flavors.first.id,
|
|
|
|
# :image_id => service.images.find {|img| img.name =~ /Ubuntu/}.id,
|
2013-01-30 10:05:10 -05:00
|
|
|
# :public_key_path => '~/.ssh/fog_rsa.pub',
|
2013-02-26 17:59:48 -05:00
|
|
|
# :private_key_path => '~/.ssh/fog_rsa'
|
2013-03-26 10:14:34 -04:00
|
|
|
#
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::InvalidServerStateException] if server state is an error state
|
2013-02-05 11:29:21 -05:00
|
|
|
def bootstrap(new_attributes = {})
|
2012-11-01 16:24:43 -04:00
|
|
|
server = create(new_attributes)
|
2013-02-05 11:32:40 -05:00
|
|
|
server.wait_for(1500) { ready? && !public_ip_address.empty? }
|
2012-11-01 16:24:43 -04:00
|
|
|
server.setup(:password => server.password)
|
|
|
|
server
|
|
|
|
end
|
|
|
|
|
2013-01-30 10:05:10 -05:00
|
|
|
# Retrieves server
|
|
|
|
# @param [String] server_id for server to be returned
|
|
|
|
# @return [Fog::Compute::RackspaceV2:Server]
|
2013-04-15 14:12:14 -04:00
|
|
|
# @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::ServiceError]
|
2013-01-30 10:05:10 -05:00
|
|
|
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Get_Server_Details-d1e2623.html
|
2012-07-30 18:22:16 -04:00
|
|
|
def get(server_id)
|
2012-12-22 18:24:03 -05:00
|
|
|
data = service.get_server(server_id).body['server']
|
2012-07-30 18:22:16 -04:00
|
|
|
new(data)
|
|
|
|
rescue Fog::Compute::RackspaceV2::NotFound
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|