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

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
This commit is contained in:
Athir Nuaimi 2010-12-11 11:32:41 -05:00
parent 814aec89d8
commit 9d2c9ff74c
10 changed files with 297 additions and 18 deletions

View file

@ -16,10 +16,46 @@ def show_linode_dns_usage( api_key)
end
begin
#connect to Linode
options = { :linode_api_key => api_key }
cloud= Fog::Linode::Compute.new( options)
# will add samples once finished adding linode DNS API to fog
#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
#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
@ -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

View file

@ -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

View file

@ -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

View file

@ -25,7 +25,7 @@ module Fog
class Mock
def linode_delete(linode_id, options={})
def domain_delete(domain_id)
Fog::Mock.not_implemented
end

View file

@ -40,7 +40,7 @@ module Fog
class Mock
def avail_kernels(options={})
def domain_list(domain_id = nil)
Fog::Mock.not_implemented
end

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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