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

[aws|dns] record(s) models

This commit is contained in:
geemus 2011-01-03 14:45:50 -08:00
parent c5583a0e7e
commit 15832b0eb7
5 changed files with 120 additions and 7 deletions

View file

@ -6,6 +6,8 @@ module Fog
recognizes :host, :path, :port, :scheme, :version, :persistent
model_path 'fog/aws/models/dns'
model :record
collection :records
model :zone
collection :zones

View file

@ -0,0 +1,64 @@
require 'fog/core/model'
module Fog
module AWS
class DNS
class Record < Fog::Model
identity :id, :aliases => ['Id']
attribute :ip, :aliases => ['ResourceRecords']
attribute :name, :aliases => ['Name']
attribute :ttl, :aliases => ['TTL']
attribute :type, :aliases => ['Type']
attribute :status, :aliases => ['Status']
attribute :created_at, :aliases => ['SubmittedAt']
def initialize(attributes={})
self.ttl ||= 3600
super
end
def destroy
requires :ip, :name, :ttl, :type, :zone
options = {
:action => 'DELETE',
:name => name,
:resource_records => [*ip],
:ttl => ttl,
:type => type
}
connection.change_resource_record_sets(zone.id, [options])
true
end
def zone
@zone
end
def save
requires :ip, :name, :ttl, :type, :zone
options = {
:action => 'CREATE',
:name => name,
:resource_records => [*ip],
:ttl => ttl,
:type => type
}
data = connection.change_resource_record_sets(zone.id, [options]).body
merge_attributes(data)
true
end
private
def zone=(new_zone)
@zone = new_zone
end
end
end
end
end

View file

@ -0,0 +1,47 @@
require 'fog/core/collection'
require 'fog/aws/models/dns/record'
module Fog
module AWS
class DNS
class Records < Fog::Collection
attribute :is_truncated, :aliases => ['IsTruncated']
attribute :max_items, :aliases => ['MaxItems']
attribute :name
attribute :next_record_name, :aliases => ['NextRecordName']
attribute :next_record_type, :aliases => ['NextRecordType']
attribute :type
attribute :zone
model Fog::AWS::DNS::Record
def all(options = {})
requires :zone
options['MaxItems'] ||= max_items
options['Name'] ||= name
options['Type'] ||= type
data = connection.list_resource_record_sets(zone.id, options).body
merge_attributes(data.reject {|key, value| !['IsTruncated', 'MaxItems', 'NextRecordName', 'NextRecordType'].include?(key)})
load(data['ResourceRecordSets'])
end
def get(record_id)
data = connection.get_change(record_id).body
new(data)
rescue Excon::Errors::BadRequest
nil
end
def new(attributes = {})
requires :zone
super({ :zone => zone }.merge!(attributes))
end
end
end
end
end

View file

@ -22,12 +22,12 @@ module Fog
end
def records
# @records ||= begin
# Fog::Linode::DNS::Records.new(
# :zone => self,
# :connection => connection
# )
# end
@records ||= begin
Fog::AWS::DNS::Records.new(
:zone => self,
:connection => connection
)
end
end
def save

View file

@ -22,7 +22,7 @@ module Fog
def get(zone_id)
data = connection.get_hosted_zone(zone_id).body
new(data)
rescue Excon::Errors::Forbidden
rescue Excon::Errors::BadRequest
nil
end