Class: Pvectl::Models::DnsConfig

Inherits:
Base
  • Object
show all
Defined in:
lib/pvectl/models/dns_config.rb

Overview

Represents the DNS resolver configuration for a Proxmox node.

Immutable value object. Created by Repositories::Dns from API data. Each node has its own DNS settings — there is no cluster-wide DNS config.

Examples:

Creating from API response

dns = DnsConfig.new(node: "pve1", search: "example.com",
                    dns1: "8.8.8.8", dns2: "1.1.1.1")
dns.servers #=> ["8.8.8.8", "1.1.1.1"]

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ DnsConfig

Creates a new DnsConfig.

Parameters:

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

    attribute key-value pairs (node, search, dns1, dns2, dns3)



37
38
39
40
41
42
43
44
# File 'lib/pvectl/models/dns_config.rb', line 37

def initialize(attributes = {})
  super
  @node = attributes[:node] || attributes["node"]
  @search = attributes[:search] || attributes["search"]
  @dns1 = attributes[:dns1] || attributes["dns1"]
  @dns2 = attributes[:dns2] || attributes["dns2"]
  @dns3 = attributes[:dns3] || attributes["dns3"]
end

Instance Attribute Details

#dns1String? (readonly)

Returns first nameserver IP address.

Returns:

  • (String, nil)

    first nameserver IP address



26
27
28
# File 'lib/pvectl/models/dns_config.rb', line 26

def dns1
  @dns1
end

#dns2String? (readonly)

Returns second nameserver IP address (optional).

Returns:

  • (String, nil)

    second nameserver IP address (optional)



29
30
31
# File 'lib/pvectl/models/dns_config.rb', line 29

def dns2
  @dns2
end

#dns3String? (readonly)

Returns third nameserver IP address (optional).

Returns:

  • (String, nil)

    third nameserver IP address (optional)



32
33
34
# File 'lib/pvectl/models/dns_config.rb', line 32

def dns3
  @dns3
end

#nodeString? (readonly)

Returns node name (not part of the API payload — added by repository).

Returns:

  • (String, nil)

    node name (not part of the API payload — added by repository)



20
21
22
# File 'lib/pvectl/models/dns_config.rb', line 20

def node
  @node
end

#searchString? (readonly)

Returns search domain for hostname lookup.

Returns:

  • (String, nil)

    search domain for hostname lookup



23
24
25
# File 'lib/pvectl/models/dns_config.rb', line 23

def search
  @search
end

Instance Method Details

#serversArray<String>

Returns the configured DNS servers in order, omitting unset entries.

Returns:

  • (Array<String>)

    nameserver IP addresses (may be empty)



49
50
51
# File 'lib/pvectl/models/dns_config.rb', line 49

def servers
  [dns1, dns2, dns3].compact
end