Class: Cisco::NameServer

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

Overview

NameServer - node utility class for DNS client name server 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, instantiate = true) ⇒ NameServer

Returns a new instance of NameServer.



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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.nameserversObject



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

def self.nameservers
  hosts = config_get('dnsclient', 'name_server')
  return {} if hosts.nil?

  hash = {}
  # Join and split because config_get returns array of strings separated by
  # spaces (regexes are a subset of PDA)
  hosts.join(' ').split(' ').each do |name|
    hash[name] = NameServer.new(name, false)
  end
  hash
end

Instance Method Details

#==(other) ⇒ Object



52
53
54
# File 'lib/cisco_node_utils/name_server.rb', line 52

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

#createObject



56
57
58
# File 'lib/cisco_node_utils/name_server.rb', line 56

def create
  config_set('dnsclient', 'name_server', state: '', ip: @name)
end

#destroyObject



60
61
62
# File 'lib/cisco_node_utils/name_server.rb', line 60

def destroy
  config_set('dnsclient', 'name_server', state: 'no', ip: @name)
end