Class: Rbeapi::Api::Dns
Overview
The Dns class manages DNS settings on an EOS node.
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
- #add_domain_list(name) ⇒ Object
- #add_name_server(server) ⇒ Object
-
#get ⇒ Hash
Returns the DNS resource.
- #parse_domain_list ⇒ Object
- #parse_domain_name ⇒ Object
- #parse_name_servers ⇒ Object
- #remove_domain_list(name) ⇒ Object
- #remove_name_server(server) ⇒ Object
-
#set_domain_list(opts = {}) ⇒ Boolean
set_domain_list configures the set of domain names to search when making dns queries for the FQDN.
-
#set_domain_name(opts = {}) ⇒ Boolean
Configure the domain-name value in the running-config.
-
#set_name_servers(opts = {}) ⇒ Boolean
set_name_servers configures the set of name servers that eos will use to resolve dns queries.
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) ⇒ Object
193 194 195 |
# File 'lib/rbeapi/api/dns.rb', line 193 def add_domain_list(name) configure "ip domain-list #{name}" end |
#add_name_server(server) ⇒ Object
138 139 140 |
# File 'lib/rbeapi/api/dns.rb', line 138 def add_name_server(server) configure "ip name-server #{server}" end |
#get ⇒ Hash
Returns the DNS resource
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 |
#parse_domain_list ⇒ Object
74 75 76 77 |
# File 'lib/rbeapi/api/dns.rb', line 74 def parse_domain_list search = config.scan(/(?<=^ip\sdomain-list\s).+$/) { domain_list: search } end |
#parse_domain_name ⇒ Object
63 64 65 66 |
# File 'lib/rbeapi/api/dns.rb', line 63 def parse_domain_name mdata = /ip domain-name ([\w.]+)/.match(config) { domain_name: mdata.nil? ? '' : mdata[1] } end |
#parse_name_servers ⇒ Object
68 69 70 71 72 |
# File 'lib/rbeapi/api/dns.rb', line 68 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 |
#remove_domain_list(name) ⇒ Object
197 198 199 |
# File 'lib/rbeapi/api/dns.rb', line 197 def remove_domain_list(name) configure "no ip domain-list #{name}" end |
#remove_name_server(server) ⇒ Object
142 143 144 |
# File 'lib/rbeapi/api/dns.rb', line 142 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.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/rbeapi/api/dns.rb', line 169 def set_domain_list(opts = {}) value = opts[:value] enable = opts.fetch(:enable, true) default = opts[:default] || false 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
89 90 91 92 |
# File 'lib/rbeapi/api/dns.rb', line 89 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
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/rbeapi/api/dns.rb', line 119 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 |