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:
parent
c5583a0e7e
commit
15832b0eb7
5 changed files with 120 additions and 7 deletions
|
@ -6,6 +6,8 @@ module Fog
|
||||||
recognizes :host, :path, :port, :scheme, :version, :persistent
|
recognizes :host, :path, :port, :scheme, :version, :persistent
|
||||||
|
|
||||||
model_path 'fog/aws/models/dns'
|
model_path 'fog/aws/models/dns'
|
||||||
|
model :record
|
||||||
|
collection :records
|
||||||
model :zone
|
model :zone
|
||||||
collection :zones
|
collection :zones
|
||||||
|
|
||||||
|
|
64
lib/fog/aws/models/dns/record.rb
Normal file
64
lib/fog/aws/models/dns/record.rb
Normal 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
|
47
lib/fog/aws/models/dns/records.rb
Normal file
47
lib/fog/aws/models/dns/records.rb
Normal 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
|
|
@ -22,12 +22,12 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def records
|
def records
|
||||||
# @records ||= begin
|
@records ||= begin
|
||||||
# Fog::Linode::DNS::Records.new(
|
Fog::AWS::DNS::Records.new(
|
||||||
# :zone => self,
|
:zone => self,
|
||||||
# :connection => connection
|
:connection => connection
|
||||||
# )
|
)
|
||||||
# end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def save
|
def save
|
||||||
|
|
|
@ -22,7 +22,7 @@ module Fog
|
||||||
def get(zone_id)
|
def get(zone_id)
|
||||||
data = connection.get_hosted_zone(zone_id).body
|
data = connection.get_hosted_zone(zone_id).body
|
||||||
new(data)
|
new(data)
|
||||||
rescue Excon::Errors::Forbidden
|
rescue Excon::Errors::BadRequest
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue