1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/bare_metal_cloud/compute.rb
Paul Thornthwaite a72433d2f8 Remove duplicate requires from services
Following work on reorganising the requires, there was an inconsistent
approach to where service wrappers are required. (Fog::Compute...)

Since they should be standardised and shared across providers (although
they really aren't yet) they have been moved to `fog-core` gem.

Each provider has their own `lib/fog/{provider}/core` files that is
required by each of their services. These files should all require
`fog/core` which already required most or these.

So this removes the extra cases to concentrate them in core.
2014-02-13 17:44:48 +00:00

99 lines
2.7 KiB
Ruby

require 'fog/bare_metal_cloud/core'
module Fog
module Compute
class BareMetalCloud < Fog::Service
requires :bare_metal_cloud_password, :bare_metal_cloud_username
recognizes :host, :port, :scheme, :persistent
model_path 'fog/bare_metal_cloud/models/compute'
request_path 'fog/bare_metal_cloud/requests/compute'
request :add_server
request :add_server_by_configuration
request :cancel_server
request :get_server
request :list_images
request :list_plans
request :list_servers
request :list_configurations
request :reboot_server
class Mock
def self.data
@data ||= Hash.new do |hash, key|
hash[key] = {}
end
end
def self.reset
@data = nil
end
def initialize(options={})
@bare_metal_cloud_username = options[:bare_metal_cloud_username]
end
def data
self.class.data[@bare_metal_cloud_username]
end
def reset_data
self.class.data.delete(@bare_metal_cloud_username)
end
end
class Real
def initialize(options={})
require 'fog/core/parser'
@bare_metal_cloud_password = options[:bare_metal_cloud_password]
@bare_metal_cloud_username = options[:bare_metal_cloud_username]
@connection_options = options[:connection_options] || {}
@host = options[:host] || "noc.newservers.com"
@persistent = options[:persistent] || false
@port = options[:port] || 443
@scheme = options[:scheme] || 'https'
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end
def reload
@connection.reset
end
def request(params)
params[:query] ||= {}
params[:query].merge!({
:password => @bare_metal_cloud_password,
:username => @bare_metal_cloud_username
})
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}))
rescue Excon::Errors::HTTPStatusError => error
raise case error
when Excon::Errors::NotFound
Fog::Compute::BareMetalCloud::NotFound.slurp(error)
else
error
end
end
response
end
end
end
end
end