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

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/fog/dns/slicehost.rb', line 54

def initialize(options={})
  unless options.delete(:provider)
    location = caller.first
    warning = "[yellow][WARN] Fog::Slicehost::DNS.new is deprecated, use Fog::DNS.new(:provider => 'Slicehost') instead[/]"
    warning << " [light_black](" << location << ")[/] "
    Formatador.display_line(warning)
  end

  require 'fog/core/parser'

  @slicehost_password = options[:slicehost_password]
  @host   = options[:host]    || "api.slicehost.com"
  @port   = options[:port]    || 443
  @scheme = options[:scheme]  || 'https'
  @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
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/dns/requests/slicehost/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::Slicehost::DNS::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/dns/requests/slicehost/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::Slicehost::DNS::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/dns/requests/slicehost/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/dns/requests/slicehost/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/dns/requests/slicehost/get_record.rb', line 20

def get_record(record_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Slicehost::DNS::GetRecords.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>:

      • ‘addresses’<~Array> - Ip addresses for the slice

      • ‘backup-id’<~Integer> - Id of backup slice was booted from

      • ‘flavor_id’<~Integer> - Id of flavor slice was booted from

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

      • ‘image-id’<~Integer> - Id of image slice was booted from

      • ‘name’<~String> - Name of the slice

      • ‘progress’<~Integer> - Progress of current action, in percentage

      • ‘status’<~String> - Current status of the slice



21
22
23
24
25
26
27
28
# File 'lib/fog/dns/requests/slicehost/get_records.rb', line 21

def get_records
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Slicehost::DNS::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/dns/requests/slicehost/get_zone.rb', line 20

def get_zone(zone_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Slicehost::DNS::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/dns/requests/slicehost/get_zones.rb', line 18

def get_zones
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Slicehost::DNS::GetZones.new,
    :path     => 'zones.xml'
  )
end

#reloadObject



71
72
73
# File 'lib/fog/dns/slicehost.rb', line 71

def reload
  @connection.reset
end

#request(params) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/fog/dns/slicehost.rb', line 75

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::Slicehost::DNS::NotFound.slurp(error)
    else
      error
    end
  end

  response
end