lib/fog/rackspace/models/dns/record.rb in fog-maestrodev-1.7.0.20121114190951 vs lib/fog/rackspace/models/dns/record.rb in fog-maestrodev-1.8.0.20130109172219
- old
+ new
@@ -1,7 +1,8 @@
require 'fog/core/model'
require 'fog/rackspace/models/dns/callback'
+require 'ipaddr'
module Fog
module DNS
class Rackspace
@@ -21,20 +22,20 @@
attribute :created
attribute :updated
def destroy
requires :zone, :identity
- wait_for_job connection.remove_record(@zone.identity, identity).body['jobId']
+ wait_for_job service.remove_record(@zone.identity, identity).body['jobId']
true
end
def zone
@zone
end
def save
- if identity
+ if persisted?
update
else
create
end
end
@@ -48,16 +49,32 @@
:name => name,
:type => type,
:data => value
}
+ if ttl
+ options[:ttl] = ttl
+ end
+
if priority
options[:priority] = priority
end
- response = wait_for_job connection.add_records(@zone.identity, [options]).body['jobId']
- merge_attributes(response.body['response']['records'].select {|record| record['name'] == self.name && record['type'] == self.type && record['data'] == self.value}.first)
+ response = wait_for_job service.add_records(@zone.identity, [options]).body['jobId']
+
+ matching_record = response.body['response']['records'].find do |record|
+ if ['A', 'AAAA'].include?(self.type.upcase)
+ # If this is an A or AAAA record, match by normalized IP address value.
+ (record['name'] == self.name) && (record['type'] == self.type) && (IPAddr.new(record['data']) == IPAddr.new(self.value))
+ else
+ # Other record types are matched by the raw value.
+ (record['name'] == self.name) && (record['type'] == self.type) && (record['data'] == self.value)
+ end
+ end
+
+ merge_attributes(matching_record)
+
true
end
def update
requires :identity, :zone
@@ -65,11 +82,12 @@
options = {}
options[:name] = name if name
options[:type] = type if type
options[:data] = value if value
options[:priority] = priority if priority
+ options[:ttl] = ttl if ttl
- wait_for_job connection.modify_record(@zone.identity, identity, options).body['jobId']
+ wait_for_job service.modify_record(@zone.identity, identity, options).body['jobId']
true
end
def zone=(new_zone)
@zone = new_zone