2010-10-04 17:02:08 -04:00
|
|
|
require 'fog/core/parser'
|
2010-09-08 15:58:51 -04:00
|
|
|
|
|
|
|
module Fog
|
|
|
|
module NewServers
|
|
|
|
class Compute < Fog::Service
|
|
|
|
|
2010-12-16 18:31:24 -05:00
|
|
|
requires :new_servers_password, :new_servers_username
|
|
|
|
recognizes :host, :port, :scheme, :persistent
|
2011-01-07 21:14:39 -05:00
|
|
|
recognizes :provider # remove post deprecation
|
2010-09-08 15:58:51 -04:00
|
|
|
|
2011-01-07 19:52:09 -05:00
|
|
|
model_path 'fog/compute/models/new_servers'
|
2010-09-08 15:58:51 -04:00
|
|
|
|
2011-01-07 19:52:09 -05:00
|
|
|
request_path 'fog/compute/requests/new_servers'
|
2010-09-08 15:58:51 -04:00
|
|
|
request :add_server
|
|
|
|
request :cancel_server
|
|
|
|
request :get_server
|
|
|
|
request :list_images
|
|
|
|
request :list_plans
|
|
|
|
request :list_servers
|
|
|
|
request :reboot_server
|
|
|
|
|
|
|
|
class Mock
|
|
|
|
|
|
|
|
def self.data
|
|
|
|
@data ||= Hash.new do |hash, key|
|
|
|
|
hash[key] = {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.reset_data(keys=data.keys)
|
|
|
|
for key in [*keys]
|
|
|
|
data.delete(key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(options={})
|
2011-01-07 21:14:39 -05:00
|
|
|
unless options.delete(:provider)
|
|
|
|
location = caller.first
|
|
|
|
warning = "[yellow][WARN] Fog::NewServers::Compute.new is deprecated, use Fog::Compute.new(:provider => 'NewServers') instead[/]"
|
|
|
|
warning << " [light_black](" << location << ")[/] "
|
|
|
|
Formatador.display_line(warning)
|
|
|
|
end
|
|
|
|
|
2010-09-08 15:58:51 -04:00
|
|
|
@new_server_username = options[:new_servers_username]
|
|
|
|
@data = self.class.data[@new_server_username]
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
|
|
|
|
def initialize(options={})
|
2011-01-07 21:14:39 -05:00
|
|
|
unless options.delete(:provider)
|
|
|
|
location = caller.first
|
|
|
|
warning = "[yellow][WARN] Fog::NewServers::Compute.new is deprecated, use Fog::Compute.new(:provider => 'NewServers') instead[/]"
|
|
|
|
warning << " [light_black](" << location << ")[/] "
|
|
|
|
Formatador.display_line(warning)
|
|
|
|
end
|
|
|
|
|
2010-09-08 15:58:51 -04:00
|
|
|
@new_servers_password = options[:new_servers_password]
|
|
|
|
@new_servers_username = options[:new_servers_username]
|
|
|
|
@host = options[:host] || "noc.newservers.com"
|
|
|
|
@port = options[:port] || 443
|
|
|
|
@scheme = options[:scheme] || 'https'
|
|
|
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
|
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
@connection.reset
|
|
|
|
end
|
|
|
|
|
|
|
|
def request(params)
|
|
|
|
params[:query] ||= {}
|
|
|
|
params[:query].merge!({
|
|
|
|
:password => @new_servers_password,
|
|
|
|
:username => @new_servers_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}))
|
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
|
2010-09-08 17:00:43 -04:00
|
|
|
Fog::NewServers::Compute::NotFound.slurp(error)
|
2010-09-08 15:58:51 -04:00
|
|
|
else
|
|
|
|
error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|