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

[linode|dns] first pass at models

This commit is contained in:
geemus 2010-12-23 16:47:47 -08:00
parent 13e8141158
commit 39ed179198
12 changed files with 239 additions and 16 deletions

View file

@ -6,6 +6,10 @@ module Fog
recognizes :port, :scheme, :persistent
model_path 'fog/linode/models/dns'
model :record
collection :records
model :zone
collection :zones
request_path 'fog/linode/requests/dns'
request :domain_create

View file

@ -0,0 +1,69 @@
require 'fog/core/model'
module Fog
module Linode
class DNS
class Record < Fog::Model
identity :id, :aliases => ['ResourceID', 'RESOURCEID']
attribute :ip, :aliases => 'TARGET'
attribute :name, :aliases => 'NAME'
attribute :priority, :aliases => 'PRIORITY'
attribute :ttl, :aliases => 'TTL_SEC'
attribute :type, :aliases => 'TYPE'
attribute :zone_id, :aliases => 'DOMAINID'
# "PROTOCOL":"",
# "WEIGHT":0,
# "PORT":0,
def initialize(attributes={})
self.ttl ||= 3600
super
end
def destroy
requires :identity
connection.domain_resource_delete(identity)
true
end
def zone
@zone
end
def save
requires :type, :zone
options = {}
# * options<~Hash>
# * weight<~Integer>: default: 5
# * port<~Integer>: default: 80
# * protocol<~String>: The protocol to append to an SRV record. Ignored on other record
# types. default: udp
options[:name] = name if name
options[:priority] = priority if priority
options[:target] = ip if ip
options[:ttl_sec] = ttl if ttl
data = unless identity
connection.domain_resource_create(zone.id, type)
else
options[:type] = type if type
connection.domain_resource_update(zone.id, identity, optionts)
end
merge_attributes(data.body)
true
end
private
def zone=(new_zone)
@zone = new_zone
end
end
end
end
end

View file

@ -0,0 +1,36 @@
require 'fog/core/collection'
require 'fog/linode/models/dns/record'
module Fog
module Linode
class DNS
class Records < Fog::Collection
attribute :zone
model Fog::Linode::DNS::Record
def all
requires :zone
data = connection.domain_resource_list(zone.id).body['DATA']
load(data)
end
def get(record_id)
data = connection.domain_resource_list(zone.id, record_id).body['DATA']
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,84 @@
require 'fog/core/model'
require 'fog/linode/models/dns/records'
module Fog
module Linode
class DNS
class Zone < Fog::Model
identity :id, :aliases => ['DOMAINID', 'ResourceID']
attribute :description, :aliases => 'DESCRIPTION'
attribute :domain, :aliases => 'DOMAIN'
attribute :email, :aliases => 'SOA_EMAIL'
attribute :ttl, :aliases => 'TTL_SEC'
attribute :type, :aliases => 'TYPE'
# "STATUS":1,
# "RETRY_SEC":0,
# "MASTER_IPS":"",
# "EXPIRE_SEC":0,
# "REFRESH_SEC":0,
# "TTL_SEC":0
def initialize(attributes={})
self.type ||= 'master'
self.ttl ||= 3600
super
end
def destroy
requires :identity
connection.domain_delete(identity)
true
end
def records
@records ||= begin
Fog::Linode::DNS::Records.new(
:zone => self,
:connection => connection
)
end
end
def nameservers
[
'ns1.linode.com',
'ns2.linode.com',
'ns3.linode.com',
'ns4.linode.com',
'ns5.linode.com'
]
end
def save
requires :domain, :type
requires :email if type == 'master'
options = {}
# * options<~Hash>
# * refresh_sec<~Integer> numeric, default: '0'
# * retry_sec<~Integer> numeric, default: '0'
# * expire_sec<~Integer> numeric, default: '0'
# * status<~Integer> 0, 1, or 2 (disabled, active, edit mode), default: 1
# * master_ips<~String> When type=slave, the zone's master DNS servers list, semicolon separated
options[:description] = description if description
options[:soa_email] = email if email
options[:ttl_sec] = ttl if ttl
data = unless identity
connection.domain_create(domain, type, options).body['DATA']
else
options[:domain] = domain if domain
options[:type] = type if type
connection.domain_update(identity, options)
end
merge_attributes(data)
true
end
end
end
end
end

View file

@ -0,0 +1,28 @@
require 'fog/core/collection'
require 'fog/linode/models/dns/zone'
module Fog
module Linode
class DNS
class Zones < Fog::Collection
model Fog::Linode::DNS::Zone
def all
data = connection.domain_list.body['DATA']
load(data)
end
def get(zone_id)
data = connection.domain_list(zone_id).body['DATA']
new(data)
rescue Excon::Errors::Forbidden
nil
end
end
end
end
end

View file

@ -24,8 +24,7 @@ module Fog
# * body<~Hash>:
# * DATA<~Hash>:
# * 'DomainID'<~Integer>: domain ID
def domain_create( domain, type, options = {})
def domain_create(domain, type, options = {})
query= {}
request(
:expects => 200,
@ -42,7 +41,7 @@ module Fog
class Mock
def domain_create( domain, type, options ={})
def domain_create(domain, type, options ={})
Fog::Mock.not_implemented
end

View file

@ -11,7 +11,7 @@ module Fog
# * options<~Hash>
# * name<~String>: The hostname or FQDN. When Type=MX the subdomain to delegate to the
# Target MX server
# * targe<~String> When Type=MX the hostname. When Type=CNAME the target of the alias.
# * target<~String> When Type=MX the hostname. When Type=CNAME the target of the alias.
# When Type=TXT the value of the record. When Type=A or AAAA the token
# of '[remote_addr]' will be substituted with the IP address of the request.
# * priority<~Integer>: priority for MX and SRV records, 0-255 - default: 10
@ -25,7 +25,7 @@ module Fog
# * body<~Hash>:
# * DATA<~Hash>:
# * 'ResourceID'<~Integer>: ID of the resource record created
def domain_resource_create( domain_id, type, options = {})
def domain_resource_create(domain_id, type, options = {})
query= {}
request(
@ -43,7 +43,7 @@ module Fog
class Mock
def domain_resource_create( domain_id, type, options = {})
def domain_resource_create(domain_id, type, options = {})
Fog::Mock.not_implemented
end

View file

@ -26,11 +26,14 @@ module Fog
# * 'DOMAINID'<~Interger>: ID of the domain that this record belongs to
# * 'NAME'<~Interger>: The hostname or FQDN. When Type=MX, the subdomain to delegate to
def domain_resource_list(domain_id, resource_id = nil)
query = { :api_action => 'domain.resource.list', :domainID => domain_id }
if resource_id
query[:resourceID] = resource_id
end
request(
:expects => 200,
:method => 'GET',
:query => { :api_action => 'domain.resource.list', :domainID => domain_id, :resourceID => resource_id }
:query => query
)
end

View file

@ -26,7 +26,7 @@ module Fog
# * body<~Hash>:
# * DATA<~Hash>:
# * 'ResourceID'<~Integer>: ID of the resource record updated
def domain_resource_update( domain_id, resource_id, options = {})
def domain_resource_update(domain_id, resource_id, options = {})
query= {}
request(
@ -44,7 +44,7 @@ module Fog
class Mock
def domain_resource_update( domain_id, resource_id, options = {})
def domain_resource_update(domain_id, resource_id, options = {})
Fog::Mock.not_implemented
end

View file

@ -24,7 +24,7 @@ module Fog
# * body<~Hash>:
# * DATA<~Hash>:
# * 'DomainID'<~Integer>: domain ID
def domain_update( domain_id, options = {})
def domain_update(domain_id, options = {})
request(
:expects => 200,
@ -38,7 +38,7 @@ module Fog
class Mock
def domain_update(datacenter_id, payment_term, plan_id)
def domain_update(domain_id, options = {})
Fog::Mock.not_implemented
end

View file

@ -9,11 +9,11 @@ module Fog
identity :id
attribute :active
attribute :ip, :aliases => 'ip'
attribute :ip, :aliases => 'ip'
attribute :name
attribute :notes, :aliases => 'aux'
attribute :description, :aliases => 'aux'
attribute :ttl
attribute :type, :aliases => 'record_type'
attribute :type, :aliases => 'record_type'
attribute :zone_id
def initialize(attributes={})

View file

@ -12,7 +12,7 @@ module Fog
attribute :ip, :aliases => 'data'
attribute :domain, :aliases => 'fqdn'
attribute :name, :aliases => 'hostname'
attribute :notes
attribute :description, :aliases => 'notes'
attribute :priority
attribute :ttl
attribute :type, :aliases => 'host-type'