Class: Cisco::DomainName

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

Overview

DomainName- node utility class for domain name configuration

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) ⇒ DomainName

Returns a new instance of DomainName.



26
27
28
29
30
# File 'lib/cisco_node_utils/domain_name.rb', line 26

def initialize(name, vrf=nil, instantiate=true)
  @name = name
  @vrf = vrf
  create if instantiate
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/cisco_node_utils/domain_name.rb', line 24

def name
  @name
end

#vrfObject (readonly)

Returns the value of attribute vrf.



24
25
26
# File 'lib/cisco_node_utils/domain_name.rb', line 24

def vrf
  @vrf
end

Class Method Details

.domainnames(vrf = nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/cisco_node_utils/domain_name.rb', line 32

def self.domainnames(vrf=nil)
  hash = {}
  if vrf.nil?
    domain = config_get('dnsclient', 'domain_name')
  else
    domain = config_get('dnsclient', 'domain_name_vrf', vrf: vrf)
  end
  hash[domain] = DomainName.new(domain, vrf, false) unless domain.empty?
  hash
end

Instance Method Details

#==(other) ⇒ Object



43
44
45
# File 'lib/cisco_node_utils/domain_name.rb', line 43

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

#createObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/cisco_node_utils/domain_name.rb', line 47

def create
  if @vrf.nil?
    config_set('dnsclient', 'domain_name',
               state: '', name: @name)
  else
    # On some platforms attempts to create a new domain results
    # in the error. 'ERROR: Deletion of VRF test in progresswait
    # for it to complete'.  We handle this by trying up to 10 times
    # with a 1 second delay between attempts before giving up.
    tries = 10
    begin
      config_set('dnsclient', 'domain_name_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
    end
  end
end

#destroyObject



72
73
74
75
76
77
78
79
80
# File 'lib/cisco_node_utils/domain_name.rb', line 72

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