mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
add support for linode domain.list method
linode has a full API to support managed DNS. Have the 1st call, domain.list working method also support option parameter to narrow results to a single domain 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:
parent
41ab3c2229
commit
814aec89d8
5 changed files with 252 additions and 0 deletions
103
examples/dns_methods.rb
Normal file
103
examples/dns_methods.rb
Normal 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)
|
|
@ -13,10 +13,22 @@ module Fog
|
|||
request :avail_kernels
|
||||
request :avail_linodeplans
|
||||
request :avail_stackscripts
|
||||
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_resource_update
|
||||
# request :linode_boot
|
||||
request :linode_create
|
||||
request :linode_delete
|
||||
request :linode_list
|
||||
request :linode_reboot
|
||||
# request :linode_resize
|
||||
# request :linode_shutdown
|
||||
# request :linode_update
|
||||
|
||||
class Mock
|
||||
|
||||
|
|
52
lib/fog/linode/requests/compute/domain_create.rb
Normal file
52
lib/fog/linode/requests/compute/domain_create.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
module Fog
|
||||
module Linode
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
# Creates a domain record
|
||||
#
|
||||
# ==== Parameters
|
||||
# * 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
|
||||
# * 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_create( domain, type, options = {})
|
||||
|
||||
query= {}
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:query => {
|
||||
:api_action => 'domain.create',
|
||||
:domain => domain,
|
||||
:type => type
|
||||
}.merge!( options)
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def linode_create(datacenter_id, payment_term, plan_id)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
35
lib/fog/linode/requests/compute/domain_delete.rb
Normal file
35
lib/fog/linode/requests/compute/domain_delete.rb
Normal 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
|
50
lib/fog/linode/requests/compute/domain_list.rb
Normal file
50
lib/fog/linode/requests/compute/domain_list.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
module Fog
|
||||
module Linode
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
# List of domains (you have access to)
|
||||
#
|
||||
# ==== Parameters
|
||||
# * domain_id<~Integer>: limit the list to the domain ID specified
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>:
|
||||
# * DATA<~Array>
|
||||
# * 'DOMAINID'<~Interger>
|
||||
# * 'SOA_EMAIL'<~String>
|
||||
# * 'DESCRIPTION'<~String>
|
||||
# * 'TTL_SEC'<~String>
|
||||
# * 'EXPIRE_SEC'<~Integer>
|
||||
# * 'RETRY_SEC'<~Integer>
|
||||
# * 'DOMAIN'<~String>
|
||||
# * 'STATUS'<~Integer>
|
||||
# * 'MASTER_IPS'<~String>
|
||||
# * 'REFRESH_SEC'<~Integer>
|
||||
# * 'TYPE'<~String>
|
||||
def domain_list(domain_id = nil)
|
||||
options = {}
|
||||
if domain_id
|
||||
options.merge!(:domainId => domain_id)
|
||||
end
|
||||
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:query => { :api_action => 'domain.list' }.merge!(options)
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def avail_kernels(options={})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue