Permalink
Browse files

Update to use R53 API 2011-05-05 and add support for changebatch of w…

…eighted records
  • Loading branch information...
Alfred Moreno
Alfred Moreno committed Oct 22, 2011
1 parent 70e7ea1 commit a7404f0086bc19df6f2e37f892e616cc53791ec2
View
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
## If your rubyforge_project name is different, then edit it and comment out
## the sub! line in the Rakefile
s.name = 'fog'
- s.version = '1.0.0'
- s.date = '2011-09-29'
+ s.version = '1.0.2'
+ s.date = '2011-10-21'
s.rubyforge_project = 'fog'
## Make sure your summary is short. The description may be as long
View
@@ -89,7 +89,7 @@ def initialize(options={})
@persistent = options[:persistent] || true
@port = options[:port] || 443
@scheme = options[:scheme] || 'https'
- @version = options[:version] || '2010-10-01'
+ @version = options[:version] || '2011-05-05'
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
end
@@ -40,32 +40,42 @@ def change_resource_record_sets(zone_id, change_batch, options = {})
optional_tags+= "<Comment>#{value}</Comment>"
end
}
-
+
#build XML
if change_batch.count > 0
-
+
changes= "<ChangeBatch>#{optional_tags}<Changes>"
-
+
change_batch.each { |change_item|
action_tag = %Q{<Action>#{change_item[:action]}</Action>}
name_tag = %Q{<Name>#{change_item[:name]}</Name>}
type_tag = %Q{<Type>#{change_item[:type]}</Type>}
ttl_tag = %Q{<TTL>#{change_item[:ttl]}</TTL>}
+
+ raise "Weighted records require a 'setidentifier' and 'weight' tag to be specified, but you only specified the #{change_item[:setidentifier].nil?? 'weight' : 'setidentifier'}" if (change_item[:weight].nil? and !change_item[:setidentifier].nil?) or (!change_item[:weight].nil? and change_item[:setidentifier].nil?)
+ identifier_tag = %Q{<SetIdentifier>#{change_item[:setidentifier]}</SetIdentifier>} unless change_item[:setidentifier].nil?
+ weight_tag = %Q{<Weight>#{change_item[:weight]}</Weight>} unless change_item[:weight].nil?
+
resource_records= change_item[:resource_records]
resource_record_tags = ''
resource_records.each { |record|
resource_record_tags+= %Q{<ResourceRecord><Value>#{record}</Value></ResourceRecord>}
}
resource_tag= %Q{<ResourceRecords>#{resource_record_tags}</ResourceRecords>}
-
- change_tags = %Q{<Change>#{action_tag}<ResourceRecordSet>#{name_tag}#{type_tag}#{ttl_tag}#{resource_tag}</ResourceRecordSet></Change>}
+
+ if (change_item[:weight].nil? and change_item[:setidentifier].nil?)
+ change_tags = %Q{<Change>#{action_tag}<ResourceRecordSet>#{name_tag}#{type_tag}#{ttl_tag}#{resource_tag}</ResourceRecordSet></Change>}
+ else
+ change_tags = %Q{<Change>#{action_tag}<ResourceRecordSet>#{name_tag}#{type_tag}#{identifier_tag}#{weight_tag}#{ttl_tag}#{resource_tag}</ResourceRecordSet></Change>}
+ end
changes+= change_tags
}
-
+
changes+= '</Changes></ChangeBatch>'
+ puts "@@@ SENDING @@@\n#{changes}\n\n"
end
- body = %Q{<?xml version="1.0" encoding="UTF-8"?><ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2010-10-01/">#{changes}</ChangeResourceRecordSetsRequest>}
+ body = %Q{<?xml version="1.0" encoding="UTF-8"?><ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2011-05-05/">#{changes}</ChangeResourceRecordSetsRequest>}
request({
:body => body,
:parser => Fog::Parsers::DNS::AWS::ChangeResourceRecordSets.new,
@@ -44,7 +44,7 @@ def create_hosted_zone(name, options = {})
end
request({
- :body => %Q{<?xml version="1.0" encoding="UTF-8"?><CreateHostedZoneRequest xmlns="https://route53.amazonaws.com/doc/2010-10-01/"><Name>#{name}</Name>#{optional_tags}</CreateHostedZoneRequest>},
+ :body => %Q{<?xml version="1.0" encoding="UTF-8"?><CreateHostedZoneRequest xmlns="https://route53.amazonaws.com/doc/2011-05-05/"><Name>#{name}</Name>#{optional_tags}</CreateHostedZoneRequest>},
:parser => Fog::Parsers::DNS::AWS::CreateHostedZone.new,
:expects => 201,
:method => 'POST',

0 comments on commit a7404f0

Please sign in to comment.