Class: Cisco::DnsDomain

Inherits:
NodeUtil show all
Defined in:
lib/cisco_node_utils/dns_domain.rb

Overview

DnsDomain - node utility class for DNS search domain config management

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NodeUtil

#client, client, #config_get, config_get, #config_get_default, config_get_default, config_set, #config_set, #get, #ios_xr?, #nexus?, node, #node, platform, #platform, supports?, #supports?

Constructor Details

#initialize(name, vrf = nil, instantiate = true) ⇒ DnsDomain

Returns a new instance of DnsDomain


31
32
33
34
35
36
37
38
# File 'lib/cisco_node_utils/dns_domain.rb', line 31

def initialize(name, vrf=nil, instantiate=true)
  unless name.is_a? String
    fail TypeError, "Expected a string, got a #{name.class.inspect}"
  end
  @name = name
  @vrf = vrf
  create if instantiate
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


29
30
31
# File 'lib/cisco_node_utils/dns_domain.rb', line 29

def name
  @name
end

#vrfObject (readonly)

Returns the value of attribute vrf


29
30
31
# File 'lib/cisco_node_utils/dns_domain.rb', line 29

def vrf
  @vrf
end

Class Method Details

.dnsdomains(vrf = nil) ⇒ Object


40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cisco_node_utils/dns_domain.rb', line 40

def self.dnsdomains(vrf=nil)
  if vrf.nil?
    domains = config_get('dnsclient', 'domain_list')
  else
    domains = config_get('dnsclient', 'domain_list_vrf', vrf: vrf)
  end
  hash = {}
  domains.each do |name|
    hash[name] = DnsDomain.new(name, vrf, false)
  end
  hash
end

Instance Method Details

#==(other) ⇒ Object


53
54
55
# File 'lib/cisco_node_utils/dns_domain.rb', line 53

def ==(other)
  (name == other.name) && (vrf == other.vrf)
end

#createObject


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/cisco_node_utils/dns_domain.rb', line 57

def create
  if @vrf.nil?
    config_set('dnsclient', 'domain_list',
               state: '', name: @name)
  else
    # On some platforms attempts to create a new domain-list results
    # in the error. 'ERROR: Deletion of VRF test in progresswait
    # for it to complete'.  We handle this by trying up to 20 times
    # with a 1 second delay between attempts before giving up.
    tries = 20
    begin
      config_set('dnsclient', 'domain_list_vrf',
                 state: '', name: @name, vrf: @vrf)
    rescue Cisco::CliError => e
      if /ERROR: Deletion of VRF .* in progress/.match(e.to_s)
        sleep 1
        tries -= 1
        # rubocop:disable Metrics/BlockNesting
        retry if tries > 0
        # rubocop:enable Metrics/BlockNesting
      end
      raise
    end
  end
end

#destroyObject


83
84
85
86
87
88
89
90
91
# File 'lib/cisco_node_utils/dns_domain.rb', line 83

def destroy
  if @vrf.nil?
    config_set('dnsclient', 'domain_list',
               state: 'no', name: @name)
  else
    config_set('dnsclient', 'domain_list_vrf',
               state: 'no', name: @name, vrf: @vrf)
  end
end