Class: Fog::DNS::PowerDNS::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/powerdns/dns.rb,
lib/fog/powerdns/requests/dns/get_zone.rb,
lib/fog/powerdns/requests/dns/get_server.rb,
lib/fog/powerdns/requests/dns/list_zones.rb,
lib/fog/powerdns/requests/dns/search_log.rb,
lib/fog/powerdns/requests/dns/create_zone.rb,
lib/fog/powerdns/requests/dns/delete_zone.rb,
lib/fog/powerdns/requests/dns/notify_zone.rb,
lib/fog/powerdns/requests/dns/update_zone.rb,
lib/fog/powerdns/requests/dns/list_servers.rb,
lib/fog/powerdns/requests/dns/get_cryptokey.rb,
lib/fog/powerdns/requests/dns/retrieve_zone.rb,
lib/fog/powerdns/requests/dns/update_rrsets.rb,
lib/fog/powerdns/requests/dns/list_cryptokeys.rb,
lib/fog/powerdns/requests/dns/get_server_stats.rb,
lib/fog/powerdns/requests/dns/get_server_config.rb,
lib/fog/powerdns/requests/dns/list_server_configs.rb,
lib/fog/powerdns/requests/dns/update_server_config.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fog/powerdns/dns.rb', line 37

def initialize(options={})

  @pdns_api_key = options[:pdns_api_key]
  @connection_options = options[:connection_options] || {}
  @host       = options[:host]      || "127.0.0.1"
  @persistent = options[:persistent]|| false
  @port       = options[:port]      || 8081
  @scheme     = options[:scheme]    || 'http'
  puts @api_key
  puts @persistent
  puts @connection_options
  puts @scheme
  puts @host
  puts @port
  @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

Instance Method Details

#create_zone(server, name, nameservers, options = {}) ⇒ Object

Create a single zone in PowerDNS Server, name and nameservers LIST are required

Parameters

  • server<~String> - Server ID

  • name<~String> - Name of domain

  • nameservers<~Array> - List of nameservers

  • options<~Hash> - Other options

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘id’: <~String>,

      • “name”: <~String>,

      • ‘type’: <~String>,

      • ‘url’: <~String>,

      • ‘kind’: <~String>,

      • ‘serial’: <~Integer>,

      • ‘notified_serial’: <~Int>,

      • ‘masters’: <~Array,

      • ‘dnssec’: <~Boolean>,

      • ‘nsec3param’: <~String>,

      • ‘nsec3narrow’: <~Boolean>,

      • ‘presigned’: <~Boolean>,

      • ‘soa_edit’: ‘<~String>’,

      • ‘soa_edit_api’: ‘<~String>’,

      • ‘account’: ‘<~String>’,

      • ‘nameservers’: <~Array>,

      • ‘servers’: <~Array>,

      • ‘recursion_desired’: <~Boolean>,

      • ‘records’: <~Array>,

      • ‘comments’: <~Array>,

    • status<~Integer> 201 when successful



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fog/powerdns/requests/dns/create_zone.rb', line 39

def create_zone(server, name, nameservers, options = {})
  body = {
      "name" => name,
      "nameservers" => nameservers
  }

  options.each { |option, value|
    body[option] = value;
  }

  request(
      :body     => Fog::JSON.encode(body),
      :expects  => 201,
      :method   => 'POST',
      :path     => "/servers/#{server}/zones"
  ).body
end

#delete_zone(server, zone) ⇒ Object

Parameters

  • server<~String> - server id

  • zone<~String> - zone id

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

    • status<~Integer> - 204 when successful



19
20
21
22
23
24
25
# File 'lib/fog/powerdns/requests/dns/delete_zone.rb', line 19

def delete_zone(server, zone)
  request(
      :expects  => 204,
      :method   => 'DELETE',
      :path     => "/servers/#{server}/zones/#{zone}"
  )
end

#get_cryptokey(server, zone, cryptokey) ⇒ Object

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘type’: <~String>,

      • ‘id’: <~Integer>,

      • ‘active’: <~Boolean>,

      • ‘keytype’: <~String>,

      • ‘dnskey’: <~String>,

      • ‘content’: <~String>,

      • ‘ds’: <~Array>

    • status<~Integer> - 200 when successful



26
27
28
29
30
31
32
# File 'lib/fog/powerdns/requests/dns/get_cryptokey.rb', line 26

