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

[zerigo|dns] first rough pass at models

This commit is contained in:
geemus 2010-12-22 20:36:53 -08:00
parent be64214d96
commit a641545902
6 changed files with 222 additions and 13 deletions

View file

@ -5,25 +5,27 @@ module Fog
requires :zerigo_email, :zerigo_token
recognizes :timeout, :persistent
# model_path 'fog/zerigo/models/dns'
# model :server
# collection :servers
model_path 'fog/zerigo/models/dns'
model :record
collection :records
model :zone
collection :zones
request_path 'fog/zerigo/requests/dns'
request :list_zones
request :count_hosts
request :count_zones
request :create_host
request :create_zone
request :delete_host
request :delete_zone
request :find_hosts
request :get_host
request :get_zone
request :get_zone_stats
request :create_zone
request :update_zone
request :delete_zone
request :list_zones
request :list_hosts
request :find_hosts
request :count_hosts
request :get_host
request :create_host
request :update_host
request :delete_host
request :update_zone
class Mock

View file

@ -0,0 +1,54 @@
require 'fog/core/model'
module Fog
module Zerigo
class DNS
class Record < Fog::Model
identity :id
attribute :created_at, :aliases => 'created-at'
attribute :ip, :aliases => 'data'
attribute :domain, :aliases => 'fqdn'
attribute :name, :aliases => 'hostname'
attribute :notes
attribute :priority
attribute :ttl
attribute :type, :aliases => 'host-type'
attribute :updated_at, :aliases => 'updated-at'
attribute :zone_id, :aliases => 'zone-id'
def destroy
requires :identity
connection.delete_host(identity)
true
end
def zone
@zone
end
def save
requires :zone, :type, :ip
options = {}
options[:hostname] = name if name
options[:notes] = notes if notes
options[:priority] = priority if priority
options[:ttl] = ttl if ttl
data = connection.create_host(@zone.id, type, ip, options)
merge_attributes(data.body)
true
end
private
def zone=(new_zone)
@zone = new_zone
end
end
end
end
end

View file

@ -0,0 +1,41 @@
require 'fog/core/collection'
require 'fog/zerigo/models/dns/record'
module Fog
module Zerigo
class DNS
class Records < Fog::Collection
attribute :zone
model Fog::Zerigo::DNS::Record
def all
requires :zone
parent = zone.collection.get(zone.identity)
if parent
merge_attributes(parent.records.attributes)
load(parent.records.map {|record| record.attributes})
else
nil
end
end
def get(record_id)
data = connection.get_host(record_id).body
new(data)
rescue Excon::Errors::NotFound
nil
end
def new(attributes = {})
requires :zone
super({ :zone => zone }.merge!(attributes))
end
end
end
end
end

View file

@ -0,0 +1,82 @@
require 'fog/core/model'
require 'fog/zerigo/models/dns/records'
module Fog
module Zerigo
class DNS
class Zone < Fog::Model
identity :id
attribute :created_at, :aliases => 'created-at'
attribute :domain
attribute :ttl, :aliases => 'default-ttl'
attribute :type, :aliases => 'ns-type'
attribute :updated_at, :aliases => 'updated-at'
# <custom-nameservers>ns1.example.com,ns2.example.com</custom-nameservers>
# <custom-ns type="boolean">true</custom-ns>
# <hostmaster>dnsadmin@example.com</hostmaster>
# <notes nil="true"/>
# <ns1 nil="true"/>
# <nx-ttl nil="true"></nx-ttl>
# <slave-nameservers nil="true"/>
# <tag-list>one two</tag-list>
# <hosts-count>1</hosts-count>
def initialize(attributes={})
self.type ||= 'pri_sec'
self.ttl ||= 3600
super
end
def destroy
requires :identity
connection.delete_zone(identity)
true
end
def records
@records ||= begin
Fog::Zerigo::DNS::Records.new(
:zone => self,
:connection => connection
)
end
end
def nameservers
[
'a.ns.zerigo.net',
'b.ns.zerigo.net',
'c.ns.zerigo.net',
'd.ns.zerigo.net',
'e.ns.zerigo.net'
]
end
def save
requires :domain, :type, :ttl
options = {}
# * options<~Hash> - optional paramaters
# * ns1<~String> - required if ns_type == sec
# * nx_ttl<~Integer> -
# * slave_nameservers<~String> - required if ns_type == pri
# * axfr_ips<~String> - comma-separated list of IPs or IP blocks allowed to perform AXFRs
# * custom_nameservers<~String> - comma-separated list of custom nameservers
# * custom_ns<~String> - indicates if vanity (custom) nameservers are enabled for this domain
# * hostmaster<~String> - email of the DNS administrator or hostmaster
# * notes<~String> - notes about the domain
# * restrict_axfr<~String> - indicates if AXFR transfers should be restricted to IPs in axfr-ips
# * tag_list<~String> - List of all tags associated with this domain
data = connection.create_zone(domain, ttl, type, options)
merge_attributes(data.body)
true
end
end
end
end
end

View file

@ -0,0 +1,30 @@
require 'fog/core/collection'
require 'fog/zerigo/models/dns/zone'
module Fog
module Zerigo
class DNS
class Zones < Fog::Collection
model Fog::Zerigo::DNS::Zone
def all
data = connection.list_zones.body['zones']
load(data)
end
def get(zone_id)
data = connection.get_zone(zone_id).body
zone = new(data)
zone.records.load(data['hosts'])
zone
rescue Excon::Errors::Forbidden
nil
end
end
end
end
end

View file

@ -31,7 +31,7 @@ module Fog
# * 'updated-at'<~String>
# * 'zone-id'<~String>
# * 'status'<~Integer> - 201 if successful
def create_host( zone_id, host_type, data, options = {} )
def create_host(zone_id, host_type, data, options = {})
optional_tags= ''
options.each { |option, value|