Class: Fog::Zerigo::DNS::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/dns/zerigo.rb,
lib/fog/dns/requests/zerigo/get_host.rb,
lib/fog/dns/requests/zerigo/get_zone.rb,
lib/fog/dns/requests/zerigo/find_hosts.rb,
lib/fog/dns/requests/zerigo/list_hosts.rb,
lib/fog/dns/requests/zerigo/list_zones.rb,
lib/fog/dns/requests/zerigo/count_hosts.rb,
lib/fog/dns/requests/zerigo/count_zones.rb,
lib/fog/dns/requests/zerigo/create_host.rb,
lib/fog/dns/requests/zerigo/create_zone.rb,
lib/fog/dns/requests/zerigo/delete_host.rb,
lib/fog/dns/requests/zerigo/delete_zone.rb,
lib/fog/dns/requests/zerigo/update_host.rb,
lib/fog/dns/requests/zerigo/update_zone.rb,
lib/fog/dns/requests/zerigo/get_zone_stats.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/fog/dns/zerigo.rb', line 63

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

  @zerigo_email  = options[:zerigo_email]
  @zerigo_token  = options[:zerigo_token]
  @host   = options[:host]    || "ns.zerigo.com"
  @port   = options[:port]    || 80
  @scheme = options[:scheme]  || 'http'
  @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
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/dns/requests/zerigo/count_hosts.rb', line 16

def count_hosts( zone_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Zerigo::DNS::CountHosts.new,
    :path     => "/api/1.1/zones/#{zone_id}/hosts/count.xml"
  )
end

#count_zonesObject

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/dns/requests/zerigo/count_zones.rb', line 16

def count_zones()
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Zerigo::DNS::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 paramaters

    • 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/dns/requests/zerigo/create_host.rb', line 34

