Class: Rbeapi::Api::Dns

Inherits:
Entity
  • Object
show all
Defined in:
lib/rbeapi/api/dns.rb

Overview

The Dns class manages DNS settings on an EOS node.

Instance Attribute Summary

Attributes inherited from Entity

#config, #error, #node

Instance Method Summary collapse

Methods inherited from Entity

#command_builder, #configure, #configure_interface, #get_block, #initialize, instance

Constructor Details

This class inherits a constructor from Rbeapi::Api::Entity

Instance Method Details

#add_domain_list(name) ⇒ Boolean

add_domain_list adds an ip domain-list.

Parameters:

  • name (String)

    The name of the ip domain-list to add.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.



247
248
249
# File 'lib/rbeapi/api/dns.rb', line 247

def add_domain_list(name)
  configure "ip domain-list #{name}"
end

#add_name_server(server) ⇒ Boolean

add_name_server adds an ip name-server.

Parameters:

  • server (String)

    The name of the ip name-server to create.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.



172
173
174
# File 'lib/rbeapi/api/dns.rb', line 172

def add_name_server(server)
  configure "ip name-server #{server}"
end

#getHash

get returns the DNS resource.

Examples:

{
  "domain_name": <string>,
  "name_servers": array<strings>,
  "domain_list": array<strings>
}

Returns:

  • (Hash)

    A Ruby hash object that provides the SNMP settings as key / value pairs.



55
56
57
58
59
60
61
# File 'lib/rbeapi/api/dns.rb', line 55

def get
  response = {}
  response.merge!(parse_domain_name)
  response.merge!(parse_name_servers)
  response.merge!(parse_domain_list)
  response
end

#remove_domain_list(name) ⇒ Boolean

remove_domain_list removes a specified ip domain-list.

Parameters:

  • name (String)

    The name of the ip domain-list to remove.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.



257
258
259
# File 'lib/rbeapi/api/dns.rb', line 257

def remove_domain_list(name)
  configure "no ip domain-list #{name}"
end

#remove_name_server(server) ⇒ Boolean

remove_name_server removes the specified ip name-server.

Parameters:

  • server (String)

    The name of the ip name-server to remove.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.



182
183
184
# File 'lib/rbeapi/api/dns.rb', line 182

def remove_name_server(server)
  configure "no ip name-server #{server}"
end

#set_domain_list(opts = {}) ⇒ Boolean

set_domain_list configures the set of domain names to search when making dns queries for the FQDN. If the enable option is set to false, then the domain-list will be configured using the no keyword. If the default option is specified, then the domain list will be configured using the default keyword. If both options are provided the default keyword option will take precedence.

Commands

ip domain-list <value>
no ip domain-list
default ip domain-list

rubocop:disable Metrics/MethodLength

Parameters:

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

    a customizable set of options

Options Hash (opts):

  • value (Array)

    The set of domain names to configure on the node. The list of domain names will be replace in the nodes running configuration by the list provided in value.

  • default (Boolean)

    Configures the ip domain-list using the default keyword argument.

Returns:

  • (Boolean)

    Returns true if the commands completed successfully.

Since:

  • eos_version 4.13.7M



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/rbeapi/api/dns.rb', line 210

def set_domain_list(opts = {})
  value = opts[:value]
  enable = opts.fetch(:enable, true)
  default = opts[:default] || false

  if value
    unless value.is_a?(Array)
      raise ArgumentError, 'value must be an Array'
    end
  end

  cmds = []
  case default
  when true
    parse_domain_list[:domain_list].each do |name|
      cmds << "default ip domain-list #{name}"
    end
  when false
    parse_domain_list[:domain_list].each do |name|
      cmds << "no ip domain-list #{name}"
    end
    if enable
      value.each do |name|
        cmds << "ip domain-list #{name}"
      end
    end
  end
  configure cmds
end

#set_domain_name(opts = {}) ⇒ Boolean

Configure the domain-name value in the running-config.

Parameters:

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

    The configuration parameters.

Options Hash (opts):

  • value (string)

    The value to set the domain-name to.

  • enable (Boolean)

    If false then the command is negated. Default is true.

  • default (Boolean)

    The value should be set to default.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.



114
115
116
117
# File 'lib/rbeapi/api/dns.rb', line 114

def set_domain_name(opts = {})
  cmds = command_builder('ip domain-name', opts)
  configure(cmds)
end

#set_name_servers(opts = {}) ⇒ Boolean

set_name_servers configures the set of name servers that eos will use to resolve dns queries. If the enable option is false, then the name-server list will be configured using the no keyword. If the default option is specified, then the name server list will be configured using the default keyword. If both options are provided the keyword option will take precedence.

Commands

ip name-server <value>
no ip name-server
default ip name-server

Parameters:

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

    The configuration parameters.

  • default (Hash)

    a customizable set of options

Options Hash (opts):

  • value (string)

    The set of name servers to configure on the node. The list of name servers will be replace in the nodes running configuration by the list provided in value.

  • enable (Boolean)

    If false then the command is negated. Default is true.

Returns:

  • (Boolean)

    Returns true if the commands completed successfully.

Since:

  • eos_version 4.13.7M



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/rbeapi/api/dns.rb', line 147

def set_name_servers(opts = {})
  value = opts[:value]
  enable = opts.fetch(:enable, true)
  default = opts[:default] || false

  case default
  when true
    cmds = 'default ip name-server'
  when false
    cmds = ['no ip name-server']
    if enable
      value.each do |srv|
        cmds << "ip name-server #{srv}"
      end
    end
  end
  configure cmds
end