Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[zerigo|dns] first rough pass at models
- Loading branch information
Showing
6 changed files
with
221 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters