diff --git a/lib/fog/linode/dns.rb b/lib/fog/linode/dns.rb index c6eabb6ad..eea24fc3d 100644 --- a/lib/fog/linode/dns.rb +++ b/lib/fog/linode/dns.rb @@ -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 diff --git a/lib/fog/linode/models/dns/record.rb b/lib/fog/linode/models/dns/record.rb new file mode 100644 index 000000000..79215ba19 --- /dev/null +++ b/lib/fog/linode/models/dns/record.rb @@ -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 diff --git a/lib/fog/linode/models/dns/records.rb b/lib/fog/linode/models/dns/records.rb new file mode 100644 index 000000000..07657a83d --- /dev/null +++ b/lib/fog/linode/models/dns/records.rb @@ -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 diff --git a/lib/fog/linode/models/dns/zone.rb b/lib/fog/linode/models/dns/zone.rb new file mode 100644 index 000000000..a8cbc0a3d --- /dev/null +++ b/lib/fog/linode/models/dns/zone.rb @@ -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 diff --git a/lib/fog/linode/models/dns/zones.rb b/lib/fog/linode/models/dns/zones.rb new file mode 100644 index 000000000..91b53d7d3 --- /dev/null +++ b/lib/fog/linode/models/dns/zones.rb @@ -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 diff --git a/lib/fog/linode/requests/dns/domain_create.rb b/lib/fog/linode/requests/dns/domain_create.rb index 111695aa3..c17c8afe7 100644 --- a/lib/fog/linode/requests/dns/domain_create.rb +++ b/lib/fog/linode/requests/dns/domain_create.rb @@ -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 diff --git a/lib/fog/linode/requests/dns/domain_resource_create.rb b/lib/fog/linode/requests/dns/domain_resource_create.rb index 5b16c088c..30f3d1e60 100644 --- a/lib/fog/linode/requests/dns/domain_resource_create.rb +++ b/lib/fog/linode/requests/dns/domain_resource_create.rb @@ -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 diff --git a/lib/fog/linode/requests/dns/domain_resource_list.rb b/lib/fog/linode/requests/dns/domain_resource_list.rb index 22f1e524f..6c0d8c38e 100644 --- a/lib/fog/linode/requests/dns/domain_resource_list.rb +++ b/lib/fog/linode/requests/dns/domain_resource_list.rb @@ -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 diff --git a/lib/fog/linode/requests/dns/domain_resource_update.rb b/lib/fog/linode/requests/dns/domain_resource_update.rb index 48bc59b92..bfd0628f2 100644 --- a/lib/fog/linode/requests/dns/domain_resource_update.rb +++ b/lib/fog/linode/requests/dns/domain_resource_update.rb @@ -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 diff --git a/lib/fog/linode/requests/dns/domain_update.rb b/lib/fog/linode/requests/dns/domain_update.rb index a3e117f98..3e8d25b35 100644 --- a/lib/fog/linode/requests/dns/domain_update.rb +++ b/lib/fog/linode/requests/dns/domain_update.rb @@ -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 diff --git a/lib/fog/slicehost/models/dns/record.rb b/lib/fog/slicehost/models/dns/record.rb index afdf15286..bc631fddf 100644 --- a/lib/fog/slicehost/models/dns/record.rb +++ b/lib/fog/slicehost/models/dns/record.rb @@ -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={}) diff --git a/lib/fog/zerigo/models/dns/record.rb b/lib/fog/zerigo/models/dns/record.rb index c22a9d0b0..22110f651 100644 --- a/lib/fog/zerigo/models/dns/record.rb +++ b/lib/fog/zerigo/models/dns/record.rb @@ -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'