class Rbeapi::Api::Dns
The Dns
class manages DNS settings on an EOS node.
Public Instance Methods
add_domain_list
adds an ip domain-list.
@param name [String] The name of the ip domain-list to add.
@return [Boolean] Returns true if the command completed successfully.
# File lib/rbeapi/api/dns.rb, line 247 def add_domain_list(name) configure "ip domain-list #{name}" end
add_name_server
adds an ip name-server.
@param server [String] The name of the ip name-server to create.
@return [Boolean] Returns true if the command completed successfully.
# File lib/rbeapi/api/dns.rb, line 172 def add_name_server(server) configure "ip name-server #{server}" end
get returns the DNS resource.
@example
{ "domain_name": <string>, "name_servers": array<strings>, "domain_list": array<strings> }
@return [Hash] A Ruby hash object that provides the SNMP settings as
key / value pairs.
# 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
removes a specified ip domain-list.
@param name [String] The name of the ip domain-list to remove.
@return [Boolean] Returns true if the command completed successfully.
# File lib/rbeapi/api/dns.rb, line 257 def remove_domain_list(name) configure "no ip domain-list #{name}" end
remove_name_server
removes the specified ip name-server.
@param server [String] The name of the ip name-server to remove.
@return [Boolean] Returns true if the command completed successfully.
# File lib/rbeapi/api/dns.rb, line 182 def remove_name_server(server) configure "no ip name-server #{server}" end
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.
@since eos_version 4.13.7M
Commands¶ ↑
ip domain-list <value> no ip domain-list default ip domain-list
@option 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.
@option opts default [Boolean] Configures the ip domain-list using the
default keyword argument.
@return [Boolean] Returns true if the commands completed successfully. rubocop:disable Metrics/MethodLength
# 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
Configure the domain-name value in the running-config.
@param opts [Hash] The configuration parameters.
@option opts value [string] The value to set the domain-name to.
@option opts enable [Boolean] If false then the command is
negated. Default is true.
@option opts default [Boolean] The value should be set to default.
@return [Boolean] Returns true if the command completed successfully.
# 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
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.
@since eos_version 4.13.7M
Commands¶ ↑
ip name-server <value> no ip name-server default ip name-server
@param [Hash] opts The configuration parameters.
@option 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.
@option opts enable [Boolean] If false then the command is
negated. Default is true.
@option default [Boolean] Configures the ip name-servers using the
default keyword argument. Default takes precedence over enable.
@return [Boolean] Returns true if the commands completed successfully.
# 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
Private Instance Methods
parse_domain_list
parses the domain-list from config.
@api private
@return [Hash<Symbol, Object>] Returns the resource hash attribute.
# File lib/rbeapi/api/dns.rb, line 95 def parse_domain_list search = config.scan(/(?<=^ip\sdomain-list\s).+$/) { domain_list: search } end
parse_domain_name
parses the domain-name from config.
@api private
@return [Hash<Symbol, Object>] Returns the resource hash attribute.
# File lib/rbeapi/api/dns.rb, line 69 def parse_domain_name mdata = /ip domain-name ([\w.]+)/.match(config) { domain_name: mdata.nil? ? '' : mdata[1] } end
parse_name_servers
parses the name-server values from
config.
@api private
@return [Hash<Symbol, Array>] Returns the resource hash attribute.
# File lib/rbeapi/api/dns.rb, line 82 def parse_name_servers servers = config.scan(/(?:ip name-server vrf )(?:\w+)\s(.+)/) values = servers.each_with_object([]) { |srv, arry| arry << srv.first } { name_servers: values } end