def get_cryptokey(server, zone, cryptokey)
  request(
      :expects  => 200,
      :method   => 'GET',
      :path     => "/servers/#{server}/zones/#{zone}/cryptokeys/#{cryptokey}"
  ).body
end

#get_server(server) ⇒ Object

Get details of a DNS server

Parameters

  • server<~String> - server id

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘type’: <~String>,

      • ‘id’: <~String>,

      • ‘url’: <~String>,

      • ‘daemon_type’: <~String>,

      • ‘version’: <~String>,

      • ‘config_url’: <~String>,

      • ‘zones_url’: <~String>,

    • status<~String> - 200 when successful



22
23
24
25
26
27
28
# File 'lib/fog/powerdns/requests/dns/get_server.rb', line 22

def get_server(server)
  request(
      :expects  => 200,
      :method   => 'GET',
      :path     => "/servers/#{server}"
  ).body
end

#get_server_config(server, config) ⇒ Object

Get a specific config setting of one server TODO: Can only get / retrieve recursor’s allow_from

Parameters

  • server<~String> - server id

  • config<~String> - config name

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘type’: <~String>,

      • ‘name’: <~String>,

      • ‘value’: <~String>

    • status<~String> - 200 when successful



20
21
22
23
24
25
26
# File 'lib/fog/powerdns/requests/dns/get_server_config.rb', line 20

def get_server_config(server, config)
  request(
      :expects  => 200,
      :method   => 'GET',
      :path     => "/servers/#{server}/config/#{config}"
  ).body
end

#get_server_stats(server) ⇒ Object

Retrieves server stats

Parameters

  • server<~String> - server id

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      * statistics<~Hash>:
        * 'type': <~String>,
        * 'name': <~String>,
        * 'value': <~String>
      
    • status<~Integer> - 200 when successful



19
20
21
22
23
24
25
# File 'lib/fog/powerdns/requests/dns/get_server_stats.rb', line 19

def get_server_stats(server)
  request(
      :expects  => 200,
      :method   => 'GET',
      :path     => "/servers/#{server}/statistics"
  ).body
end

#get_zone(server, zone) ⇒ Object

Get details of a DNS zone

Parameters

  • zone<~String> - Zone id

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘id’: <~String>,

      • “name”: <~String>,

      • ‘type’: <~String>,

      • ‘url’: <~String>,

      • ‘kind’: <~String>,

      • ‘serial’: <~Integer>,

      • ‘notified_serial’: <~Int>,

      • ‘masters’: <~Array,

      • ‘dnssec’: <~Boolean>,

      • ‘nsec3param’: <~String>,

      • ‘nsec3narrow’: <~Boolean>,

      • ‘presigned’: <~Boolean>,

      • ‘soa_edit’: ‘<~String>’,

      • ‘soa_edit_api’: ‘<~String>’,

      • ‘account’: ‘<~String>’,

      • ‘nameservers’: <~Array>,

      • ‘servers’: <~Array>,

      • ‘recursion_desired’: <~Boolean>,

      • ‘records’: <~Array>,

      • ‘comments’: <~Array>,

    • status<~Integer> 200 when successful



35
36
37
38
39
40
41
# File 'lib/fog/powerdns/requests/dns/get_zone.rb', line 35

def get_zone(server, zone)
  request(
      :expects  => 200,
      :method   => 'GET',
      :path     => "/servers/#{server}/zones/#{zone}"
  ).body
end

#list_cryptokeys(server, zone) ⇒ Object

Get details of all public cryptokeys

Parameters

server<~String> - server id zone<~String> - zone id

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      * Cryptokey<~Hash>:
      * 'type': <~String>,
      * 'id': <~Integer>,
      * 'active': <~Boolean>,
      * 'keytype': <~String>,
      * 'dnskey': <~String>,
      * 'content': <~String>,
      * 'ds': <~Array>
      
    • status<~Integer> - 200 when successful



25
26
27
28
29
30
31
# File 'lib/fog/powerdns/requests/dns/list_cryptokeys.rb', line 25

def list_cryptokeys(server, zone)
  request(
      :expects  => 200,
      :method   => 'GET',
      :path     => "/servers/#{server}/zones/#{zone}/cryptokeys"
  ).body
end

#list_server_configs(server) ⇒ Object

Get all of a DNS server’s config settings

Parameters

  • server<~String> - server id

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      * Config<~Hash>:
        * 'type': <~String>,
        * 'name': <~String>,
        * 'value': <~String>
      
    • status<~String> - 200 when successful



