1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Merge pull request #595 from patio11/slicehost_dns_fixes

Slicehost dns fixes
This commit is contained in:
Wesley Beary 2011-11-08 07:26:12 -08:00
commit dd2ba7904d
10 changed files with 153 additions and 33 deletions

View file

@ -23,6 +23,7 @@ module Fog
request :get_records
request :get_zone
request :get_zones
request :update_record
class Mock

View file

@ -12,7 +12,7 @@ module Fog
identity :id
attribute :active
attribute :value, :aliases => 'ip'
attribute :value, :aliases => ['ip', 'data']
attribute :name
attribute :description, :aliases => 'aux'
attribute :ttl
@ -45,13 +45,17 @@ module Fog
end
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :name, :type, :value, :zone
options = {}
options[:active] = active ? 'Y' : 'N'
options[:aux] = description if description
options[:ttl] = ttl if ttl
data = connection.create_record(type, zone.id, name, value, options)
if identity
data = connection.update_record(identity, type, zone.id, name, value, options)
else
data = connection.create_record(type, zone.id, name, value, options)
end
merge_attributes(data.body)
true
end

View file

@ -39,7 +39,7 @@ module Fog
Fog::DNS::Slicehost::Records.new(
:zone => self,
:connection => connection
)
).all
end
end

View file

@ -11,9 +11,15 @@ module Fog
def end_element(name)
case name
when 'zone-id', 'ttl', 'id'
when 'zone_id'
@response["zone-id"] = value.to_i
when 'record_type'
@response["record-type"] = value
when 'ttl', 'id'
@response[name] = value.to_i
when 'record-type', 'name', 'data', 'active', 'aux'
when 'value'
@response["data"] = value
when 'name', 'data', 'active', 'aux'
@response[name] = value
end
end

View file

@ -6,15 +6,27 @@ module Fog
class GetRecord < Fog::Parsers::Base
def reset
@record = {}
@response = { }
end
def end_element(name)
case name
when 'zone-id', 'ttl'
@response[name] = value.to_i
when 'record-type', 'name', 'data', 'active', 'aux'
@response[name] = value
when 'id'
@record["id"] = value.to_i
when 'zone-id'
@record["zone_id"] = value.to_i
when 'record-type'
@record["record_type"] = value
when 'ttl'
@record[name] = value.to_i
when 'data'
@record["value"] = value
when 'name', 'active', 'aux'
@record[name] = value
when 'record'
@response = @record
@record = {}
end
end
@ -23,4 +35,4 @@ module Fog
end
end
end
end
end

View file

@ -12,9 +12,17 @@ module Fog
def end_element(name)
case name
when 'zone-id', 'ttl'
when 'id'
@record["id"] = value.to_i
when 'zone-id'
@record["zone_id"] = value.to_i
when 'record-type'
@record["record_type"] = value
when 'ttl'
@record[name] = value.to_i
when 'record-type', 'name', 'data', 'active', 'aux'
when 'data'
@record["value"] = value
when 'name', 'active', 'aux'
@record[name] = value
when 'record'
@response['records'] << @record

View file

@ -21,7 +21,7 @@ module Fog
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::DNS::Slicehost::GetRecords.new,
:parser => Fog::Parsers::DNS::Slicehost::GetRecord.new,
:path => "records/#{record_id}.xml"
)
end

View file

@ -10,14 +10,13 @@ module Fog
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# * 'addresses'<~Array> - Ip addresses for the slice
# * 'backup-id'<~Integer> - Id of backup slice was booted from
# * 'flavor_id'<~Integer> - Id of flavor slice was booted from
# * 'id'<~Integer> - Id of the slice
# * 'image-id'<~Integer> - Id of image slice was booted from
# * 'name'<~String> - Name of the slice
# * 'progress'<~Integer> - Progress of current action, in percentage
# * 'status'<~String> - Current status of the slice
# * 'name'<~String> - Record NAME field (e.g. "example.org." or "www")
# * 'data'<~String> - Data contained by the record (e.g. an IP address, for A records)
# * 'record_type'<~String> - Type of record (A, CNAME, TXT, etc)
# * 'aux'<~String> - Aux data for the record, for those types which have it (e.g. TXT)
# * 'zone_id'<~Integer> - zone ID to which this record belongs
# * 'active'<~String> - whether this record is active in the Slicehost DNS (Y for yes, N for no)
# * 'ttl'<~Integer> - TTL in seconds
def get_records
request(
:expects => 200,

View file

@ -0,0 +1,43 @@
module Fog
module DNS
class Slicehost
class Real
#require 'fog/slicehost/parsers/dns/update_record'
# Get an individual DNS record from the specified zone
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'record_type'<~String> - type of DNS record to create (A, CNAME, etc)
# * 'zone_id'<~Integer> - ID of the zone to update
# * 'name'<~String> - host name this DNS record is for
# * 'data'<~String> - data for the DNS record (ie for an A record, the IP address)
# * 'ttl'<~Integer> - time to live in seconds
# * 'active'<~String> - whether this record is active or not ('Y' or 'N')
# * 'aux'<~String> - extra data required by the record
def update_record(record_id, record_type, zone_id, name, data, options = {})
optional_tags= ''
options.each { |option, value|
case option
when :ttl
optional_tags+= "<ttl type='integer'>#{value}</ttl>"
when :active
optional_tags+= "<active>#{value}</active>"
when :aux
optional_tags+= "<aux>#{value}</aux>"
end
}
request(
:body => %Q{<?xml version="1.0" encoding="UTF-8"?><record><record_type>#{record_type}</record_type><zone_id type="integer">#{zone_id}</zone_id><name>#{name}</name><data>#{data}</data>#{optional_tags}</record>},
:expects => 200,
:method => 'PUT',
:path => "records/#{record_id}.xml"
)
end
end
end
end
end

View file

@ -183,11 +183,11 @@ Shindo.tests('Fog::DNS[:slicehost] | DNS requests', ['slicehost', 'dns']) do
response = Fog::DNS[:slicehost].get_record(@record_id)
if response.status == 200
mail_domain = 'mail.' + @domain
record = response.body['records'][0]
if (record['record-type'] == 'MX') and (record['name'] == @domain) and
(record['data'] == mail_domain) and (record['ttl'] == 3600) and (record['active'] == 'N') and
record = response.body
if (record['record_type'] == 'MX') and (record['name'] == @domain) and
(record['value'] == mail_domain) and (record['ttl'] == 3600) and (record['active'] == 'N') and
(record['aux'] == "10")
result= true
result = true
end
end
@ -197,7 +197,7 @@ Shindo.tests('Fog::DNS[:slicehost] | DNS requests', ['slicehost', 'dns']) do
test('get records - verify all parameters for one record') do
pending if Fog.mocking?
result= false
result = false
response = Fog::DNS[:slicehost].get_records()
if response.status == 200
@ -205,22 +205,69 @@ Shindo.tests('Fog::DNS[:slicehost] | DNS requests', ['slicehost', 'dns']) do
#find mx record
records.each {|record|
if record['record-type'] == 'MX'
if (record['record_type'] == 'MX') and (record['name'] == @domain)
mail_domain = 'mail.' + @domain
if (record['record-type'] == 'MX') and (record['name'] == @domain) and
(record['data'] == mail_domain) and (record['ttl'] == 3600) and (record['active'] == 'N') and
if (record['record_type'] == 'MX') and (record['name'] == @domain) and
(record['value'] == mail_domain) and (record['ttl'] == 3600) and (record['active'] == 'N') and
(record['aux'] == "10")
result= true
break
result = true
end
break
end
}
end
result
end
test('update record - verify all parameters for one record') do
pending if Fog.mocking?
result = false
specific_record = nil
response = Fog::DNS[:slicehost].get_records()
if response.status == 200
records = response.body['records']
#find mx record
records.each {|record|
if (record['record_type'] == 'MX') and (record['name'] == @domain)
specific_record = record
break
end
}
end
if (specific_record) #Try to change the TTL for this MX record if we've successfully created it.
response = Fog::DNS[:slicehost].update_record(specific_record['id'], specific_record['record_type'], specific_record['zone_id'],
specific_record['name'], specific_record['value'], {:ttl => 7200, :active => "N", :aux => "10"})
mail_domain = 'mail.' + @domain
record = Fog::DNS[:slicehost].get_record(specific_record['id']).body
if (record['record_type'] == 'MX') and (record['name'] == @domain) and
(record['value'] == mail_domain) and (record['ttl'] == 7200) and (record['active'] == 'N') and
(record['aux'] == "10")
result = true
end
end
result
end
test("newly created zone returns only records which we added to it, not other records already in account") do
pending if Fog.mocking?
@new_zone = Fog::DNS[:slicehost].zones.get(@zone_id)
records = @new_zone.records
records.length == @new_records.length
end
test("delete #{@new_records.count} records created") do
pending if Fog.mocking?