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.

Parameters:

  • http (HTTP)

    An HTTP object for interaction with the PowerDNS server.

  • parent (API)

    This object’s parent.

  • id (String)

    ID of the server.

  • info (Hash) (defaults to: {})

    Optional information of the server.



40
41
42
43
44
45
46
47
# 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

Instance Attribute Details

#idString (readonly)

Returns the ID of the server.

Returns:

  • (String)

    the ID of the server.



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

def id
  @id
end

Instance Method Details

#cache_flush(domain) ⇒ Hash

Flushes cache for a domain.

Parameters:

  • domain (String)

    name of the domain.

Returns:

  • (Hash)

    result of the action.



55
56
57
# 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) ⇒ Hash, Config

Returns existing configuration or creates a Config object.

Parameters:

  • name (String, nil) (defaults to: nil)

    Name of the configuration option.

  • value (String, nil) (defaults to: nil)

    Value op the configuration option.

Returns:

  • (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.



114
115
116
117
118
119
120
121
# 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

#failuresObject

Manipulates failure logging.



99
100
101
# File 'lib/pdns_api/server.rb', line 99

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

#overrides(id = nil) ⇒ Hash, Override Also known as: override

Returns existing or creates an Override object.

Parameters:

  • id (Integer, nil) (defaults to: nil)

    ID of the override.

Returns:

  • (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.



133
134
135
136
137
138
# 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

#search_log(search_term) ⇒ Hash

Searches through the server’s log with search_term.

Parameters:

  • search_term (String)

    terms to search for.

Returns:

  • (Hash)

    result of the search.



65
66
67
# File 'lib/pdns_api/server.rb', line 65

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

#statisticsObject

Gets the statistics for the server.



71
72
73
# File 'lib/pdns_api/server.rb', line 71

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

#traceHash

Retrieves the query tracing log.

Returns:

  • (Hash)

    Regular expression and matching log lines.



93
94
95
# File 'lib/pdns_api/server.rb', line 93

def trace
  @http.get("#{@url}/trace")
end

#trace=(domain_regex) ⇒ Hash

Manipulates the query tracing log.

Parameters:

  • domain_regex (String, nil)

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

Returns:

  • (Hash)

    Regular expression and matching log lines.



84
85
86
# File 'lib/pdns_api/server.rb', line 84

def trace=(domain_regex)
  @http.put("#{@url}/trace", domains: domain_regex)
end

#zones(id = nil) ⇒ Hash, Zone Also known as: zone

Returns existing or creates a Zone object.

Parameters:

  • id (String, nil) (defaults to: nil)

    ID of the override.

Returns:

  • (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.



150
151
152
153
154
155
# 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