mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
dynect: add a bunch of stuff: node_list, list_any_records, handle 307 job
redirect,
This commit is contained in:
parent
6c6f2108a2
commit
f47e4c8af0
11 changed files with 238 additions and 26 deletions
|
@ -16,6 +16,8 @@ module Fog
|
|||
request :session
|
||||
request :list_zones
|
||||
request :get_zone
|
||||
request :list_any_records
|
||||
request :node_list
|
||||
|
||||
class Real
|
||||
def initialize(options={})
|
||||
|
@ -45,6 +47,7 @@ module Fog
|
|||
params[:headers]['Auth-Token'] = auth_token unless params[:path] == "Session"
|
||||
params[:path] = "#{@path}/#{params[:path]}"
|
||||
response = @connection.request(params.merge!({:host => @host}))
|
||||
response = handle_redirect(response) if response.status == 307
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
raise error
|
||||
end
|
||||
|
@ -53,9 +56,19 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def handle_redirect(response)
|
||||
raise request({
|
||||
:expects => 200,
|
||||
:method => "GET",
|
||||
:path => response.body
|
||||
})
|
||||
|
||||
|
||||
end
|
||||
|
||||
# class Mock
|
||||
# end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,28 +9,20 @@ module Fog
|
|||
deprecate :ip, :value
|
||||
deprecate :ip=, :value=
|
||||
|
||||
identity :id
|
||||
attribute :name
|
||||
attribute :value, :aliases => "content"
|
||||
identity :id, :aliases => "record_id"
|
||||
attribute :name, :aliases => "fqdn"
|
||||
attribute :value, :aliases => "rdata"
|
||||
attribute :ttl
|
||||
attribute :created_at
|
||||
attribute :updated_at
|
||||
attribute :zone_id, :aliases => "domain_id"
|
||||
attribute :zone_id, :aliases => "zone"
|
||||
attribute :type, :aliases => "record_type"
|
||||
attribute :priority, :aliases => "prio"
|
||||
|
||||
def initialize(attributes={})
|
||||
end
|
||||
|
||||
def destroy
|
||||
end
|
||||
|
||||
def zone
|
||||
raise 'destroy not implemented'
|
||||
end
|
||||
|
||||
def save
|
||||
raise 'save not implemented'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -11,7 +11,18 @@ module Fog
|
|||
|
||||
model Fog::Dynect::DNS::Record
|
||||
|
||||
def all
|
||||
def all(attributes={})
|
||||
selected_nodes = nodes
|
||||
selected_nodes = nodes.select do |node|
|
||||
Array(attributes[:nodes]).include?(node)
|
||||
end if attributes[:nodes]
|
||||
|
||||
data = selected_nodes.inject([]) do |m, node|
|
||||
m += connection.list_any_records(zone.id, node).map(&:body)
|
||||
m
|
||||
end
|
||||
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(record_id)
|
||||
|
@ -22,6 +33,13 @@ module Fog
|
|||
super({ :zone => zone }.merge!(attributes))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def nodes
|
||||
requires :zone
|
||||
Array(connection.node_list(zone.id).body)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -7,25 +7,26 @@ module Fog
|
|||
|
||||
class Zone < Fog::Model
|
||||
|
||||
identity :zone
|
||||
identity :id, :aliases => "zone"
|
||||
attribute :serial
|
||||
attribute :zone_type
|
||||
attribute :serial_style
|
||||
|
||||
def destroy
|
||||
raise 'Not Implemented'
|
||||
raise 'destroy Not Implemented'
|
||||
end
|
||||
|
||||
def records
|
||||
raise 'Not Implemented'
|
||||
@records ||= Fog::Dynect::DNS::Records.new(:zone => self, :connection => connection)
|
||||
end
|
||||
|
||||
def nameservers
|
||||
raise 'Not Implemented'
|
||||
raise 'nameservers Not Implemented'
|
||||
end
|
||||
|
||||
def save
|
||||
raise 'Not Implemented'
|
||||
#raise 'Not Implemented'
|
||||
'dynect save'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ module Fog
|
|||
zone_names = connection.list_zones.body["zones"]
|
||||
load(zone_names.map {|name|
|
||||
{
|
||||
"zone" => name
|
||||
"id" => name
|
||||
}
|
||||
})
|
||||
end
|
||||
|
|
25
lib/fog/dns/parsers/dynect/anyrecord.rb
Normal file
25
lib/fog/dns/parsers/dynect/anyrecord.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module Dynect
|
||||
module DNS
|
||||
|
||||
class AnyRecord < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = {}
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'zone', 'fqdn', 'record_type', 'record_id', 'rdata', 'address', 'txtdata'
|
||||
@response[name] = @value
|
||||
when 'ttl'
|
||||
@response[name] = @value.to_i
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
29
lib/fog/dns/parsers/dynect/anyrecords.rb
Normal file
29
lib/fog/dns/parsers/dynect/anyrecords.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module Dynect
|
||||
module DNS
|
||||
|
||||
class AnyRecords < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = []
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when /.+RecordURI$/
|
||||
matches = @value.match(/\/REST\/(.+)Record\/(.+)\/(.+)\/(.+)/).to_a
|
||||
_, record_type, zone, fqdn, recordid = matches
|
||||
|
||||
@response << ({"zone" => zone,
|
||||
"fqdn" => fqdn,
|
||||
"recordid" => recordid,
|
||||
"record_type" => record_type})
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/dns/parsers/dynect/node_list.rb
Normal file
23
lib/fog/dns/parsers/dynect/node_list.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module Dynect
|
||||
module DNS
|
||||
|
||||
class NodeList < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = []
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'item'
|
||||
@response << @value unless @value == "INFO"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
59
lib/fog/dns/requests/dynect/list_any_records.rb
Normal file
59
lib/fog/dns/requests/dynect/list_any_records.rb
Normal file
|
@ -0,0 +1,59 @@
|
|||
module Fog
|
||||
module Dynect
|
||||
class DNS
|
||||
class Real
|
||||
|
||||
require 'fog/dns/parsers/dynect/anyrecords'
|
||||
require 'fog/dns/parsers/dynect/anyrecord'
|
||||
|
||||
# Get the list of records for the specific domain.
|
||||
#
|
||||
# ==== Parameters
|
||||
# * domain<~String>
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * records<Array~>
|
||||
# * fqdn<~String>
|
||||
# * address<~String>
|
||||
# * record_type<~String>
|
||||
# * ttl<~Integer>
|
||||
# * zone<~String>
|
||||
def list_any_records(zone, fqdn)
|
||||
all_records = request(
|
||||
:parser => Fog::Parsers::Dynect::DNS::AnyRecords.new,
|
||||
:expects => [200, 307],
|
||||
:method => "GET",
|
||||
:path => "ANYRecord/#{zone}/#{fqdn}",
|
||||
)
|
||||
|
||||
all_records.body.inject([]) do |results, record|
|
||||
results << request(
|
||||
:parser => Fog::Parsers::Dynect::DNS::AnyRecord.new,
|
||||
:expects => [200, 307],
|
||||
:method => "GET",
|
||||
:path => "#{record['record_type']}Record/#{record['zone']}/#{record['fqdn']}/#{record['recordid']}",
|
||||
)
|
||||
results
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def list_any_records
|
||||
response = Excon::Response.new
|
||||
response.body = [{
|
||||
"fqdn" => "example.com",
|
||||
"address" => "127.0.0.1",
|
||||
"zone" => "example.com",
|
||||
"record_type" => "A",
|
||||
"ttl" => 30
|
||||
}]
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
31
lib/fog/dns/requests/dynect/node_list.rb
Normal file
31
lib/fog/dns/requests/dynect/node_list.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
module Fog
|
||||
module Dynect
|
||||
class DNS
|
||||
class Real
|
||||
|
||||
require 'fog/dns/parsers/dynect/node_list'
|
||||
|
||||
def node_list(zone)
|
||||
request(
|
||||
:parser => Fog::Parsers::Dynect::DNS::NodeList.new,
|
||||
:expects => 200,
|
||||
:method => "GET",
|
||||
:path => "NodeList/#{zone}",
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def node_list(zone)
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = [zone]
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,13 @@
|
|||
Shindo.tests('Dynect::dns | DNS requests', ['dynect', 'dns']) do
|
||||
tests "success" do
|
||||
def zone
|
||||
ENV['DYNECT_ZONE']
|
||||
end
|
||||
|
||||
def fqdn
|
||||
ENV['DYNECT_FQDN']
|
||||
end
|
||||
|
||||
tests "start api session" do
|
||||
response = Dynect[:dns].session
|
||||
returns(true) { response.body['Auth-Token'] =~ /.+=$/ && true }
|
||||
|
@ -14,15 +22,28 @@ Shindo.tests('Dynect::dns | DNS requests', ['dynect', 'dns']) do
|
|||
end
|
||||
|
||||
tests "get zone" do
|
||||
first_zone_name = Dynect[:dns].list_zones.body['zones'].first
|
||||
response = Dynect[:dns].get_zone(first_zone_name)
|
||||
returns(true) { response.body['zone'] == first_zone_name }
|
||||
response = Dynect[:dns].get_zone(zone)
|
||||
returns(true) { response.body['zone'] == zone }
|
||||
returns(true) { response.body['serial'] > 0 }
|
||||
returns(true) { response.body['zone_type'] == "Primary" }
|
||||
returns(true) { response.body['serial_style'] == "increment" }
|
||||
end
|
||||
|
||||
tests "list records"
|
||||
tests "list records" do
|
||||
responses = Dynect[:dns].list_any_records(zone, fqdn)
|
||||
returns(3) { responses.size }
|
||||
returns(30) { responses.map(&:body).first['ttl'] }
|
||||
end
|
||||
|
||||
tests "list zone nodes" do
|
||||
response = Dynect[:dns].node_list(zone)
|
||||
returns(zone) { response.body.first }
|
||||
end
|
||||
|
||||
tests "model" do
|
||||
records = Fog::DNS.new(:provider => "Dynect").zones.get(zone).records.all(:nodes => fqdn)
|
||||
returns("127.0.0.2") { records.last.value }
|
||||
end
|
||||
|
||||
tests "create record"
|
||||
tests "delete record"
|
||||
|
|
Loading…
Reference in a new issue