mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[dns|rackspace] initial commit
This commit is contained in:
parent
01544701aa
commit
cc40adc46b
4 changed files with 73 additions and 1 deletions
|
@ -11,7 +11,9 @@ class Rackspace < Fog::Bin
|
|||
Fog::Storage::Rackspace
|
||||
when :load_balancers
|
||||
Fog::Rackspace::LoadBalancers
|
||||
else
|
||||
when :dns
|
||||
Fog::DNS::Rackspace
|
||||
else
|
||||
raise ArgumentError, "Unrecognized service: #{key}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,6 +32,9 @@ module Fog
|
|||
when :zerigo
|
||||
require 'fog/dns/zerigo'
|
||||
Fog::DNS::Zerigo.new(attributes)
|
||||
when :rackspace
|
||||
require 'fog/dns/rackspace'
|
||||
Fog::DNS::Rackspace.new(attributes)
|
||||
else
|
||||
raise ArgumentError.new("#{provider} is not a recognized dns provider")
|
||||
end
|
||||
|
|
66
lib/fog/dns/rackspace.rb
Normal file
66
lib/fog/dns/rackspace.rb
Normal file
|
@ -0,0 +1,66 @@
|
|||
module Fog
|
||||
module DNS
|
||||
class Rackspace < Fog::Service
|
||||
|
||||
US_ENDPOINT = 'https://dns.api.rackspacecloud.com/v1.0'
|
||||
UK_ENDPOINT = 'https://lon.dns.api.rackspacecloud.com/v1.0'
|
||||
|
||||
requires :rackspace_api_key, :rackspace_username
|
||||
recognizes :rackspace_auth_url
|
||||
recognizes :rackspace_auth_token
|
||||
|
||||
model_path 'fog/dns/models/rackspace'
|
||||
#TODO - Need to add
|
||||
#model :record
|
||||
#collection :records
|
||||
#model :zone
|
||||
#collection :zones
|
||||
|
||||
request_path 'fog/dns/requests/rackspace'
|
||||
|
||||
class Real
|
||||
def initialize(options={})
|
||||
require 'multi_json'
|
||||
@rackspace_api_key = options[:rackspace_api_key]
|
||||
@rackspace_username = options[:rackspace_username]
|
||||
@rackspace_auth_url = options[:rackspace_auth_url]
|
||||
uri = URI.parse(options[:rackspace_dns_endpoint] || US_ENDPOINT)
|
||||
|
||||
@auth_token, @account_id = *authenticate
|
||||
@path = "#{uri.path}/#{@account_id}"
|
||||
headers = { 'Content-Type' => 'application/json', 'X-Auth-Token' => @auth_token }
|
||||
|
||||
@connection = Fog::Connection.new(uri.to_s, options[:persistent], { :headers => headers})
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def request(params)
|
||||
#TODO - Unify code with other rackspace services
|
||||
begin
|
||||
response = @connection.request(params.merge!({
|
||||
:path => "#{@path}/#{params[:path]}"
|
||||
}))
|
||||
#TODO - Going to add rescues for the different expected errors
|
||||
end
|
||||
unless response.body.empty?
|
||||
response.body = MultiJson.decode(response.body)
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
def authenticate
|
||||
options = {
|
||||
:rackspace_api_key => @rackspace_api_key,
|
||||
:rackspace_username => @rackspace_username,
|
||||
:rackspace_auth_url => @rackspace_auth_url
|
||||
}
|
||||
credentials = Fog::Rackspace.authenticate(options)
|
||||
auth_token = credentials['X-Auth-Token']
|
||||
account_id = credentials['X-Server-Management-Url'].match(/.*\/([\d]+)$/)[1]
|
||||
[auth_token, account_id]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,6 +9,7 @@ module Fog
|
|||
service(:compute, 'compute/rackspace')
|
||||
service(:storage, 'storage/rackspace')
|
||||
service(:load_balancers, 'rackspace/load_balancers')
|
||||
service(:dns, 'dns/rackspace')
|
||||
|
||||
def self.authenticate(options)
|
||||
rackspace_auth_url = options[:rackspace_auth_url] || "auth.api.rackspacecloud.com"
|
||||
|
|
Loading…
Add table
Reference in a new issue