19
20
21
22
23
24
25
# File 'lib/fog/powerdns/requests/dns/list_server_configs.rb', line 19

def list_server_configs(server)
  request(
      :expects  => 200,
      :method   => 'GET',
      :path     => "/servers/#{server}/config"
  ).body
end

#list_serversObject

Get details of all powerdns servers

Parameters

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • server<~Array>:

        • ‘type’: <~String>,

        • ‘id’: <~String>,

        • ‘url’: <~String>,

        • ‘daemon_type’: <~String>,

        • ‘version’: <~String>,

        • ‘config_url’: <~String>,

        • ‘zones_url’: <~String>,

    • status<~String> - 200 when successful



23
24
25
26
27
28
29
# File 'lib/fog/powerdns/requests/dns/list_servers.rb', line 23

def list_servers
  request(
      :expects  => 200,
      :method   => 'GET',
      :path     => "/servers"
  ).body
end

#list_zones(server) ⇒ Object

Get details of a server’s DNS zones

Parameters

  • server<~String> - server id

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • zone<~Hash>:

        • ‘id’: <~String>,

        • “name”: <~String>,

        • ‘type’: <~String>,

        • ‘url’: <~String>,

        • ‘kind’: <~String>,

        • ‘serial’: <~Integer>,

        • ‘notified_serial’: <~Int>,

        • ‘masters’: <~Array,

        • ‘dnssec’: <~Boolean>,

        • ‘nsec3param’: <~String>,

        • ‘nsec3narrow’: <~Boolean>,

        • ‘presigned’: <~Boolean>,

        • ‘soa_edit’: ‘<~String>’,

        • ‘soa_edit_api’: ‘<~String>’,

        • ‘account’: ‘<~String>’,

        • ‘nameservers’: <~Array>,

        • ‘servers’: <~Array>,

        • ‘recursion_desired’: <~Boolean>,

        • ‘records’: <~Array>,

        • ‘comments’: <~Array>,

    • status<~Integer> 200 when successful



36
37
38
39
40
41
42
# File 'lib/fog/powerdns/requests/dns/list_zones.rb', line 36

def list_zones(server)
  request(
      :expects  => 200,
      :method   => 'GET',
      :path     => "/servers/#{server}/zones"
  ).body
end

#notify_zone(server, zone) ⇒ Object

DNS Notify all slaves of the zone Authoritative only, zone must be set up as master or slave (fails otherwise)

Parameters

  • server<~String> - server id

  • zone<~String> - zone name

Returns

TODO: Untested

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘id’: <~String>,

      • “name”: <~String>,

      • ‘type’: <~String>,

      • ‘url’: <~String>,

      • ‘kind’: <~String>,

      • ‘serial’: <~Integer>,

      • ‘notified_serial’: <~Int>,

      • ‘masters’: <~Array,

      • ‘dnssec’: <~Boolean>,

      • ‘nsec3param’: <~String>,

      • ‘nsec3narrow’: <~Boolean>,

      • ‘presigned’: <~Boolean>,

      • ‘soa_edit’: ‘<~String>’,

      • ‘soa_edit_api’: ‘<~String>’,

      • ‘account’: ‘<~String>’,

      • ‘nameservers’: <~Array>,

      • ‘servers’: <~Array>,

      • ‘recursion_desired’: <~Boolean>,

      • ‘records’: <~Array>,

      • ‘comments’: <~Array>,

    • status<~Integer> 200 when successful



39
40
41
42
43
44
45
# File 'lib/fog/powerdns/requests/dns/notify_zone.rb', line 39

def notify_zone(server, zone)
  request(
      :expects  => 200,
      :method   => 'PUT',
      :path     => "/servers/#{server}/zones/#{zone}/notify"
  )
end

#reloadObject



54
55
56
# File 'lib/fog/powerdns/dns.rb', line 54

def reload
  @connection.reset
end

#request(params) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/fog/powerdns/dns.rb', line 58

def request(params)
  params[:headers] ||= {}
  params[:headers].merge!("X-API-key" => "#{@pdns_api_key}")
  params[:headers].merge!(
      "Accept" => "application/json",
      "Content-Type" => "application/json"
  )

  response = @connection.request(params)

  unless response.body.empty?
    response.body = Fog::JSON.decode(response.body)
  end
  response
end

#retrieve_zone(server, zone) ⇒ Object

Retrieves master Authoritative only, zone must be set up as slave (fails otherwise)

