Class: Fog::DNS::Slicehost::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/slicehost/dns.rb,
lib/fog/slicehost/requests/dns/get_zone.rb,
lib/fog/slicehost/requests/dns/get_zones.rb,
lib/fog/slicehost/requests/dns/get_record.rb,
lib/fog/slicehost/requests/dns/create_zone.rb,
lib/fog/slicehost/requests/dns/delete_zone.rb,
lib/fog/slicehost/requests/dns/get_records.rb,
lib/fog/slicehost/requests/dns/create_record.rb,
lib/fog/slicehost/requests/dns/delete_record.rb,
lib/fog/slicehost/requests/dns/update_record.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



56
57
58
59
60
61
62
63
64
65
66
# 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

Instance Method Details

#create_record(record_type, zone_id, name, data, options = {}) ⇒ Object

Create a new record in a DNS zone - or update an existing one

Parameters

  • 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

Returns

  • 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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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_zone(origin, options = {}) ⇒ Object

Create a new zone for Slicehost’s DNS servers to serve/host

Parameters

  • origin<~String> - domain name to host (ie example.com)

  • options<~Hash> - optional paramaters

    • ttl<~Integer> - TimeToLive (ttl) for the domain, in seconds (> 60)

    • active<~String> - whether zone is active in Slicehost DNS server - ‘Y’ or ‘N’

Returns

  • 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



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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_record(record_id) ⇒ Object

Delete a record from the specified DNS zone

Parameters

  • record_id<~Integer> - Id of DNS record to delete

Returns

  • response<~Excon::Response>: - HTTP status code will be result



12
13
14
15
16
17
18
# 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_zone(zone_id) ⇒ Object

Delete a zone from Slicehost’s DNS

Parameters

  • zone_id<~Integer> - Id of zone to delete

Returns

  • response<~Excon::Response>: - HTTP status code will be result



12
13
14
15
16
17
18
# 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_record(record_id) ⇒ Object

Get an individual DNS record from the specified zone

Returns

  • 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



20
21
22
23
24
25
26
27
# 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_recordsObject

Get all the DNS records across all the DNS zones for this account

Returns

  • 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



20
21
22
23
24
25
26
27
# 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_zone(zone_id) ⇒ Object

Get details of a DNS zone

Parameters

  • zone_id<~Integer> - Id of zone to lookup

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘origin’<~String> - domain name to host (ie example.com)

      • ‘id’<~Integer> - Id of the zone

      • ‘ttl’<~Integer> - TimeToLive (ttl) for the domain, in seconds (> 60)

      • ‘active’<~String> - whether zone is active in Slicehost DNS server - ‘Y’ or ‘N’



20
21
22
23
24
25
26
27
# 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_zonesObject

Get list of all DNS zones hosted on Slicehost (for this account)

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘zones’<~Array>

        • ‘origin’<~String> - domain name to host (ie example.com)

        • ‘id’<~Integer> - Id of the zone

        • ‘ttl’<~Integer> - TimeToLive (ttl) for the domain, in seconds (> 60)

        • ‘active’<~String> - whether zone is active in Slicehost DNS server - ‘Y’ or ‘N’



18
19
20
21
22
23
24
25
# 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

#reloadObject



68
69
70
# File 'lib/fog/slicehost/dns.rb', line 68

def reload
  @connection.reset
end

#request(params) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# 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

#update_record(record_id, record_type, zone_id, name, data, options = {}) ⇒ Object

Get an individual DNS record from the specified zone

Returns

  • 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



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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