Class: Pvectl::Commands::Get::Handlers::Dns

Inherits:
Object
  • Object
show all
Includes:
ResourceHandler
Defined in:
lib/pvectl/commands/get/handlers/dns.rb,
sig/pvectl/commands/get/handlers/dns.rbs

Overview

Handler for reading per-node DNS resolver settings.

Implements ResourceHandler interface for the "dns" resource type. DNS is a singleton resource per node — there is no cluster-wide DNS configuration, so a node name is always required.

Examples:

Using via ResourceRegistry

handler = ResourceRegistry.for("dns")
dns = handler.list(node: "pve1") # => [DnsConfig]

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ResourceHandler

#selector_class

Constructor Details

#initialize(repository: nil) ⇒ Dns

Creates handler with optional repository for dependency injection.

Parameters:

  • (defaults to: nil)

    DNS repository

  • (defaults to: nil)


26
27
28
# File 'lib/pvectl/commands/get/handlers/dns.rb', line 26

def initialize(repository: nil)
  @repository = repository
end

Instance Attribute Details

#repositoryRepositories::Dns (readonly)

Returns repository, creating it if necessary.

Returns:

  • DNS repository



71
72
73
# File 'lib/pvectl/commands/get/handlers/dns.rb', line 71

def repository
  @repository ||= build_repository
end

Instance Method Details

#build_repositoryRepositories::Dns

Builds repository with connection from config.

Returns:

  • configured DNS repository



78
79
80
81
82
83
# File 'lib/pvectl/commands/get/handlers/dns.rb', line 78

def build_repository
  config_service = Pvectl::Config::Service.new
  config_service.load
  connection = Pvectl::Connection.new(config_service.current_config)
  Pvectl::Repositories::Dns.new(connection)
end

#describe(name:, node: nil, **_opts) ⇒ Models::DnsConfig

Describes the DNS configuration for a single node.

Accepts either name (positional argument from describe command) or node (--node flag) as the node identifier.

Parameters:

  • node name (positional)

  • (defaults to: nil)

    node name (--node flag, fallback)

  • unused, for interface compatibility

  • (defaults to: nil)

Returns:

  • DNS configuration model

Raises:

  • when no node identifier given



59
60
61
62
63
64
# File 'lib/pvectl/commands/get/handlers/dns.rb', line 59

def describe(name:, node: nil, **_opts)
  node_name = name || node
  raise ArgumentError, "Node name required: pvectl describe dns NODE or --node NODE" if node_name.nil? || node_name.to_s.empty?

  repository.fetch(node_name)
end

#list(node: nil, **_options) ⇒ Array<Models::DnsConfig>

Returns the DNS configuration for the given node, wrapped in an array.

Parameters:

  • (defaults to: nil)

    node name (REQUIRED — DNS is per-node)

  • unused, for interface compatibility

  • (defaults to: nil)

Returns:

  • single-element array with the DNS config

Raises:

  • when no node is provided



36
37
38
39
40
# File 'lib/pvectl/commands/get/handlers/dns.rb', line 36

def list(node: nil, **_options)
  raise ArgumentError, "DNS requires --node NODE to identify which node's settings to read" if node.nil? || node.to_s.empty?

  [repository.fetch(node)]
end

#presenterPresenters::DnsConfig

Returns presenter for DNS configuration.

Returns:

  • DNS presenter instance



45
46
47
# File 'lib/pvectl/commands/get/handlers/dns.rb', line 45

def presenter
  Pvectl::Presenters::DnsConfig.new
end