Class: Fog::DNS::Zerigo::Real
- Inherits:
-
Object
- Object
- Fog::DNS::Zerigo::Real
- Defined in:
- lib/fog/zerigo/dns.rb,
lib/fog/zerigo/requests/dns/get_host.rb,
lib/fog/zerigo/requests/dns/get_zone.rb,
lib/fog/zerigo/requests/dns/find_hosts.rb,
lib/fog/zerigo/requests/dns/list_hosts.rb,
lib/fog/zerigo/requests/dns/list_zones.rb,
lib/fog/zerigo/requests/dns/count_hosts.rb,
lib/fog/zerigo/requests/dns/count_zones.rb,
lib/fog/zerigo/requests/dns/create_host.rb,
lib/fog/zerigo/requests/dns/create_zone.rb,
lib/fog/zerigo/requests/dns/delete_host.rb,
lib/fog/zerigo/requests/dns/delete_zone.rb,
lib/fog/zerigo/requests/dns/update_host.rb,
lib/fog/zerigo/requests/dns/update_zone.rb,
lib/fog/zerigo/requests/dns/get_zone_stats.rb
Instance Method Summary collapse
-
#count_hosts(zone_id) ⇒ Object
total number of hosts available for the specified zone.
-
#count_zones ⇒ Object
Total number of zones hosted Zerigo for this account.
-
#create_host(zone_id, host_type, data, options = {}) ⇒ Object
Create a new host in the specified zone.
-
#create_zone(domain, default_ttl, ns_type, options = {}) ⇒ Object
Create a new zone for Zerigo’s DNS servers to serve/host ==== Parameters.
-
#delete_host(host_id) ⇒ Object
Delete a host record .
-
#delete_zone(zone_id) ⇒ Object
Delete a zone from Zerigo.
-
#find_hosts(fqdn, zone_id = nil) ⇒ Object
Get list of all the host records that match the FQDN.
-
#get_host(host_id) ⇒ Object
get details about a given host record.
-
#get_zone(zone_id_or_domain) ⇒ Object
Get details of a DNS zone.
-
#get_zone_stats(zone_id) ⇒ Object
returns current traffic statistics about this zone.
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
-
#list_hosts(zone_id) ⇒ Object
Get list of all DNS zones hosted on Slicehost (for this account).
-
#list_zones(options = {}) ⇒ Object
Get list of all DNS zones hosted on Slicehost (for this account).
- #reload ⇒ Object
- #request(params) ⇒ Object
-
#update_host(host_id, options = {}) ⇒ Object
Update a host record.
-
#update_zone(zone_id, options = {}) ⇒ Object
Update the parameters of a zone ==== Parameters.
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/fog/zerigo/dns.rb', line 73 def initialize(={}) require 'fog/core/parser' @zerigo_email = [:zerigo_email] @zerigo_token = [:zerigo_token] @connection_options = [:connection_options] || {} @host = [:host] || "ns.zerigo.com" @persistent = [:persistent] || false @port = [:port] || 80 @scheme = [:scheme] || 'http' @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end |
Instance Method Details
#count_hosts(zone_id) ⇒ Object
total number of hosts available for the specified zone. It is the same value as provided in the X-Query-Count header in the list_hosts API method
Returns
-
response<~Excon::Response>:
-
body<~Hash>
-
‘count’<~Integer>
-
-
‘status’<~Integer> - 200 indicates success
-
16 17 18 19 20 21 22 23 |
# File 'lib/fog/zerigo/requests/dns/count_hosts.rb', line 16 def count_hosts(zone_id) request( :expects => 200, :method => 'GET', :parser => Fog::Parsers::DNS::Zerigo::CountHosts.new, :path => "/api/1.1/zones/#{zone_id}/hosts/count.xml" ) end |
#count_zones ⇒ Object
Total number of zones hosted Zerigo for this account. It is the same value as provided in the X-Query-Count header in the list_zones API method
Returns
-
response<~Excon::Response>:
-
body<~Hash>
-
‘count’<~Integer>
-
-
‘status’<~Integer> - 200 indicates success
-
16 17 18 19 20 21 22 23 |
# File 'lib/fog/zerigo/requests/dns/count_zones.rb', line 16 def count_zones request( :expects => 200, :method => 'GET', :parser => Fog::Parsers::DNS::Zerigo::CountZones.new, :path => "/api/1.1/zones/count.xml" ) end |
#create_host(zone_id, host_type, data, options = {}) ⇒ Object
Create a new host in the specified zone
Parameters
-
zone_id<~Integer>
-
host_type<~String>
-
data<~String>
-
options<~Hash> - optional parameters
-
hostname<~String> - Note: normally this is set/required!!
-
notes<~String>
-
priority<~Integer> - Note: required for MX or SRV records
-
ttl<~Integer>
-
Returns
-
response<~Excon::Response>:
-
body<~Hash>
-
‘created-at’<~String>
-
‘data’<~String>
-
‘fqdn’<~String>
-
‘host-type’<~String>
-
‘hostname’<~String>
-
‘id’<~Integer>
-
‘notes’<~String>
-
‘priority’<~Integer>
-
‘ttl’<~Integer>
-
‘updated-at’<~String>
-
‘zone-id’<~String>
-
-
‘status’<~Integer> - 201 if successful
-
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fog/zerigo/requests/dns/create_host.rb', line 34 def create_host(zone_id, host_type, data, = {}) = '' .each { |option, value| case option when :hostname += "<hostname>#{value}</hostname>" when :notes += "<notes>#{value}</notes>" when :priority += "<priority>#{value}</priority>" when :ttl += "<ttl>#{value}</ttl>" end } request( :body => %Q{<?xml version="1.0" encoding="UTF-8"?><host><host-type>#{host_type}</host-type><data>#{data}</data>#{}</host>}, :expects => 201, :method => 'POST', :parser => Fog::Parsers::DNS::Zerigo::CreateHost.new, :path => "/api/1.1/zones/#{zone_id}/hosts.xml" ) end |
#create_zone(domain, default_ttl, ns_type, options = {}) ⇒ Object
Create a new zone for Zerigo’s DNS servers to serve/host
Parameters
-
domain<~String>
-
default_ttl<~Integer>
-
ns_type<~String>
-
options<~Hash> - optional paramaters
-
ns1<~String> - required if ns_type == sec
-
nx_ttl<~Integer> -
-
slave_nameservers<~String> - required if ns_type == pri
-
axfr_ips<~String> - comma-separated list of IPs or IP blocks allowed to perform AXFRs
-
custom_nameservers<~String> - comma-separated list of custom nameservers
-
custom_ns<~String> - indicates if vanity (custom) nameservers are enabled for this domain
-
hostmaster<~String> - email of the DNS administrator or hostmaster
-
notes<~String> - notes about the domain
-
restrict_axfr<~String> - indicates if AXFR transfers should be restricted to IPs in axfr-ips
-
tag_list<~String> - List of all tags associated with this domain
-
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘id’<~Integer> - zone ID to use for future calls
-
‘default-ttl’<~Integer>
-
‘nx-ttl’<~Integer>
-
‘hosts-count’<~Integer>
-
‘created-at’<~String>
-
‘custom-nameservers’<~String>
-
‘custom-ns’<~String>
-
‘domain’<~String>
-
‘hostmaster’<~String>
-
‘notes’<~String>
-
‘ns1’<~String>
-
‘ns-type’<~String>
-
‘slave-nameservers’<~String>
-
‘tag-list’<~String>
-
‘updated-at’<~String>
-
‘hosts’<~String>
-
‘axfr-ips’<~String>
-
‘restrict-axfr’<~String>
-
-
‘status’<~Integer> - 201 if successful
-
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/fog/zerigo/requests/dns/create_zone.rb', line 49 def create_zone(domain, default_ttl, ns_type, = {}) = '' .each { |option, value| case option when :ns1 += "<ns1>#{value}</ns1>" when :nx_ttl += "<nx-ttl type='interger'>#{value}</nx-ttl>" when :slave_nameservers += "<slave-nameservers>#{value}</slave-nameservers>" when :axfr_ips += "<axfr-ips>#{value}</axfr-ips>" when :custom_nameservers += "<custom-nameservers>#{value}</custom-nameservers>" when :custom_ns += "<custom-ns>#{value}</custom-ns>" when :hostmaster += "<hostmaster>#{value}</hostmaster>" when :notes += "<notes>#{value}</notes>" when :restrict_axfr += "<restrict-axfr>#{value}</restrict-axfr>" when :tag_list += "<tag-list>#{value}</tag-list>" end } request( :body => %Q{<?xml version="1.0" encoding="UTF-8"?><zone><domain>#{domain}</domain><default-ttl type="integer">#{default_ttl}</default-ttl><ns-type>#{ns_type}</ns-type>#{}</zone>}, :expects => 201, :method => 'POST', :parser => Fog::Parsers::DNS::Zerigo::CreateZone.new, :path => '/api/1.1/zones.xml' ) end |
#delete_host(host_id) ⇒ Object
Delete a host record
Parameters
-
host_id<~Integer> - Id of host record to delete
Returns
-
response<~Excon::Response>:
-
‘status’<~Integer> - 200 indicates success
-
13 14 15 16 17 18 19 |
# File 'lib/fog/zerigo/requests/dns/delete_host.rb', line 13 def delete_host(host_id) request( :expects => 200, :method => 'DELETE', :path => "/api/1.1/hosts/#{host_id}.xml" ) end |
#delete_zone(zone_id) ⇒ Object
Delete a zone from Zerigo
Parameters
-
zone_id<~Integer> - Id of zone to delete
Returns
-
response<~Excon::Response>:
-
‘status’<~Integer> - 200 indicates success
-
14 15 16 17 18 19 20 |
# File 'lib/fog/zerigo/requests/dns/delete_zone.rb', line 14 def delete_zone(zone_id) request( :expects => 200, :method => 'DELETE', :path => "/api/1.1/zones/#{zone_id}.xml" ) end |
#find_hosts(fqdn, zone_id = nil) ⇒ Object
Get list of all the host records that match the FQDN. If desired, can limit search to a specific zone
Parameters
-
fqdn<~String> - domain to look for
-
zone_id<~Integer> - if want to limit search to specific zone
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘hosts’<~Hash>
-
‘created-at’<~String>
-
‘data’<~String>
-
‘fqdn’<~String>
-
‘host-type’<~String>
-
‘hostname’<~String>
-
‘id’<~Integer>
-
‘notes’<~String>
-
‘priority’<~Integer>
-
‘ttl’<~Integer>
-
‘updated-at’<~String>
-
‘zone-id’<~String>
-
-
-
‘status’<~Integer> - 200 indicated success
-
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fog/zerigo/requests/dns/find_hosts.rb', line 32 def find_hosts(fqdn, zone_id = nil) if zone_id.nil? #look for matching host across all zones request( :expects => 200, :method => 'GET', :parser => Fog::Parsers::DNS::Zerigo::FindHosts.new, :path => "/api/1.1/hosts.xml?fqdn=#{fqdn}" ) else #look for hosts in a specific zone request( :expects => 200, :method => 'GET', :parser => Fog::Parsers::DNS::Zerigo::FindHosts.new, :path => "/api/1.1/zones/#{zone_id}/hosts.xml?fqdn=#{fqdn}" ) end end |
#get_host(host_id) ⇒ Object
get details about a given host record
Parameters
-
host_id<~Integer> - ID of the host record to retrieve
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘created-at’<~String>
-
‘data’<~String>
-
‘fqdn’<~String>
-
‘host-type’<~String>
-
‘hostname’<~String>
-
‘id’<~Integer>
-
‘notes’<~String>
-
‘priority’<~Integer>
-
‘ttl’<~Integer>
-
‘updated-at’<~String>
-
‘zone-id’<~String>
-
-
‘status’<~Integer> - 200 indicates success
-
27 28 29 30 31 32 33 34 |
# File 'lib/fog/zerigo/requests/dns/get_host.rb', line 27 def get_host(host_id) request( :expects => 200, :method => 'GET', :parser => Fog::Parsers::DNS::Zerigo::GetHost.new, :path => "/api/1.1/hosts/#{host_id}.xml" ) end |
#get_zone(zone_id_or_domain) ⇒ Object
Get details of a DNS zone. The response is similar to list_zones, with the addition of hosts-count and possibly hosts.
Parameters
-
zone<~String> - Either the zone ID or the zone name (ie sample-domain.com)
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘default-ttl’<~Integer>
-
‘id’<~Integer>
-
‘nx-ttl’<~Integer>
-
‘hosts-count’<~Integer>
-
‘created-at’<~String>
-
‘custom-nameservers’<~String>
-
‘custom-ns’<~String>
-
‘domain’<~String>
-
‘hostmaster’<~String>
-
‘notes’<~String>
-
‘ns1’<~String>
-
‘ns-type’<~String>
-
‘slave-nameservers’<~String>
-
‘tag-list’<~String>
-
‘updated-at’<~String>
-
‘hosts’<~Array> - a list of all host records. For the format of host info, see get_host()
-
‘axfr-ips’<~String>
-
‘restrict-axfr’<~String>
-
-
‘status’<~Integer> - 200 indicates success
-
37 38 39 40 41 42 43 44 |
# File 'lib/fog/zerigo/requests/dns/get_zone.rb', line 37 def get_zone(zone_id_or_domain) request( :expects => 200, :method => 'GET', :parser => Fog::Parsers::DNS::Zerigo::GetZone.new, :path => "/api/1.1/zones/#{zone_id_or_domain}.xml" ) end |
#get_zone_stats(zone_id) ⇒ Object
returns current traffic statistics about this zone. Queries is measured from the beginning of the current period through the time of the API call.
Parameters
-
zone_id<~Integer> - the zone ID
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘domain’<~String> - domain name (ie example.com)
-
‘id’<~Integer> - Id of the zone
-
‘period-being’<~String> - date in following format 2010-07-01
-
‘period-end’<~String> - date
-
‘queries’<~Integer> - # of queries for the zone during period
-
-
‘status’<~Integer> - 200 indicates success
-
24 25 26 27 28 29 30 31 |
# File 'lib/fog/zerigo/requests/dns/get_zone_stats.rb', line 24 def get_zone_stats(zone_id) request( :expects => 200, :method => 'GET', :parser => Fog::Parsers::DNS::Zerigo::GetZoneStats.new, :path => "/api/1.1/zones/#{zone_id}/stats.xml" ) end |
#list_hosts(zone_id) ⇒ Object
Get list of all DNS zones hosted on Slicehost (for this account)
Parameters
-
zone_id<~Integer> - the zone ID of the zone from which to get the host records for
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘hosts’<~Array>
-
‘created-at’<~String>
-
‘data’<~String>
-
‘fqdn’<~String>
-
‘host-type’<~String>
-
‘hostname’<~String>
-
‘id’<~Integer>
-
‘notes’<~String>
-
‘priority’<~Integer>
-
‘ttl’<~Integer>
-
‘updated-at’<~String>
-
‘zone-id’<~String>
-
-
-
-
‘status’<~Integer> - 200 indicates success
28 29 30 31 32 33 34 35 |
# File 'lib/fog/zerigo/requests/dns/list_hosts.rb', line 28 def list_hosts(zone_id) request( :expects => 200, :method => 'GET', :parser => Fog::Parsers::DNS::Zerigo::ListHosts.new, :path => "/api/1.1/zones/#{zone_id}/hosts.xml" ) end |
#list_zones(options = {}) ⇒ Object
Get list of all DNS zones hosted on Slicehost (for this account)
Parameters
-
options<~Hash>
-
page<~Integer> - Indicates where to begin in your list of zones.
-
per_page<~Integer> - The maximum number of zones to be included in the response body
-
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘zones’<~Array>
-
‘default-ttl’<~Integer>
-
‘id’<~Integer>
-
‘nx-ttl’<~Integer>
-
‘hosts-count’<~Integer>
-
‘created-at’<~String>
-
‘custom-nameservers’<~String>
-
‘custom-ns’<~String>
-
‘domain’<~String>
-
‘hostmaster’<~String>
-
‘notes’<~String>
-
‘ns1’<~String>
-
‘ns-type’<~String>
-
‘slave-nameservers’<~String>
-
‘tag-list’<~String>
-
‘updated-at’<~String>
-
‘hosts’<~String>
-
‘axfr-ips’<~String>
-
‘restrict-axfr’<~String>
-
-
-
‘status’<~Integer> - 200 indicates success
-
38 39 40 41 42 43 44 45 46 |
# File 'lib/fog/zerigo/requests/dns/list_zones.rb', line 38 def list_zones( = {}) request( :query => , :expects => 200, :method => 'GET', :parser => Fog::Parsers::DNS::Zerigo::ListZones.new, :path => '/api/1.1/zones.xml' ) end |
#reload ⇒ Object
86 87 88 |
# File 'lib/fog/zerigo/dns.rb', line 86 def reload @connection.reset end |
#request(params) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/fog/zerigo/dns.rb', line 90 def request(params) params[:headers] ||= {} key= "#{@zerigo_email}:#{@zerigo_token}" params[:headers].merge!({ 'Authorization' => "Basic #{Base64.encode64(key).delete("\r\n")}" }) case params[:method] when 'DELETE', 'GET', 'HEAD' params[:headers]['Accept'] = 'application/xml' when 'POST', 'PUT' params[:headers]['Content-Type'] = 'application/xml' end begin response = @connection.request(params.merge!({:host => @host})) rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::DNS::Zerigo::NotFound.slurp(error) else error end end response end |
#update_host(host_id, options = {}) ⇒ Object
Update a host record
Parameters
-
host_id<~Integer> - host ID of the record to update
-
options<~Hash> - optional paramaters
-
host_type<~String>
-
data<~String>
-
hostname<~String> - Note: normally this is set/required!!
-
notes<~String>
-
priority<~Integer> - Note: required for MX or SRV records
-
ttl<~Integer>
-
Returns
-
response<~Excon::Response>:
-
‘status’<~Integer> - 200 for success
-
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fog/zerigo/requests/dns/update_host.rb', line 21 def update_host(host_id, = {}) = '' .each { |option, value| case option when :host_type += "<host-type>#{value}</host-type>" when :data += "<data>#{value}</data>" when :hostname += "<hostname>#{value}</hostname>" when :notes += "<notes>#{value}</notes>" when :priority += "<priority>#{value}</priority>" when :ttl += "<ttl>#{value}</ttl>" end } request( :body => %Q{<?xml version="1.0" encoding="UTF-8"?><host>#{}</host>}, :expects => 200, :method => 'PUT', :path => "/api/1.1/hosts/#{host_id}.xml" ) end |
#update_zone(zone_id, options = {}) ⇒ Object
Update the parameters of a zone
Parameters
-
zone_id<~Integer>
-
options<~Hash> - optional paramaters
-
default_ttl<~Integer>
-
ns_type<~String>
-
ns1<~String> - required if ns_type == sec
-
nx_ttl<~Integer> -
-
slave_nameservers<~String> - required if ns_type == pri
-
axfr_ips<~String> - comma-separated list of IPs or IP blocks allowed to perform AXFRs
-
custom_nameservers<~String> - comma-separated list of custom nameservers
-
custom_ns<~String> - indicates if vanity (custom) nameservers are enabled for this domain
-
hostmaster<~String> - email of the DNS administrator or hostmaster
-
notes<~String> - notes about the domain
-
restrict_axfr<~String> - indicates if AXFR transfers should be restricted to IPs in axfr-ips
-
tag_list<~String> - List of all tags associated with this domain
-
Returns
-
response<~Excon::Response>:
-
‘status’<~Integer> - 200 for success
-
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fog/zerigo/requests/dns/update_zone.rb', line 27 def update_zone(zone_id, = {}) = '' .each { |option, value| case option when :default_ttl += "<default-ttl>#{value}</default-ttl>" when :ns_type += "<ns-type>#{value}</ns-type>" when :ns1 += "<ns1>#{value}</ns1>" when :nx_ttl += "<nx-ttl type='interger'>#{value}</nx-ttl>" when :slave_nameservers += "<slave-nameservers>#{value}</slave-nameservers>" when :axfr_ips += "<axfr-ips>#{value}</axfr-ips>" when :custom_nameservers += "<custom-nameservers>#{value}</custom-nameservers>" when :custom_ns += "<custom-ns>#{value}</custom-ns>" when :hostmaster += "<hostmaster>#{value}</hostmaster>" when :notes += "<notes>#{value}</notes>" when :restrict_axfr += "<restrict-axfr>#{value}</restrict-axfr>" when :tag_list += "<tag-list>#{value}</tag-list>" end } request( :body => %Q{<?xml version="1.0" encoding="UTF-8"?><zone>#{}</zone>}, :expects => 200, :method => 'PUT', :path => "/api/1.1/zones/#{zone_id}.xml" ) end |