Class: PDNS::Server

Inherits:
API
  • Object
show all
Defined in:
lib/pdns_api/server.rb

Overview

Server object for accessing data for a particular server.

Instance Attribute Summary collapse

Attributes inherited from API

#class, #url

Instance Method Summary collapse

Methods inherited from API

#change, #create, #delete, #ensure_array, #get, #info

Constructor Details

#initialize(http, parent, id, info = {}) ⇒ Server

Creates a Server object.

  • http: An HTTP object for interaction with the PowerDNS server.

  • parent: This object’s parent.

  • id: ID of the server.

  • info: Optional information of the server.



39
40
41
42
43
44
45
46
# File 'lib/pdns_api/server.rb', line 39

def initialize(http, parent, id, info = {})
  @class  = :servers
  @http   = http
  @parent = parent
  @id     = id
  @url    = "#{parent.url}/#{@class}/#{id}"
  @info   = info
end

Instance Attribute Details

#idObject (readonly)

The ID of the server.



30
31
32
# File 'lib/pdns_api/server.rb', line 30

def id
  @id
end

Instance Method Details

#cache(domain) ⇒ Object

Flushes cache for domain.



50
51
52
# File 'lib/pdns_api/server.rb', line 50

def cache(domain)
  # TODO: #{url}/cache/flush?domain=:domain: PUT
end

#config(name = nil, value = nil) ⇒ Object

Returns existing configuration or creates a Config object.

If name is not set the current configuration is returned in a hash.

If name is set a Config object is returned using the provided name. If value is set as well, a complete config object is returned.



85
86
87
88
89
90
91
92
# File 'lib/pdns_api/server.rb', line 85

def config(name = nil, value = nil)
  return Config.new(@http, self, name, value) unless name.nil? || value.nil?
  return Config.new(@http, self, name) unless name.nil?

  # Get all current configuration
  config = @http.get("#{@url}/config")
  config.map { |c| [c[:name], c[:value]] }.to_h
end

#failuresObject

Manipulates failure logging.



74
75
76
# File 'lib/pdns_api/server.rb', line 74

def failures
  # TODO: /servers/:server_id/failures: GET, PUT
end

#overrides(id = nil) ⇒ Object Also known as: override

Returns existing or creates an Override object.

If id is not set the current servers are returned in a hash containing Override objects.

If id is set an Override object with the provided ID is returned.



101
102
103
104
105
106
# File 'lib/pdns_api/server.rb', line 101

def overrides(id = nil)
  return Override.new(@http, self, id) unless id.nil?

  overrides = @http.get("#{@url}/config")
  overrides.map { |o| [o[:id], Override.new(@http, self, o[:id], o)] }.to_h
end

#search_log(search_term) ⇒ Object

Searches through the server’s log with search_term.



56
57
58
# File 'lib/pdns_api/server.rb', line 56

def search_log(search_term)
  # TODO: /servers/:server_id/search-log?q=:search_term: GET
end

#statisticsObject

Gets the statistics for the server.



62
63
64
# File 'lib/pdns_api/server.rb', line 62

def statistics
  # TODO: /servers/:server_id/statistics: GET
end

#traceObject

Manipulates the query tracing log.



68
69
70
# File 'lib/pdns_api/server.rb', line 68

def trace
  # TODO: /servers/:server_id/trace: GET, PUT
end

#zones(id = nil) ⇒ Object Also known as: zone

Returns existing or creates a Zone object.

If id is not set the current servers are returned in a hash containing Zone objects.

If id is set a Server object with the provided ID is returned.



115
116
117
118
119
120
# File 'lib/pdns_api/server.rb', line 115

def zones(id = nil)
  return Zone.new(@http, self, id) unless id.nil?

  zones = @http.get("#{@url}/zones")
  zones.map { |z| [z[:id], Zone.new(@http, self, z[:id], z)] }.to_h
end