class PDNS::Server

Server object for accessing data for a particular server.

Attributes

id[R]

@return [String] the ID of the server.

Public Class Methods

new(http, parent, id, info = {}) click to toggle source

Creates a Server object.

@param http [HTTP] An HTTP object for interaction with the PowerDNS server. @param parent [API] This object's parent. @param id [String] ID of the server. @param info [Hash] Optional information of the server.

# File lib/pdns_api/server.rb, line 40
def initialize(http, parent, id, info = {})
  @class  = :servers
  @http   = http
  @parent = parent
  @id     = id
  @url    = "#{parent.url}/#{@class}/#{id}"
  @info   = info
end

Public Instance Methods

cache_flush(domain) click to toggle source

Flushes cache for a domain.

@param domain [String] name of the domain. @return [Hash] result of the action.

# File lib/pdns_api/server.rb, line 55
def cache_flush(domain)
  @http.put("#{@url}/cache/flush?domain=#{domain}")
end
config(name = nil, value = nil) click to toggle source

Returns existing configuration or creates a Config object.

@param name [String, nil] Name of the configuration option. @param value [String, nil] Value op the configuration option.

@return [Hash, Config] Hash containing Config objects or a single 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.
# File lib/pdns_api/server.rb, line 114
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
failures() click to toggle source

Manipulates failure logging.

# File lib/pdns_api/server.rb, line 99
def failures
  # TODO: /servers/:server_id/failures: GET, PUT
end
override(id = nil)
Alias for: overrides
overrides(id = nil) click to toggle source

Returns existing or creates an Override object.

@param id [Integer, nil] ID of the override.

@return [Hash, Override] Hash containing Override objects or a single 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.
# File lib/pdns_api/server.rb, line 133
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
Also aliased as: override
search_log(search_term) click to toggle source

Searches through the server's log with search_term.

@param search_term [String] terms to search for. @return [Hash] result of the search.

# File lib/pdns_api/server.rb, line 65
def search_log(search_term)
  # TODO: /servers/:server_id/search-log?q=:search_term: GET
end
statistics() click to toggle source

Gets the statistics for the server.

# File lib/pdns_api/server.rb, line 71
def statistics
  # TODO: /servers/:server_id/statistics: GET
end
trace() click to toggle source

Retrieves the query tracing log.

@return [Hash] Regular expression and matching log lines.

# File lib/pdns_api/server.rb, line 93
def trace
  @http.get("#{@url}/trace")
end
trace=(domain_regex) click to toggle source

Manipulates the query tracing log.

@param domain_regex [String, nil]

Regular expression to match for domain tracing.
Set to nil to turn off tracking.

@return [Hash] Regular expression and matching log lines.

# File lib/pdns_api/server.rb, line 84
def trace=(domain_regex)
  @http.put("#{@url}/trace", domains: domain_regex)
end
zone(id = nil)
Alias for: zones
zones(id = nil) click to toggle source

Returns existing or creates a Zone object.

@param id [String, nil] ID of the override.

@return [Hash, Zone] Hash containing Zone objects or a single 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.
# File lib/pdns_api/server.rb, line 150
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
Also aliased as: zone