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
|
|
|
|
class Servers < Fog::Collection
|
|
|
|
model Fog::Compute::RackspaceV2::Server
|
|
|
|
|
2014-02-19 07:30:59 -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-12-19 10:26:28 -05:00
|
|
|
# @note This method is compatible with Cloud Servers utlizing RackConnect ***if and only if***
|
2013-12-19 10:40:09 -05:00
|
|
|
# provided the attribute "no_passwd_lock" set to *true*.
|
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)
|
2014-03-12 15:46:57 -04:00
|
|
|
server.wait_for { 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
|