Parameters

  • server<~String> - server id

  • zone<~String> - zone name

Returns

TODO: Untested

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘id’: <~String>,

      • “name”: <~String>,

      • ‘type’: <~String>,

      • ‘url’: <~String>,

      • ‘kind’: <~String>,

      • ‘serial’: <~Integer>,

      • ‘notified_serial’: <~Int>,

      • ‘masters’: <~Array,

      • ‘dnssec’: <~Boolean>,

      • ‘nsec3param’: <~String>,

      • ‘nsec3narrow’: <~Boolean>,

      • ‘presigned’: <~Boolean>,

      • ‘soa_edit’: ‘<~String>’,

      • ‘soa_edit_api’: ‘<~String>’,

      • ‘account’: ‘<~String>’,

      • ‘nameservers’: <~Array>,

      • ‘servers’: <~Array>,

      • ‘recursion_desired’: <~Boolean>,

      • ‘records’: <~Array>,

      • ‘comments’: <~Array>,

    • status<~Integer> 201 when successful



39
40
41
42
43
44
45
# File 'lib/fog/powerdns/requests/dns/retrieve_zone.rb', line 39

def retrieve_zone(server, zone)
  request(
      :expects  => 200,
      :method   => 'PUT',
      :path     => "/servers/#{server}/zones/#{zone}/axfr-retrieve"
  )
end

#search_log(server, term) ⇒ Object

Searches for term in server logs

Parameters

  • server<~String> - server id

  • term<~String> - search term

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • log-line<~String>

    • status<~Integer> - 200 when successful



17
18
19
20
21
22
23
# File 'lib/fog/powerdns/requests/dns/search_log.rb', line 17

def search_log(server, term)
  request(
      :expects  => 200,
      :method   => 'GET',
      :path     => "/servers/#{server}/search-log?q=#{term}"
  ).body
end

#update_rrsets(server, zone, options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fog/powerdns/requests/dns/update_rrsets.rb', line 32

def update_rrsets(server, zone, options = {})
  options.each { |option, value|
    body[option] = value;
  }

  request(
      :body     => Fog::JSON.encode(body),
      :expects  => 200,
      :method   => 'PATCH',
      :path     => "/servers/#{server}/zones/#{zone}/"
  )
end

#update_server_config(server, config, body) ⇒ Object

Update a specific config setting of one server TODO: Can only get / retrieve recursor’s allow_from

Parameters

  • server<~String> - server id

  • config<~String> - config name

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘type’: <~String>,

      • ‘name’: <~String>,

      • ‘value’: <~String>

    • status<~String> - 200 when successful



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fog/powerdns/requests/dns/update_server_config.rb', line 20

def update_server_config(server, config, body)
  if config == 'allows_from'
    request(
        :body     => body,
        :expects  => 200,
        :method   => 'PUT',
        :path     => "/servers/#{server}/config/#{config}"
    ).body
  else
    puts 'Only allows_from config is allowed.'
  end
end

#update_zone(server, zone, options = {}) ⇒ Object

Modify a single zone in PowerDNS

Parameters

server<~String> - server id zone<~String> - zone id options<~Hash> - pairs enumerated below

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘id’: <~String>,

      • “name”: <~String>,

      • ‘type’: <~String>,

      • ‘url’: <~String>,

      • ‘kind’: <~String>,

      • ‘serial’: <~Integer>,

      • ‘notified_serial’: <~Int>,

      • ‘masters’: <~Array,

      • ‘dnssec’: <~Boolean>,

      • ‘nsec3param’: <~String>,

      • ‘nsec3narrow’: <~Boolean>,

      • ‘presigned’: <~Boolean>,

      • ‘soa_edit’: ‘<~String>’,

      • ‘soa_edit_api’: ‘<~String>’,

      • ‘account’: ‘<~String>’,

      • ‘nameservers’: <~Array>,

      • ‘servers’: <~Array>,

      • ‘recursion_desired’: <~Boolean>,

      • ‘records’: <~Array>,

      • ‘comments’: <~Array>,

    • status<~Integer> 200 when successful



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fog/powerdns/requests/dns/update_zone.rb', line 38

def update_zone(server, zone, options = {})

  options.each { |option, value|
    body[option] = value;
  }

  request(
      :body     => Fog::JSON.encode(body),
      :expects  => 200,
      :method   => 'PUT',
      :path     => "/servers/#{server}/zones/#{zone}"
  ).body
end