2012-05-15 14:54:20 -04:00
|
|
|
require 'fog/bare_metal_cloud'
|
2011-08-31 16:52:53 -04:00
|
|
|
require 'fog/compute'
|
|
|
|
|
2010-09-08 15:58:51 -04:00
|
|
|
module Fog
|
2011-06-16 19:28:54 -04:00
|
|
|
module Compute
|
2012-03-01 21:54:49 -05:00
|
|
|
class BareMetalCloud < Fog::Service
|
2010-09-08 15:58:51 -04:00
|
|
|
|
2012-03-01 21:54:49 -05:00
|
|
|
requires :bare_metal_cloud_password, :bare_metal_cloud_username
|
2010-12-16 18:31:24 -05:00
|
|
|
recognizes :host, :port, :scheme, :persistent
|
2010-09-08 15:58:51 -04:00
|
|
|
|
2012-03-01 21:54:49 -05:00
|
|
|
model_path 'fog/bare_metal_cloud/models/compute'
|
2010-09-08 15:58:51 -04:00
|
|
|
|
2012-03-01 21:54:49 -05:00
|
|
|
request_path 'fog/bare_metal_cloud/requests/compute'
|
2010-09-08 15:58:51 -04:00
|
|
|
request :add_server
|
2012-08-24 00:17:43 -04:00
|
|
|
request :add_server_by_configuration
|
2010-09-08 15:58:51 -04:00
|
|
|
request :cancel_server
|
|
|
|
request :get_server
|
|
|
|
request :list_images
|
|
|
|
request :list_plans
|
|
|
|
request :list_servers
|
2012-08-24 00:17:43 -04:00
|
|
|
request :list_configurations
|
2010-09-08 15:58:51 -04:00
|
|
|
request :reboot_server
|
|
|
|
|
|
|
|
class Mock
|
|
|
|
|
|
|
|
def self.data
|
|
|
|
@data ||= Hash.new do |hash, key|
|
|
|
|
hash[key] = {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-17 22:40:17 -04:00
|
|
|
def self.reset
|
|
|
|
@data = nil
|
|
|
|
end
|
|
|
|
|
2010-09-08 15:58:51 -04:00
|
|
|
def initialize(options={})
|
2012-03-01 21:54:49 -05:00
|
|
|
@bare_metal_cloud_username = options[:bare_metal_cloud_username]
|
2011-05-19 18:35:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
2012-03-01 21:54:49 -05:00
|
|
|
self.class.data[@bare_metal_cloud_username]
|
2011-03-10 14:16:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def reset_data
|
2012-03-01 21:54:49 -05:00
|
|
|
self.class.data.delete(@bare_metal_cloud_username)
|
2010-09-08 15:58:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
|
|
|
|
def initialize(options={})
|
2011-02-16 20:25:50 -05:00
|
|
|
require 'fog/core/parser'
|
|
|
|
|
2012-03-01 21:54:49 -05:00
|
|
|
@bare_metal_cloud_password = options[:bare_metal_cloud_password]
|
|
|
|
@bare_metal_cloud_username = options[:bare_metal_cloud_username]
|
2011-09-12 11:01:48 -04:00
|
|
|
@connection_options = options[:connection_options] || {}
|
2012-08-24 00:17:43 -04:00
|
|
|
@host = options[:host] || "noc.newservers.com"
|
2011-09-12 11:01:48 -04:00
|
|
|
@persistent = options[:persistent] || false
|
|
|
|
@port = options[:port] || 443
|
|
|
|
@scheme = options[:scheme] || 'https'
|
|
|
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
|
2010-09-08 15:58:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
@connection.reset
|
|
|
|
end
|
|
|
|
|
|
|
|
def request(params)
|
|
|
|
params[:query] ||= {}
|
|
|
|
params[:query].merge!({
|
2012-03-01 21:54:49 -05:00
|
|
|
:password => @bare_metal_cloud_password,
|
|
|
|
:username => @bare_metal_cloud_username
|
2010-09-08 15:58:51 -04:00
|
|
|
})
|
|
|
|
params[:headers] ||= {}
|
|
|
|
case params[:method]
|
|
|
|
when 'DELETE', 'GET', 'HEAD'
|
|
|
|
params[:headers]['Accept'] = 'application/xml'
|
|
|
|
when 'POST', 'PUT'
|
|
|
|
params[:headers]['Content-Type'] = 'application/xml'
|
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
|
|
|
response = @connection.request(params.merge!({:host => @host}))
|
2010-11-29 23:07:47 -05:00
|
|
|
rescue Excon::Errors::HTTPStatusError => error
|
2010-09-08 15:58:51 -04:00
|
|
|
raise case error
|
|
|
|
when Excon::Errors::NotFound
|
2012-03-01 21:54:49 -05:00
|
|
|
Fog::Compute::BareMetalCloud::NotFound.slurp(error)
|
2010-09-08 15:58:51 -04:00
|
|
|
else
|
|
|
|
error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|