2014-02-01 21:13:17 -05:00
|
|
|
require 'fog/linode/core'
|
2011-08-31 16:52:53 -04:00
|
|
|
|
2010-12-21 18:11:29 -05:00
|
|
|
module Fog
|
2011-06-15 20:25:01 -04:00
|
|
|
module DNS
|
|
|
|
class Linode < Fog::Service
|
2010-12-21 18:11:29 -05:00
|
|
|
|
|
|
|
requires :linode_api_key
|
|
|
|
recognizes :port, :scheme, :persistent
|
|
|
|
|
2011-08-24 20:50:12 -04:00
|
|
|
model_path 'fog/linode/models/dns'
|
2010-12-23 19:47:47 -05:00
|
|
|
model :record
|
|
|
|
collection :records
|
|
|
|
model :zone
|
|
|
|
collection :zones
|
2010-12-21 18:11:29 -05:00
|
|
|
|
2011-08-24 20:50:12 -04:00
|
|
|
request_path 'fog/linode/requests/dns'
|
2010-12-21 18:11:29 -05:00
|
|
|
request :domain_create
|
|
|
|
request :domain_delete
|
|
|
|
request :domain_list
|
|
|
|
request :domain_update
|
|
|
|
request :domain_resource_create
|
|
|
|
request :domain_resource_delete
|
|
|
|
request :domain_resource_list
|
|
|
|
request :domain_resource_update
|
|
|
|
|
|
|
|
class Mock
|
|
|
|
|
|
|
|
def self.data
|
|
|
|
@data ||= Hash.new do |hash, key|
|
|
|
|
hash[key] = {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-19 10:05:33 -04:00
|
|
|
def self.reset
|
|
|
|
@data = nil
|
|
|
|
end
|
|
|
|
|
2010-12-21 18:11:29 -05:00
|
|
|
def initialize(options={})
|
|
|
|
@linode_api_key = options[:linode_api_key]
|
2011-05-19 18:35:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def 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-12-21 18:11:29 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
|
|
|
|
def initialize(options={})
|
2011-09-12 11:01:48 -04:00
|
|
|
@connection_options = options[:connection_options] || {}
|
|
|
|
@host = options[:host] || "api.linode.com"
|
2010-12-21 18:11:29 -05:00
|
|
|
@linode_api_key = options[:linode_api_key]
|
2011-09-12 11:01:48 -04:00
|
|
|
@persistent = options[:persistent] || false
|
|
|
|
@port = options[:port] || 443
|
|
|
|
@scheme = options[:scheme] || 'https'
|
2014-02-26 04:52:02 -05:00
|
|
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
|
2010-12-21 18:11:29 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
@connection.reset
|
|
|
|
end
|
|
|
|
|
|
|
|
def request(params)
|
|
|
|
params[:query] ||= {}
|
|
|
|
params[:query].merge!(:api_key => @linode_api_key)
|
|
|
|
|
2013-10-16 11:24:41 -04:00
|
|
|
response = @connection.request(params)
|
2010-12-21 18:11:29 -05:00
|
|
|
|
|
|
|
unless response.body.empty?
|
2012-04-25 10:31:28 -04:00
|
|
|
response.body = Fog::JSON.decode(response.body)
|
2010-12-21 18:11:29 -05:00
|
|
|
if data = response.body['ERRORARRAY'].first
|
|
|
|
error = case data['ERRORCODE']
|
|
|
|
when 5
|
2011-06-15 20:25:01 -04:00
|
|
|
Fog::DNS::Linode::NotFound
|
2010-12-21 18:11:29 -05:00
|
|
|
else
|
2011-06-15 20:25:01 -04:00
|
|
|
Fog::DNS::Linode::Error
|
2010-12-21 18:11:29 -05:00
|
|
|
end
|
|
|
|
raise error.new(data['ERRORMESSAGE'])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|