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:
parent
909d062d89
commit
78b8d4a125
4 changed files with 148 additions and 6 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)
|
|
@ -14,7 +14,7 @@ module Fog
|
||||||
request :avail_linodeplans
|
request :avail_linodeplans
|
||||||
request :avail_stackscripts
|
request :avail_stackscripts
|
||||||
request :domain_create
|
request :domain_create
|
||||||
# request :domain_delete
|
request :domain_delete
|
||||||
request :domain_list
|
request :domain_list
|
||||||
# request :domain_update
|
# request :domain_update
|
||||||
# request :domain_resource_create
|
# request :domain_resource_create
|
||||||
|
|
|
@ -6,7 +6,8 @@ module Fog
|
||||||
# Creates a domain record
|
# Creates a domain record
|
||||||
#
|
#
|
||||||
# ==== Parameters
|
# ==== 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
|
# * type<~String>: master or slave
|
||||||
# * options<~Hash>
|
# * options<~Hash>
|
||||||
# * description<~String> Currently undisplayed
|
# * description<~String> Currently undisplayed
|
||||||
|
@ -20,9 +21,12 @@ module Fog
|
||||||
#
|
#
|
||||||
# ==== Returns
|
# ==== Returns
|
||||||
# * response<~Excon::Response>:
|
# * response<~Excon::Response>:
|
||||||
# * body<~Array>:
|
# * body<~Hash>:
|
||||||
# TODO: docs
|
# * DATA<~Hash>:
|
||||||
def domain_create( domain, type, options)
|
# * 'DomainID'<~Integer>: domain ID
|
||||||
|
def domain_create( domain, type, options = {})
|
||||||
|
|
||||||
|
query= {}
|
||||||
request(
|
request(
|
||||||
:expects => 200,
|
:expects => 200,
|
||||||
:method => 'GET',
|
:method => 'GET',
|
||||||
|
@ -30,7 +34,7 @@ module Fog
|
||||||
:api_action => 'domain.create',
|
:api_action => 'domain.create',
|
||||||
:domain => domain,
|
:domain => domain,
|
||||||
:type => type
|
:type => type
|
||||||
}
|
}.merge!( options)
|
||||||
)
|
)
|
||||||
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
|
Loading…
Reference in a new issue