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

can now create DNS zones on linode

added support for domain.create method.
continuing work to support rest of DNS zone methods
added a sample in examples directory.  Right now includes code for slicehost.  will add linode once API fully supported
This commit is contained in:
Athir Nuaimi 2010-12-10 17:33:36 -05:00
parent 909d062d89
commit 78b8d4a125
4 changed files with 148 additions and 6 deletions

103
examples/dns_methods.rb Normal file
View file

@ -0,0 +1,103 @@
#!/usr/bin/env ruby
require 'rubygems'
# require 'fog'
require '/Users/anuaimi/code/fog/lib/fog'
LINODE_API_KEY = '--put-your-key-here--'
SLICEHOST_PASSWORD = '--put-your-key-here--'
# example of how to use Linode DNS calls
def show_linode_dns_usage( api_key)
if api_key == '--put-your-key-here--'
return false
end
begin
options = { :linode_api_key => api_key }
cloud= Fog::Linode::Compute.new( options)
# will add samples once finished adding linode DNS API to fog
rescue
#opps, ran into a problem
puts $!.message
return false
end
true
end
# example of how to use Slicehost DNS calls
def show_slicehost_dns_usage( password)
#check if we have a value api key for this cloud
if password == '--put-your-key-here--'
return false
end
begin
#connect to Slicehost
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' }
response= cloud.create_zone( "sample-domain.com", options)
if response.status == 200
zone_id= response.body['id']
end
#add an A record for website
record_id = 0
options = { :ttl => 3600, :active => 'N' }
response= cloud.create_record( 'A', 159631, "www.sample-domain.com", "1.2.3.4", options)
if response.status == 200
record_id= response.body['id']
end
#now get details on zone and A record for www
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"
end
end
#finally cleanup by deleting the zone we created
if zoned_id > 0
response = cloud.delete_zone( zone_id)
if response.status == 200
puts "sample-domain.com removed from Slicehost DNS"
end
end
rescue
#opps, ran into a problem
puts $!.message
return false
end
true
end
######################################
# note, if you have not added your key for a given provider, the related function will do nothing
show_linode_dns_usage( LINODE_API_KEY)
show_slicehost_dns_usage( SLICEHOST_PASSWORD)

View file

@ -14,7 +14,7 @@ module Fog
request :avail_linodeplans
request :avail_stackscripts
request :domain_create
# request :domain_delete
request :domain_delete
request :domain_list
# request :domain_update
# request :domain_resource_create

View file

@ -6,7 +6,8 @@ module Fog
# Creates a domain record
#
# ==== Parameters
# * domain<~String>: The zone's name
# * domain<~String>: The zone's name. Note, if master zone, SOA_email is required and if slave
# master_ips is/are required
# * type<~String>: master or slave
# * options<~Hash>
# * description<~String> Currently undisplayed
@ -20,9 +21,12 @@ module Fog
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def domain_create( domain, type, options)
# * body<~Hash>:
# * DATA<~Hash>:
# * 'DomainID'<~Integer>: domain ID
def domain_create( domain, type, options = {})
query= {}
request(
:expects => 200,
:method => 'GET',
@ -30,7 +34,7 @@ module Fog
:api_action => 'domain.create',
:domain => domain,
:type => type
}
}.merge!( options)
)
end

View file

@ -0,0 +1,35 @@
module Fog
module Linode
class Compute
class Real
# Delete the given domain from the list Linode hosts
#
# ==== Parameters
# * domain_id<~Integer>: id of domain to delete
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * DATA<~Hash>:
# TODO: docs
def domain_delete(domain_id)
request(
:expects => 200,
:method => 'GET',
:query => { :api_action => 'domain.delete', :domainId => domain_id }
)
end
end
class Mock
def linode_delete(linode_id, options={})
Fog::Mock.not_implemented
end
end
end
end
end