From 0ffd1404d53e3e81cc8e7321a89f50916e0c56fc Mon Sep 17 00:00:00 2001 From: Athir Nuaimi Date: Sat, 11 Dec 2010 11:32:41 -0500 Subject: [PATCH] All Linode DNS functions are now supported. Still needs some testing though Added support for all the DNS resource functions. As with Slicehost, no mocks or test cases yet. Also, example code still needs some updating --- examples/dns_methods.rb | 58 +++++++++++++++---- lib/fog/linode/compute.rb | 8 +-- .../linode/requests/compute/domain_create.rb | 2 +- .../linode/requests/compute/domain_delete.rb | 2 +- .../linode/requests/compute/domain_list.rb | 2 +- .../compute/domain_resource_create.rb | 53 +++++++++++++++++ .../compute/domain_resource_delete.rb | 36 ++++++++++++ .../requests/compute/domain_resource_list.rb | 48 +++++++++++++++ .../compute/domain_resource_update.rb | 54 +++++++++++++++++ .../linode/requests/compute/domain_update.rb | 52 +++++++++++++++++ 10 files changed, 297 insertions(+), 18 deletions(-) create mode 100644 lib/fog/linode/requests/compute/domain_resource_create.rb create mode 100644 lib/fog/linode/requests/compute/domain_resource_delete.rb create mode 100644 lib/fog/linode/requests/compute/domain_resource_list.rb create mode 100644 lib/fog/linode/requests/compute/domain_resource_update.rb create mode 100644 lib/fog/linode/requests/compute/domain_update.rb diff --git a/examples/dns_methods.rb b/examples/dns_methods.rb index 3fc71988c..58cab6474 100644 --- a/examples/dns_methods.rb +++ b/examples/dns_methods.rb @@ -16,11 +16,47 @@ def show_linode_dns_usage( api_key) end begin + #connect to Linode options = { :linode_api_key => api_key } cloud= Fog::Linode::Compute.new( options) + + #create a zone for a domain + domain = 'sample-domain.com' + type = 'master' + options = { :SOA_email => 'netops@sample-domain.com', :description => "Sample-Domain Inc", :status => 0} + response = cloud.domain_create( domain, type, options) + if response.status == 200 + master_zone_id = response.body['DATA']['DOMAINID'] + end - # will add samples once finished adding linode DNS API to fog - + #create a slave zone + domain = 'sample-slave-domain.com' + type = 'slave' + options = { :master_ips => '1.2.3.4; 1.2.3.5'} + response = cloud.domain_create( domain, type, options) + if response.status == 200 + slave_zone_id = response.body['DATA']['DOMAINID'] + end + + #add an A record for website + + #get a list of zones Linode hosted for account + response = cloud.domain_list() + if response.status == 200 + num_zones = response.body['DATA'].count + puts "Linode is hosting #{num_zones} DNS zones for this account" + end + + #finally cleanup by deleting the zone we created + response = cloud.domain_delete( master_zone_id) + if response.status == 200 + puts "master zone deleted" + end + response = cloud.domain_delete( slave_zone_id) + if response.status == 200 + puts "slave zone deleted" + end + rescue #opps, ran into a problem puts $!.message @@ -43,13 +79,6 @@ def show_slicehost_dns_usage( password) options = { :slicehost_password => password } cloud= Fog::Slicehost::Compute.new( options) - #start by getting a list of existing zones Slicehost hosted for account - response = cloud.get_zones() - if response.status == 200 - num_zones= response.body['zones'].count - puts "Slicehost is hosting #{num_zones} DNS zones for this account" - end - #create a zone for a domain zone_id = 0 options = { :ttl => 1800, :active => 'N' } @@ -66,14 +95,21 @@ def show_slicehost_dns_usage( password) record_id= response.body['id'] end - #now get details on zone and A record for www + #get a list of zones Slicehost hosted for account + response = cloud.get_zones() + if response.status == 200 + num_zones= response.body['zones'].count + puts "Slicehost is hosting #{num_zones} DNS zones for this account" + end + + #now get details on www record for the zone if record_id > 0 response = cloud.get_record( record_id) if response.status == 200 record = response.body['records'][0] name = record['name'] type = record['record-type'] - puts "got #{type} record for #{name} domain" + puts "record is an #{type} record for #{name} domain" end end diff --git a/lib/fog/linode/compute.rb b/lib/fog/linode/compute.rb index 69c7ff956..6b84a1795 100644 --- a/lib/fog/linode/compute.rb +++ b/lib/fog/linode/compute.rb @@ -16,10 +16,10 @@ module Fog request :domain_create request :domain_delete request :domain_list - # request :domain_update - # request :domain_resource_create - # request :domain_resource_delete - # request :domain_resource_list + request :domain_update + request :domain_resource_create + request :domain_resource_delete + request :domain_resource_list # request :domain_resource_update # request :linode_boot request :linode_create diff --git a/lib/fog/linode/requests/compute/domain_create.rb b/lib/fog/linode/requests/compute/domain_create.rb index 36620dc6e..2bde9396e 100644 --- a/lib/fog/linode/requests/compute/domain_create.rb +++ b/lib/fog/linode/requests/compute/domain_create.rb @@ -42,7 +42,7 @@ module Fog class Mock - def linode_create(datacenter_id, payment_term, plan_id) + def domain_create( domain, type, options ={}) Fog::Mock.not_implemented end diff --git a/lib/fog/linode/requests/compute/domain_delete.rb b/lib/fog/linode/requests/compute/domain_delete.rb index 5c3d0d032..06feccb34 100644 --- a/lib/fog/linode/requests/compute/domain_delete.rb +++ b/lib/fog/linode/requests/compute/domain_delete.rb @@ -25,7 +25,7 @@ module Fog class Mock - def linode_delete(linode_id, options={}) + def domain_delete(domain_id) Fog::Mock.not_implemented end diff --git a/lib/fog/linode/requests/compute/domain_list.rb b/lib/fog/linode/requests/compute/domain_list.rb index 8ea08357b..b2d037dd7 100644 --- a/lib/fog/linode/requests/compute/domain_list.rb +++ b/lib/fog/linode/requests/compute/domain_list.rb @@ -40,7 +40,7 @@ module Fog class Mock - def avail_kernels(options={}) + def domain_list(domain_id = nil) Fog::Mock.not_implemented end diff --git a/lib/fog/linode/requests/compute/domain_resource_create.rb b/lib/fog/linode/requests/compute/domain_resource_create.rb new file mode 100644 index 000000000..e6e34ea7a --- /dev/null +++ b/lib/fog/linode/requests/compute/domain_resource_create.rb @@ -0,0 +1,53 @@ +module Fog + module Linode + class Compute + class Real + + # Creates a resource record in a domain + # + # ==== Parameters + # * domain_id<~Integer>: limit the list to the domain ID specified + # * type<~String>: One of: NS, MX, A, AAAA, CNAME, TXT, or SRV + # * 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. + # 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 + # * 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 + # * ttl_sec<~Integer>: default: 0 + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + # * DATA<~Hash>: + # * 'ResourceID'<~Integer>: ID of the resource record created + def domain_resource_create( domain_id, type, options = {}) + + query= {} + request( + :expects => 200, + :method => 'GET', + :query => { + :api_action => 'domain.resource.create', + :domainID => domain_id, + :type => type + }.merge!( options) + ) + end + + end + + class Mock + + def domain_resource_create( domain_id, type, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/linode/requests/compute/domain_resource_delete.rb b/lib/fog/linode/requests/compute/domain_resource_delete.rb new file mode 100644 index 000000000..27846a4d2 --- /dev/null +++ b/lib/fog/linode/requests/compute/domain_resource_delete.rb @@ -0,0 +1,36 @@ +module Fog + module Linode + class Compute + class Real + + # Delete the given resource from a domain + # + # ==== Parameters + # * domain_id<~Integer>: id of domain resource belongs to + # * resource_id<~Integer>: id of resouce to delete + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + # * DATA<~Hash>: + # * resource_id<~Integer>: resource id that was deleted + def domain_resource_delete(domain_id, resource_id) + request( + :expects => 200, + :method => 'GET', + :query => { :api_action => 'domain.resource.delete', :domainId => domain_id, :resourceID => resource_id } + ) + end + + end + + class Mock + + def domain_resource_delete(domain_id, resource_id) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/linode/requests/compute/domain_resource_list.rb b/lib/fog/linode/requests/compute/domain_resource_list.rb new file mode 100644 index 000000000..3962627e6 --- /dev/null +++ b/lib/fog/linode/requests/compute/domain_resource_list.rb @@ -0,0 +1,48 @@ +module Fog + module Linode + class Compute + class Real + + # List of resource records for a domain + # + # ==== Parameters + # * domain_id<~Integer>: limit the list to the domain ID specified + # * resource_id<~Integer>: optional. use if want only a specific resource record + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Array>: + # * DATA<~Array> + # * 'PROTOCOL'<~String>: for SRV records. default is UDP + # * 'TTL_SEC'<~Interger>: + # * 'PRIORITY'<~Interger>: for MX and SRV records + # * 'TYPE'<~String>: One of: NS, MX, A, AAAA, CNAME, TXT, or SRV + # * '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. + # * 'WEIGHT'<~Interger>: + # * 'RESOURCEID'<~Interger>: ID of the resource record + # * 'PORT'<~Interger>: + # * '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) + + request( + :expects => 200, + :method => 'GET', + :query => { :api_action => 'domain.resource.list', :domainID => domain_id, :resourceID => resource_id } + ) + end + + end + + class Mock + + def domain_resource_list(domain_id, resource_id = nil) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/linode/requests/compute/domain_resource_update.rb b/lib/fog/linode/requests/compute/domain_resource_update.rb new file mode 100644 index 000000000..8fa2adb8a --- /dev/null +++ b/lib/fog/linode/requests/compute/domain_resource_update.rb @@ -0,0 +1,54 @@ +module Fog + module Linode + class Compute + class Real + + # Updates a resource record in a domain + # + # ==== Parameters + # * domain_id<~Integer>: limit the list to the domain ID specified + # * resource_id<~Integer>: id of resouce to delete + # * options<~Hash> + # * type<~String>: One of: NS, MX, A, AAAA, CNAME, TXT, or SRV + # * name<~String>: The hostname or FQDN. When Type=MX the subdomain to delegate to the + # Target MX server + # * 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 + # * 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 + # * ttl_sec<~Integer>: default: 0 + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + # * DATA<~Hash>: + # * 'ResourceID'<~Integer>: ID of the resource record updated + def domain_resource_update( domain_id, resource_id, options = {}) + + query= {} + request( + :expects => 200, + :method => 'GET', + :query => { + :api_action => 'domain.resource.update', + :domainID => domain_id, + :resourceID => resource_id, + }.merge!( options) + ) + end + + end + + class Mock + + def domain_resource_update( domain_id, resource_id, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/linode/requests/compute/domain_update.rb b/lib/fog/linode/requests/compute/domain_update.rb new file mode 100644 index 000000000..f39eed983 --- /dev/null +++ b/lib/fog/linode/requests/compute/domain_update.rb @@ -0,0 +1,52 @@ +module Fog + module Linode + class Compute + class Real + + # Update a domain record + # + # ==== Parameters + # * domain_id<~Integer>: The ID to identify the zone + # * options<~Hash> + # * domain<~String>: The zone's name. + # * type<~String>: master or slave + # * description<~String> Currently undisplayed + # * SOA_email<~String> Required when type=master + # * refresh_sec<~Integer> numeric, default: '0' + # * retry_sec<~Integer> numeric, default: '0' + # * expire_sec<~Integer> numeric, default: '0' + # * ttl_sec<~String> 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 + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + # * DATA<~Hash>: + # * 'DomainID'<~Integer>: domain ID + def domain_update( domain_id, options = {}) + + query= {} + request( + :expects => 200, + :method => 'GET', + :query => { + :api_action => 'domain.update', + :domain => domain, + :type => type + }.merge!( options) + ) + end + + end + + class Mock + + def domain_update(datacenter_id, payment_term, plan_id) + Fog::Mock.not_implemented + end + + end + end + end +end