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(domain) ⇒ Object

Flushes cache for domain.


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

def cache(domain)
  # TODO: #{url}/cache/flush?domain=:domain: PUT
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.


90
91
92
93
94
95
96
97
# File 'lib/pdns_api/server.rb', line 90

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.


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

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.


109
110
111
112
113
114
# File 'lib/pdns_api/server.rb', line 109

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.


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

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

#statisticsObject

Gets the statistics for the server.


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

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

end

#traceObject

Manipulates the query tracing log.


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

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

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.


126
127
128
129
130
131
# File 'lib/pdns_api/server.rb', line 126

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