2010-09-08 13:56:38 -04:00
|
|
|
module Fog
|
|
|
|
module Linode
|
|
|
|
class Compute < Fog::Service
|
|
|
|
|
2010-12-16 18:31:24 -05:00
|
|
|
requires :linode_api_key
|
|
|
|
recognizes :port, :scheme, :persistent
|
2011-01-07 21:14:39 -05:00
|
|
|
recognizes :provider # remove post deprecation
|
2010-09-08 13:56:38 -04:00
|
|
|
|
2011-01-07 19:52:09 -05:00
|
|
|
model_path 'fog/compute/models/linode'
|
2010-09-08 13:56:38 -04:00
|
|
|
|
2011-01-07 19:52:09 -05:00
|
|
|
request_path 'fog/compute/requests/linode'
|
2010-09-08 13:56:38 -04:00
|
|
|
request :avail_datacenters
|
|
|
|
request :avail_distributions
|
|
|
|
request :avail_kernels
|
|
|
|
request :avail_linodeplans
|
|
|
|
request :avail_stackscripts
|
2010-12-10 14:07:00 -05:00
|
|
|
# request :linode_boot
|
2010-09-08 13:56:38 -04:00
|
|
|
request :linode_create
|
|
|
|
request :linode_delete
|
|
|
|
request :linode_list
|
|
|
|
request :linode_reboot
|
2010-12-10 14:07:00 -05:00
|
|
|
# request :linode_resize
|
|
|
|
# request :linode_shutdown
|
|
|
|
# request :linode_update
|
2010-09-08 13:56:38 -04:00
|
|
|
|
|
|
|
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 13:56:38 -04:00
|
|
|
def initialize(options={})
|
2011-01-07 21:14:39 -05:00
|
|
|
unless options.delete(:provider)
|
|
|
|
location = caller.first
|
|
|
|
warning = "[yellow][WARN] Fog::Linode::Compute.new is deprecated, use Fog::Compute.new(:provider => 'Linode') instead[/]"
|
|
|
|
warning << " [light_black](" << location << ")[/] "
|
|
|
|
Formatador.display_line(warning)
|
|
|
|
end
|
|
|
|
|
2010-09-08 13:56:38 -04:00
|
|
|
@linode_api_key = options[:linode_api_key]
|
2011-03-21 13:54:07 -04:00
|
|
|
@data = self.class.data[@linode_api_key]
|
2011-03-10 14:16:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def reset_data
|
|
|
|
self.class.data.delete(@linode_api_key)
|
2010-09-08 13:56:38 -04:00
|
|
|
@data = self.class.data[@linode_api_key]
|
|
|
|
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::Linode::Compute.new is deprecated, use Fog::Compute.new(:provider => 'Linode') instead[/]"
|
|
|
|
warning << " [light_black](" << location << ")[/] "
|
|
|
|
Formatador.display_line(warning)
|
|
|
|
end
|
|
|
|
|
2010-10-29 17:58:28 -04:00
|
|
|
require 'json'
|
2010-09-08 13:56:38 -04:00
|
|
|
@linode_api_key = options[:linode_api_key]
|
|
|
|
@host = options[:host] || "api.linode.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!(:api_key => @linode_api_key)
|
|
|
|
|
|
|
|
response = @connection.request(params.merge!({:host => @host}))
|
|
|
|
|
|
|
|
unless response.body.empty?
|
|
|
|
response.body = JSON.parse(response.body)
|
|
|
|
if data = response.body['ERRORARRAY'].first
|
|
|
|
error = case data['ERRORCODE']
|
|
|
|
when 5
|
2010-09-08 17:00:43 -04:00
|
|
|
Fog::Linode::Compute::NotFound
|
2010-09-08 13:56:38 -04:00
|
|
|
else
|
2010-09-08 17:00:43 -04:00
|
|
|
Fog::Linode::Compute::Error
|
2010-09-08 13:56:38 -04:00
|
|
|
end
|
|
|
|
raise error.new(data['ERRORMESSAGE'])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|