mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[linode|dns] give dns its own namespace/service
This commit is contained in:
parent
8c5b57cf0e
commit
8d7733c239
13 changed files with 110 additions and 35 deletions
|
@ -7,6 +7,7 @@ module Fog
|
|||
|
||||
service_path 'fog/linode'
|
||||
service 'compute'
|
||||
service 'dns'
|
||||
|
||||
def self.new(attributes = {})
|
||||
location = caller.first
|
||||
|
|
|
@ -3,9 +3,11 @@ class Linode < Fog::Bin
|
|||
|
||||
def class_for(key)
|
||||
case key
|
||||
when :compute, :linode
|
||||
when :compute
|
||||
Fog::Linode::Compute
|
||||
else
|
||||
when :dns
|
||||
Fog::Linode::DNS
|
||||
else
|
||||
raise ArgumentError, "Unsupported #{self} service: #{key}"
|
||||
end
|
||||
end
|
||||
|
@ -24,7 +26,7 @@ class Linode < Fog::Bin
|
|||
end
|
||||
|
||||
def services
|
||||
[:compute]
|
||||
[:compute, :dns]
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -13,14 +13,6 @@ module Fog
|
|||
request :avail_kernels
|
||||
request :avail_linodeplans
|
||||
request :avail_stackscripts
|
||||
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
|
||||
# request :linode_boot
|
||||
request :linode_create
|
||||
request :linode_delete
|
||||
|
|
80
lib/fog/linode/dns.rb
Normal file
80
lib/fog/linode/dns.rb
Normal file
|
@ -0,0 +1,80 @@
|
|||
module Fog
|
||||
module Linode
|
||||
class DNS < Fog::Service
|
||||
|
||||
requires :linode_api_key
|
||||
recognizes :port, :scheme, :persistent
|
||||
|
||||
model_path 'fog/linode/models/dns'
|
||||
|
||||
request_path 'fog/linode/requests/dns'
|
||||
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
|
||||
|
||||
def self.reset_data(keys=data.keys)
|
||||
for key in [*keys]
|
||||
data.delete(key)
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(options={})
|
||||
@linode_api_key = options[:linode_api_key]
|
||||
@data = self.class.data[@linode_api_key]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Real
|
||||
|
||||
def initialize(options={})
|
||||
require 'json'
|
||||
@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
|
||||
Fog::Linode::DNS::NotFound
|
||||
else
|
||||
Fog::Linode::DNS::Error
|
||||
end
|
||||
raise error.new(data['ERRORMESSAGE'])
|
||||
end
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
module Fog
|
||||
module Linode
|
||||
class Compute
|
||||
class DNS
|
||||
class Real
|
||||
|
||||
# Creates a domain record
|
|
@ -1,6 +1,6 @@
|
|||
module Fog
|
||||
module Linode
|
||||
class Compute
|
||||
class DNS
|
||||
class Real
|
||||
|
||||
# Delete the given domain from the list Linode hosts
|
|
@ -1,6 +1,6 @@
|
|||
module Fog
|
||||
module Linode
|
||||
class Compute
|
||||
class DNS
|
||||
class Real
|
||||
|
||||
# List of domains (you have access to)
|
|
@ -1,6 +1,6 @@
|
|||
module Fog
|
||||
module Linode
|
||||
class Compute
|
||||
class DNS
|
||||
class Real
|
||||
|
||||
# Creates a resource record in a domain
|
|
@ -1,6 +1,6 @@
|
|||
module Fog
|
||||
module Linode
|
||||
class Compute
|
||||
class DNS
|
||||
class Real
|
||||
|
||||
# Delete the given resource from a domain
|
|
@ -1,6 +1,6 @@
|
|||
module Fog
|
||||
module Linode
|
||||
class Compute
|
||||
class DNS
|
||||
class Real
|
||||
|
||||
# List of resource records for a domain
|
|
@ -1,6 +1,6 @@
|
|||
module Fog
|
||||
module Linode
|
||||
class Compute
|
||||
class DNS
|
||||
class Real
|
||||
|
||||
# Updates a resource record in a domain
|
|
@ -1,6 +1,6 @@
|
|||
module Fog
|
||||
module Linode
|
||||
class Compute
|
||||
class DNS
|
||||
class Real
|
||||
|
||||
# Update a domain record
|
|
@ -1,4 +1,4 @@
|
|||
Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
||||
Shindo.tests('Linode::dns | DNS requests', ['linode', 'dns']) do
|
||||
|
||||
@domain = ''
|
||||
@new_zones = []
|
||||
|
@ -22,7 +22,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
|||
pending if Fog.mocking?
|
||||
|
||||
@org_zone_count= 0
|
||||
response = Linode[:compute].domain_list()
|
||||
response = Linode[:dns].domain_list()
|
||||
if response.status == 200
|
||||
zones = response.body['DATA']
|
||||
@org_zone_count = zones.count
|
||||
|
@ -37,7 +37,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
|||
type = 'master'
|
||||
domain= generate_unique_domain
|
||||
options = { :SOA_email => "netops@#{domain}", :description => "Sample-Domain Inc", :status => 0}
|
||||
response = Linode[:compute].domain_create( domain, type, options)
|
||||
response = Linode[:dns].domain_create( domain, type, options)
|
||||
if response.status == 200
|
||||
@master_zone_id = response.body['DATA']['DomainID']
|
||||
@new_zones << @master_zone_id
|
||||
|
@ -53,7 +53,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
|||
@domain= generate_unique_domain
|
||||
options = { :SOA_email => "netops@#{@domain}", :refresh_sec => 14400, :retry_sec => 3600,
|
||||
:expire_sec => 604800, :ttl_sec => 28800, :status => 0, :master_ips => '1.2.3.4;2.3.4.5' }
|
||||
response = Linode[:compute].domain_create( @domain, type, options)
|
||||
response = Linode[:dns].domain_create( @domain, type, options)
|
||||
if response.status == 200
|
||||
@slave_zone_id = response.body['DATA']['DomainID']
|
||||
@new_zones << @slave_zone_id
|
||||
|
@ -67,7 +67,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
|||
|
||||
result= false
|
||||
|
||||
response = Linode[:compute].domain_list( @slave_zone_id)
|
||||
response = Linode[:dns].domain_list( @slave_zone_id)
|
||||
if response.status == 200
|
||||
zones = response.body['DATA']
|
||||
num_zones = zones.count
|
||||
|
@ -91,7 +91,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
|||
result= false
|
||||
|
||||
options = { :ttl_sec => 14400 }
|
||||
response = Linode[:compute].domain_update( @slave_zone_id, options)
|
||||
response = Linode[:dns].domain_update( @slave_zone_id, options)
|
||||
if response.status == 200
|
||||
result= true
|
||||
end
|
||||
|
@ -104,7 +104,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
|||
|
||||
result= false
|
||||
|
||||
response = Linode[:compute].domain_list( @slave_zone_id)
|
||||
response = Linode[:dns].domain_list( @slave_zone_id)
|
||||
if response.status == 200
|
||||
zones = response.body['DATA']
|
||||
num_zones = zones.count
|
||||
|
@ -124,7 +124,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
|||
|
||||
host= 'www.' + @domain
|
||||
options = { :name => host, :target => '4.5.6.7', :ttl_sec => 3600 }
|
||||
response = Linode[:compute].domain_resource_create( @master_zone_id, 'A', options)
|
||||
response = Linode[:dns].domain_resource_create( @master_zone_id, 'A', options)
|
||||
if response.status == 200
|
||||
record_id = response.body['DATA']['ResourceID']
|
||||
@new_records << record_id
|
||||
|
@ -138,7 +138,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
|||
|
||||
host= 'mail'
|
||||
options = { :name => host, :target => 'www.' + @domain }
|
||||
response = Linode[:compute].domain_resource_create( @master_zone_id, 'CNAME', options)
|
||||
response = Linode[:dns].domain_resource_create( @master_zone_id, 'CNAME', options)
|
||||
if response.status == 200
|
||||
record_id = response.body['DATA']['ResourceID']
|
||||
@new_records << record_id
|
||||
|
@ -151,7 +151,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
|||
pending if Fog.mocking?
|
||||
|
||||
options = { :name => @domain, :target => 'ns.' + @domain}
|
||||
response = Linode[:compute].domain_resource_create( @master_zone_id, 'NS', options)
|
||||
response = Linode[:dns].domain_resource_create( @master_zone_id, 'NS', options)
|
||||
if response.status == 200
|
||||
record_id = response.body['DATA']['ResourceID']
|
||||
@new_records << record_id
|
||||
|
@ -164,7 +164,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
|||
pending if Fog.mocking?
|
||||
|
||||
options = { :target => 'mail.' + @domain, :ttl_sec => 7200, :priority => 5 }
|
||||
response = Linode[:compute].domain_resource_create( @master_zone_id, 'MX', options)
|
||||
response = Linode[:dns].domain_resource_create( @master_zone_id, 'MX', options)
|
||||
if response.status == 200
|
||||
@record_id = response.body['DATA']['ResourceID']
|
||||
@new_records << @record_id
|
||||
|
@ -179,7 +179,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
|||
result= false
|
||||
|
||||
domain= 'mail.' + @domain
|
||||
response = Linode[:compute].domain_resource_list(@master_zone_id, @record_id)
|
||||
response = Linode[:dns].domain_resource_list(@master_zone_id, @record_id)
|
||||
if response.status == 200
|
||||
|
||||
records= response.body['DATA']
|
||||
|
@ -200,7 +200,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
|||
pending if Fog.mocking?
|
||||
|
||||
options = { :target => 'mail2.' + @domain }
|
||||
response = Linode[:compute].domain_resource_update( @master_zone_id, @record_id, options)
|
||||
response = Linode[:dns].domain_resource_update( @master_zone_id, @record_id, options)
|
||||
|
||||
response.status == 200
|
||||
end
|
||||
|
@ -211,7 +211,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
|||
result= false
|
||||
|
||||
domain= 'mail2.' + @domain
|
||||
response = Linode[:compute].domain_resource_list(@master_zone_id, @record_id)
|
||||
response = Linode[:dns].domain_resource_list(@master_zone_id, @record_id)
|
||||
if response.status == 200
|
||||
|
||||
records= response.body['DATA']
|
||||
|
@ -233,7 +233,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
|||
|
||||
result= true
|
||||
@new_records.each { |record_id|
|
||||
response = Linode[:compute].domain_resource_delete( @master_zone_id, record_id)
|
||||
response = Linode[:dns].domain_resource_delete( @master_zone_id, record_id)
|
||||
if response.status != 200
|
||||
result= false;
|
||||
end
|
||||
|
@ -246,7 +246,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
|||
|
||||
result= true
|
||||
@new_zones.each { |zone_id|
|
||||
response = Linode[:compute].domain_delete( zone_id)
|
||||
response = Linode[:dns].domain_delete( zone_id)
|
||||
if response.status != 200
|
||||
result= false;
|
||||
end
|
Loading…
Reference in a new issue