# File lib/fog/slicehost/dns.rb, line 56 def initialize(options={}) require 'fog/core/parser' @slicehost_password = options[:slicehost_password] @connection_options = options[:connection_options] || {} @host = options[:host] || "api.slicehost.com" @persistent = options[:persistent] || false @port = options[:port] || 443 @scheme = options[:scheme] || 'https' @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end
Create a new record in a DNS zone - or update an existing one
record_type<~String> - type of DNS record to create (A, CNAME, etc)
zone_id<~Integer> - ID of the zone to update
name<~String> - host name this DNS record is for
data<~String> - data for the DNS record (ie for an A record, the IP address)
options<~Hash> - extra parameters that are not mandatory
ttl<~Integer> - time to live in seconds
active<~String> - whether this record is active or not ('Y' or 'N')
aux<~String> - extra data required by the record
response<~Excon::Response>:
body<~Hash>:
'name'<~String> - as above
'id'<~Integer> - Id of zone/domain - used in future API calls for this zone
'ttl'<~Integer> - as above
'data'<~String> - as above
'active'<~String> - as above
'aux'<~String> - as above
# File lib/fog/slicehost/requests/dns/create_record.rb, line 27 def create_record(record_type, zone_id, name, data, options = {}) optional_tags= '' options.each { |option, value| case option when :ttl optional_tags+= "<ttl type='integer'>#{value}</ttl>" when :active optional_tags+= "<active>#{value}</active>" when :aux optional_tags+= "<aux>#{value}</aux>" end } request( :body => %Q{<?xml version="1.0" encoding="UTF-8"?><record><record_type>#{record_type}</record_type><zone_id type="integer">#{zone_id}</zone_id><name>#{name}</name><data>#{data}</data>#{optional_tags}</record>}, :expects => 201, :method => 'POST', :parser => Fog::Parsers::DNS::Slicehost::CreateRecord.new, :path => 'records.xml' ) end
Create a new zone for Slicehost's DNS servers to serve/host
origin<~String> - domain name to host (ie example.com)
options<~Hash> - optional paramaters
response<~Excon::Response>:
body<~Hash>:
'origin'<~String> - as above
'id'<~Integer> - Id of zone/domain - used in future API calls
'ttl'<~Integer> - as above
'active'<~String> - as above
# File lib/fog/slicehost/requests/dns/create_zone.rb, line 22 def create_zone(origin, options = {}) optional_tags= '' options.each { |option, value| case option when :ttl optional_tags+= "<ttl type='interger'>#{value}</ttl>" when :active optional_tags+= "<active>#{value}</active>" end } request( :body => %Q{<?xml version="1.0" encoding="UTF-8"?><zone><origin>#{origin}</origin>#{optional_tags}</zone>}, :expects => 201, :method => 'POST', :parser => Fog::Parsers::DNS::Slicehost::CreateZone.new, :path => 'zones.xml' ) end
Delete a record from the specified DNS zone
record_id<~Integer> - Id of DNS record to delete
response<~Excon::Response>: - HTTP status code will be result
# File lib/fog/slicehost/requests/dns/delete_record.rb, line 12 def delete_record(record_id) request( :expects => 200, :method => 'DELETE', :path => "records/#{record_id}.xml" ) end
Delete a zone from Slicehost's DNS
zone_id<~Integer> - Id of zone to delete
response<~Excon::Response>: - HTTP status code will be result
# File lib/fog/slicehost/requests/dns/delete_zone.rb, line 12 def delete_zone(zone_id) request( :expects => 200, :method => 'DELETE', :path => "zones/#{zone_id}.xml" ) end
Get an individual DNS record from the specified zone
response<~Excon::Response>:
body<~Hash>:
'record_type'<~String> - type of DNS record to create (A, CNAME, etc)
'zone_id'<~Integer> - ID of the zone to update
'name'<~String> - host name this DNS record is for
'data'<~String> - data for the DNS record (ie for an A record, the IP address)
'ttl'<~Integer> - time to live in seconds
'active'<~String> - whether this record is active or not ('Y' or 'N')
'aux'<~String> - extra data required by the record
# File lib/fog/slicehost/requests/dns/get_record.rb, line 20 def get_record(record_id) request( :expects => 200, :method => 'GET', :parser => Fog::Parsers::DNS::Slicehost::GetRecord.new, :path => "records/#{record_id}.xml" ) end
Get all the DNS records across all the DNS zones for this account
response<~Excon::Response>:
body<~Array>:
'name'<~String> - Record NAME field (e.g. "example.org." or "www")
'data'<~String> - Data contained by the record (e.g. an IP address, for A records)
'record_type'<~String> - Type of record (A, CNAME, TXT, etc)
'aux'<~String> - Aux data for the record, for those types which have it (e.g. TXT)
'zone_id'<~Integer> - zone ID to which this record belongs
'active'<~String> - whether this record is active in the Slicehost DNS (Y for yes, N for no)
'ttl'<~Integer> - TTL in seconds
# File lib/fog/slicehost/requests/dns/get_records.rb, line 20 def get_records request( :expects => 200, :method => 'GET', :parser => Fog::Parsers::DNS::Slicehost::GetRecords.new, :path => "records.xml" ) end
Get details of a DNS zone
zone_id<~Integer> - Id of zone to lookup
response<~Excon::Response>:
# File lib/fog/slicehost/requests/dns/get_zone.rb, line 20 def get_zone(zone_id) request( :expects => 200, :method => 'GET', :parser => Fog::Parsers::DNS::Slicehost::GetZone.new, :path => "/zones/#{zone_id}.xml" ) end
Get list of all DNS zones hosted on Slicehost (for this account)
response<~Excon::Response>:
# File lib/fog/slicehost/requests/dns/get_zones.rb, line 18 def get_zones request( :expects => 200, :method => 'GET', :parser => Fog::Parsers::DNS::Slicehost::GetZones.new, :path => 'zones.xml' ) end
# File lib/fog/slicehost/dns.rb, line 68 def reload @connection.reset end
# File lib/fog/slicehost/dns.rb, line 72 def request(params) params[:headers] ||= {} params[:headers].merge!({ 'Authorization' => "Basic #{Base64.encode64(@slicehost_password).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::Slicehost::NotFound.slurp(error) else error end end response end
Get an individual DNS record from the specified zone
response<~Excon::Response>:
body<~Hash>:
'record_type'<~String> - type of DNS record to create (A, CNAME, etc)
'zone_id'<~Integer> - ID of the zone to update
'name'<~String> - host name this DNS record is for
'data'<~String> - data for the DNS record (ie for an A record, the IP address)
'ttl'<~Integer> - time to live in seconds
'active'<~String> - whether this record is active or not ('Y' or 'N')
'aux'<~String> - extra data required by the record
# File lib/fog/slicehost/requests/dns/update_record.rb, line 20 def update_record(record_id, record_type, zone_id, name, data, options = {}) optional_tags= '' options.each { |option, value| case option when :ttl optional_tags+= "<ttl type='integer'>#{value}</ttl>" when :active optional_tags+= "<active>#{value}</active>" when :aux optional_tags+= "<aux>#{value}</aux>" end } request( :body => %Q{<?xml version="1.0" encoding="UTF-8"?><record><record_type>#{record_type}</record_type><zone_id type="integer">#{zone_id}</zone_id><name>#{name}</name><data>#{data}</data>#{optional_tags}</record>}, :expects => 200, :method => 'PUT', :path => "records/#{record_id}.xml" ) end