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_path 'fog/linode'
|
||||||
service 'compute'
|
service 'compute'
|
||||||
|
service 'dns'
|
||||||
|
|
||||||
def self.new(attributes = {})
|
def self.new(attributes = {})
|
||||||
location = caller.first
|
location = caller.first
|
||||||
|
|
|
@ -3,8 +3,10 @@ class Linode < Fog::Bin
|
||||||
|
|
||||||
def class_for(key)
|
def class_for(key)
|
||||||
case key
|
case key
|
||||||
when :compute, :linode
|
when :compute
|
||||||
Fog::Linode::Compute
|
Fog::Linode::Compute
|
||||||
|
when :dns
|
||||||
|
Fog::Linode::DNS
|
||||||
else
|
else
|
||||||
raise ArgumentError, "Unsupported #{self} service: #{key}"
|
raise ArgumentError, "Unsupported #{self} service: #{key}"
|
||||||
end
|
end
|
||||||
|
@ -24,7 +26,7 @@ class Linode < Fog::Bin
|
||||||
end
|
end
|
||||||
|
|
||||||
def services
|
def services
|
||||||
[:compute]
|
[:compute, :dns]
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,14 +13,6 @@ module Fog
|
||||||
request :avail_kernels
|
request :avail_kernels
|
||||||
request :avail_linodeplans
|
request :avail_linodeplans
|
||||||
request :avail_stackscripts
|
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_boot
|
||||||
request :linode_create
|
request :linode_create
|
||||||
request :linode_delete
|
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 Fog
|
||||||
module Linode
|
module Linode
|
||||||
class Compute
|
class DNS
|
||||||
class Real
|
class Real
|
||||||
|
|
||||||
# Creates a domain record
|
# Creates a domain record
|
|
@ -1,6 +1,6 @@
|
||||||
module Fog
|
module Fog
|
||||||
module Linode
|
module Linode
|
||||||
class Compute
|
class DNS
|
||||||
class Real
|
class Real
|
||||||
|
|
||||||
# Delete the given domain from the list Linode hosts
|
# Delete the given domain from the list Linode hosts
|
|
@ -1,6 +1,6 @@
|
||||||
module Fog
|
module Fog
|
||||||
module Linode
|
module Linode
|
||||||
class Compute
|
class DNS
|
||||||
class Real
|
class Real
|
||||||
|
|
||||||
# List of domains (you have access to)
|
# List of domains (you have access to)
|
|
@ -1,6 +1,6 @@
|
||||||
module Fog
|
module Fog
|
||||||
module Linode
|
module Linode
|
||||||
class Compute
|
class DNS
|
||||||
class Real
|
class Real
|
||||||
|
|
||||||
# Creates a resource record in a domain
|
# Creates a resource record in a domain
|
|
@ -1,6 +1,6 @@
|
||||||
module Fog
|
module Fog
|
||||||
module Linode
|
module Linode
|
||||||
class Compute
|
class DNS
|
||||||
class Real
|
class Real
|
||||||
|
|
||||||
# Delete the given resource from a domain
|
# Delete the given resource from a domain
|
|
@ -1,6 +1,6 @@
|
||||||
module Fog
|
module Fog
|
||||||
module Linode
|
module Linode
|
||||||
class Compute
|
class DNS
|
||||||
class Real
|
class Real
|
||||||
|
|
||||||
# List of resource records for a domain
|
# List of resource records for a domain
|
|
@ -1,6 +1,6 @@
|
||||||
module Fog
|
module Fog
|
||||||
module Linode
|
module Linode
|
||||||
class Compute
|
class DNS
|
||||||
class Real
|
class Real
|
||||||
|
|
||||||
# Updates a resource record in a domain
|
# Updates a resource record in a domain
|
|
@ -1,6 +1,6 @@
|
||||||
module Fog
|
module Fog
|
||||||
module Linode
|
module Linode
|
||||||
class Compute
|
class DNS
|
||||||
class Real
|
class Real
|
||||||
|
|
||||||
# Update a domain record
|
# 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 = ''
|
@domain = ''
|
||||||
@new_zones = []
|
@new_zones = []
|
||||||
|
@ -22,7 +22,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
||||||
pending if Fog.mocking?
|
pending if Fog.mocking?
|
||||||
|
|
||||||
@org_zone_count= 0
|
@org_zone_count= 0
|
||||||
response = Linode[:compute].domain_list()
|
response = Linode[:dns].domain_list()
|
||||||
if response.status == 200
|
if response.status == 200
|
||||||
zones = response.body['DATA']
|
zones = response.body['DATA']
|
||||||
@org_zone_count = zones.count
|
@org_zone_count = zones.count
|
||||||
|
@ -37,7 +37,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
||||||
type = 'master'
|
type = 'master'
|
||||||
domain= generate_unique_domain
|
domain= generate_unique_domain
|
||||||
options = { :SOA_email => "netops@#{domain}", :description => "Sample-Domain Inc", :status => 0}
|
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
|
if response.status == 200
|
||||||
@master_zone_id = response.body['DATA']['DomainID']
|
@master_zone_id = response.body['DATA']['DomainID']
|
||||||
@new_zones << @master_zone_id
|
@new_zones << @master_zone_id
|
||||||
|
@ -53,7 +53,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
||||||
@domain= generate_unique_domain
|
@domain= generate_unique_domain
|
||||||
options = { :SOA_email => "netops@#{@domain}", :refresh_sec => 14400, :retry_sec => 3600,
|
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' }
|
: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
|
if response.status == 200
|
||||||
@slave_zone_id = response.body['DATA']['DomainID']
|
@slave_zone_id = response.body['DATA']['DomainID']
|
||||||
@new_zones << @slave_zone_id
|
@new_zones << @slave_zone_id
|
||||||
|
@ -67,7 +67,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
||||||
|
|
||||||
result= false
|
result= false
|
||||||
|
|
||||||
response = Linode[:compute].domain_list( @slave_zone_id)
|
response = Linode[:dns].domain_list( @slave_zone_id)
|
||||||
if response.status == 200
|
if response.status == 200
|
||||||
zones = response.body['DATA']
|
zones = response.body['DATA']
|
||||||
num_zones = zones.count
|
num_zones = zones.count
|
||||||
|
@ -91,7 +91,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
||||||
result= false
|
result= false
|
||||||
|
|
||||||
options = { :ttl_sec => 14400 }
|
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
|
if response.status == 200
|
||||||
result= true
|
result= true
|
||||||
end
|
end
|
||||||
|
@ -104,7 +104,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
||||||
|
|
||||||
result= false
|
result= false
|
||||||
|
|
||||||
response = Linode[:compute].domain_list( @slave_zone_id)
|
response = Linode[:dns].domain_list( @slave_zone_id)
|
||||||
if response.status == 200
|
if response.status == 200
|
||||||
zones = response.body['DATA']
|
zones = response.body['DATA']
|
||||||
num_zones = zones.count
|
num_zones = zones.count
|
||||||
|
@ -124,7 +124,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
||||||
|
|
||||||
host= 'www.' + @domain
|
host= 'www.' + @domain
|
||||||
options = { :name => host, :target => '4.5.6.7', :ttl_sec => 3600 }
|
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
|
if response.status == 200
|
||||||
record_id = response.body['DATA']['ResourceID']
|
record_id = response.body['DATA']['ResourceID']
|
||||||
@new_records << record_id
|
@new_records << record_id
|
||||||
|
@ -138,7 +138,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
||||||
|
|
||||||
host= 'mail'
|
host= 'mail'
|
||||||
options = { :name => host, :target => 'www.' + @domain }
|
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
|
if response.status == 200
|
||||||
record_id = response.body['DATA']['ResourceID']
|
record_id = response.body['DATA']['ResourceID']
|
||||||
@new_records << record_id
|
@new_records << record_id
|
||||||
|
@ -151,7 +151,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
||||||
pending if Fog.mocking?
|
pending if Fog.mocking?
|
||||||
|
|
||||||
options = { :name => @domain, :target => 'ns.' + @domain}
|
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
|
if response.status == 200
|
||||||
record_id = response.body['DATA']['ResourceID']
|
record_id = response.body['DATA']['ResourceID']
|
||||||
@new_records << record_id
|
@new_records << record_id
|
||||||
|
@ -164,7 +164,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
||||||
pending if Fog.mocking?
|
pending if Fog.mocking?
|
||||||
|
|
||||||
options = { :target => 'mail.' + @domain, :ttl_sec => 7200, :priority => 5 }
|
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
|
if response.status == 200
|
||||||
@record_id = response.body['DATA']['ResourceID']
|
@record_id = response.body['DATA']['ResourceID']
|
||||||
@new_records << @record_id
|
@new_records << @record_id
|
||||||
|
@ -179,7 +179,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
||||||
result= false
|
result= false
|
||||||
|
|
||||||
domain= 'mail.' + @domain
|
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
|
if response.status == 200
|
||||||
|
|
||||||
records= response.body['DATA']
|
records= response.body['DATA']
|
||||||
|
@ -200,7 +200,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
||||||
pending if Fog.mocking?
|
pending if Fog.mocking?
|
||||||
|
|
||||||
options = { :target => 'mail2.' + @domain }
|
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
|
response.status == 200
|
||||||
end
|
end
|
||||||
|
@ -211,7 +211,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
||||||
result= false
|
result= false
|
||||||
|
|
||||||
domain= 'mail2.' + @domain
|
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
|
if response.status == 200
|
||||||
|
|
||||||
records= response.body['DATA']
|
records= response.body['DATA']
|
||||||
|
@ -233,7 +233,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
||||||
|
|
||||||
result= true
|
result= true
|
||||||
@new_records.each { |record_id|
|
@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
|
if response.status != 200
|
||||||
result= false;
|
result= false;
|
||||||
end
|
end
|
||||||
|
@ -246,7 +246,7 @@ Shindo.tests('Linode::Compute | DNS requests', ['linode', 'dns']) do
|
||||||
|
|
||||||
result= true
|
result= true
|
||||||
@new_zones.each { |zone_id|
|
@new_zones.each { |zone_id|
|
||||||
response = Linode[:compute].domain_delete( zone_id)
|
response = Linode[:dns].domain_delete( zone_id)
|
||||||
if response.status != 200
|
if response.status != 200
|
||||||
result= false;
|
result= false;
|
||||||
end
|
end
|
Loading…
Reference in a new issue