def create_host(zone_id, host_type, data, options = {})
  
  optional_tags= ''
  options.each { |option, value|
    case option
    when :hostname
      optional_tags+= "<hostname>#{value}</hostname>"
    when :notes
      optional_tags+= "<notes>#{value}</notes>"
    when :priority
      optional_tags+= "<priority>#{value}</priority>"
    when :ttl
      optional_tags+= "<ttl>#{value}</ttl>"
    end
  }
    
  request(
    :body     => %Q{<?xml version="1.0" encoding="UTF-8"?><host><host-type>#{host_type}</host-type><data>#{data}</data>#{optional_tags}</host>},
    :expects  => 201,
    :method   => 'POST',
    :parser   => Fog::Parsers::Zerigo::DNS::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/dns/requests/zerigo/create_zone.rb', line 49

def create_zone( domain, default_ttl, ns_type, options = {})

  optional_tags= ''
  options.each { |option, value|
    case option
    when :ns1
      optional_tags+= "<ns1>#{value}</ns1>"
    when :nx_ttl
      optional_tags+= "<nx-ttl type='interger'>#{value}</nx-ttl>"
    when :slave_nameservers
      optional_tags+= "<slave-nameservers>#{value}</slave-nameservers>"
    when :axfr_ips
      optional_tags+= "<axfr-ips>#{value}</axfr-ips>"
    when :custom_nameservers
      optional_tags+= "<custom-nameservers>#{value}</custom-nameservers>"
    when :custom_ns
      optional_tags+= "<custom-ns>#{value}</custom-ns>"
    when :hostmaster
      optional_tags+= "<hostmaster>#{value}</hostmaster>"
    when :notes
      optional_tags+= "<notes>#{value}</notes>"
    when :restrict_axfr
      optional_tags+= "<restrict-axfr>#{value}</restrict-axfr>"
    when :tag_list
      optional_tags+= "<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>#{optional_tags}</zone>},
    :expects  => 201,
    :method   => 'POST',
    :parser   => Fog::Parsers::Zerigo::DNS::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/dns/requests/zerigo/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/dns/requests/zerigo/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/dns/requests/zerigo/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::Zerigo::DNS::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::Zerigo::DNS::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/dns/requests/zerigo/get_host.rb', line 27

def get_host( host_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Zerigo::DNS::GetHost.new,
    :path     => "/api/1.1/hosts/#{host_id}.xml"
  )
end

#get_zone(zone) ⇒ 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/dns/requests/zerigo/get_zone.rb', line 37

def get_zone(zone)
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Zerigo::DNS::GetZone.new,
    :path     => "/api/1.1/zones/#{zone}.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/dns/requests/zerigo/get_zone_stats.rb', line 24

def get_zone_stats(zone_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Zerigo::DNS::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/dns/requests/zerigo/list_hosts.rb', line 28

def list_hosts( zone_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Zerigo::DNS::ListHosts.new,
    :path     => "/api/1.1/zones/#{zone_id}/hosts.xml"
  )
end

#list_zonesObject

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

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



33
34
35
36
37
38
39
40
# File 'lib/fog/dns/requests/zerigo/list_zones.rb', line 33

def list_zones
  request(
    :expects  => 200,
    :method   => 'GET',
    :parser   => Fog::Parsers::Zerigo::DNS::ListZones.new,
    :path     => '/api/1.1/zones.xml'
  )
end

#reloadObject



79
80
81
# File 'lib/fog/dns/zerigo.rb', line 79

def reload
  @connection.reset
end

#request(params) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/fog/dns/zerigo.rb', line 83

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::Zerigo::DNS::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/dns/requests/zerigo/update_host.rb', line 21

def update_host( host_id, options = {})

  optional_tags= ''
  options.each { |option, value|
    case option
    when :host_type
      optional_tags+= "<host-type>#{host_type}</host-type>"
    when :data
      optional_tags+= "<data>#{data}</data>"
    when :hostname
      optional_tags+= "<hostname>#{value}</hostname>"
    when :notes
      optional_tags+= "<notes>#{value}</notes>"
    when :priority
      optional_tags+= "<priority>#{value}</priority>"
    when :ttl
      optional_tags+= "<ttl>#{value}</ttl>"
    end
  }

  request(
    :body     => %Q{<?xml version="1.0" encoding="UTF-8"?><host>#{optional_tags}</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/dns/requests/zerigo/update_zone.rb', line 27

def update_zone( zone_id, options = {})

  optional_tags= ''
  options.each { |option, value|
    case option
    when :default_ttl
      optional_tags+= "<default-ttl>#{value}</default-ttl>"
    when :ns_type
      optional_tags+= "<ns-type>#{value}</ns-type>"
    when :ns1
      optional_tags+= "<ns1>#{value}</ns1>"
    when :nx_ttl
      optional_tags+= "<nx-ttl type='interger'>#{value}</nx-ttl>"
    when :slave_nameservers
      optional_tags+= "<slave-nameservers>#{value}</slave-nameservers>"
    when :axfr_ips
      optional_tags+= "<axfr-ips>#{value}</axfr-ips>"
    when :custom_nameservers
      optional_tags+= "<custom-nameservers>#{value}</custom-nameservers>"
    when :custom_ns
      optional_tags+= "<custom-ns>#{value}</custom-ns>"
    when :hostmaster
      optional_tags+= "<hostmaster>#{value}</hostmaster>"
    when :notes
      optional_tags+= "<notes>#{value}</notes>"
    when :restrict_axfr
      optional_tags+= "<restrict-axfr>#{value}</restrict-axfr>"
    when :tag_list
      optional_tags+= "<tag-list>#{value}</tag-list>"
    end
  }
  
  request(
    :body     => %Q{<?xml version="1.0" encoding="UTF-8"?><zone>#{optional_tags}</zone>},
    :expects  => 200,
    :method   => 'PUT',
    :path     => "/api/1.1/zones/#{zone_id}.xml"
  )
end