Class: Rbeapi::Api::Ntp
Overview
The Ntp class provides an instance for working with the nodes NTP configuration.
Constant Summary collapse
- DEFAULT_TRST_KEY =
''.freeze
- DEFAULT_SRC_INTF =
''.freeze
- SERVER_REGEXP =
Regular expression to extract a NTP server’s attributes from the running-configuration text. The explicit [ ] spaces enable line wrapping and indentation with the /x flag.
/^(?:ntp[ ]server) (?:(?:[ ]vrf[ ])([^\s]+))? [ ]([^\s]+) ([ ]prefer)? (?:(?:[ ]minpoll[ ])(\d+))? (?:(?:[ ]maxpoll[ ])(\d+))? (?:(?:[ ]source[ ])([^\s]+))? (?:(?:[ ]key[ ])(\d+))?/x
- AUTH_KEY_REGEXP =
Regular expression to extract NTP authentication-keys from the running-configuration text. The explicit [ ] spaces enable line wrapping and indentation with the /x flag.
/^(?:ntp[ ]authentication-key[ ]) (\d+)[ ](\w+)[ ](\d+)[ ](\w+)/x
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#add_server(server, prefer = false, opts = {}) ⇒ Boolean
add_server configures a new ntp server destination hostname or ip address to the list of ntp destinations.
-
#get ⇒ nil, Hash<Symbol, Object>
get returns the nodes current ntp configure as a resource hash.
-
#remove_server(server, vrf = nil) ⇒ Boolean
remove_server deletes the provided server destination from the list of ntp server destinations.
-
#set_authenticate(opts = {}) ⇒ Boolean
set_authenticate configures ntp authentication in the nodes running configuration.
-
#set_authentication_key(opts = {}) ⇒ Boolean
set_authentication_key configures the ntp authentication-keys in the device running configuration.
-
#set_prefer(srv, value) ⇒ Boolean
set_prefer will set the prefer keyword for the specified ntp server.
-
#set_source_interface(opts = {}) ⇒ Boolean
set_source_interface configures the ntp source value in the nodes running configuration.
-
#set_trusted_key(opts = {}) ⇒ Boolean
set_trusted_key configures the ntp trusted-keys in the device running configuration.
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_server(server, prefer = false, opts = {}) ⇒ Boolean
add_server configures a new ntp server destination hostname or ip address to the list of ntp destinations. The optional prefer argument configures the server as a preferred (true) or not (false) ntp destination.
361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/rbeapi/api/ntp.rb', line 361 def add_server(server, prefer = false, opts = {}) cmd = 'ntp server ' cmd << "vrf #{opts[:vrf]} " if opts[:vrf] cmd << server.to_s cmd << ' prefer' if prefer || opts[:prefer].to_s == 'true' cmd << " minpoll #{opts[:minpoll]} " if opts[:minpoll] cmd << " maxpoll #{opts[:maxpoll]} " if opts[:maxpoll] cmd << " source #{opts[:source_interface]} " if opts[:source_interface] cmd << " key #{opts[:key]} " if opts[:key] configure(cmd) end |
#get ⇒ nil, Hash<Symbol, Object>
get returns the nodes current ntp configure as a resource hash.
81 82 83 84 85 86 87 88 89 |
# File 'lib/rbeapi/api/ntp.rb', line 81 def get response = {} response.merge!(parse_authenticate) response.merge!(parse_source_interface) response.merge!(parse_servers) response.merge!(parse_trusted_key) response.merge!(parse_auth_keys) response end |
#remove_server(server, vrf = nil) ⇒ Boolean
remove_server deletes the provided server destination from the list of ntp server destinations. If the ntp server does not exist in the list of servers, this method will return successful
385 386 387 |
# File 'lib/rbeapi/api/ntp.rb', line 385 def remove_server(server, vrf = nil) configure("no ntp server #{vrf.nil? ? '' : "vrf #{vrf} "}#{server}") end |
#set_authenticate(opts = {}) ⇒ Boolean
set_authenticate configures ntp authentication in the nodes running configuration. If the enable keyword is false, then ntp authentication is configured with the no keyword argument. If the default keyword argument is provided and set to true, the value is configured used the default keyword. The default keyword takes precedence over the enable keyword if both options are specified.
Commands
ntp authenticate
no ntp authenticate
default ntp authenticate
209 210 211 212 |
# File 'lib/rbeapi/api/ntp.rb', line 209 def set_authenticate(opts = {}) cmd = command_builder('ntp authenticate', opts) configure(cmd) end |
#set_authentication_key(opts = {}) ⇒ Boolean
set_authentication_key configures the ntp authentication-keys in the device running configuration. If the enable keyword is false, then the ntp source is configured with the no keyword argument. If the default keyword argument is provided and set to true, the value is configured used the default keyword. The default keyword takes precedence over the enable keyword if both options are specified.
Commands
ntp trusted-key <key> <algorithm> <mode> <password>
no ntp trusted-key <key>
default ntp trusted-key <key>
default value is 7
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/rbeapi/api/ntp.rb', line 247 def set_authentication_key(opts = {}) cmd = command_builder('ntp authentication-key', opts) configure(cmd) algorithm = opts[:algorithm] default = opts[:default] || false enable = opts.fetch(:enable, true) key = opts[:key] mode = opts.fetch(:mode, 7) password = opts[:password] case default when true cmds = "default ntp authentication-key #{key}" when false cmds = if enable "ntp authentication-key #{key} #{algorithm} #{mode} "\ "#{password}" else "no ntp authentication-key #{key}" end end configure cmds end |
#set_prefer(srv, value) ⇒ Boolean
set_prefer will set the prefer keyword for the specified ntp server. If the server does not already exist in the configuration, it will be added and the prefer keyword will be set.
Commands
ntp server <srv> prefer
no ntp server <srv> prefer
408 409 410 411 412 413 414 415 416 |
# File 'lib/rbeapi/api/ntp.rb', line 408 def set_prefer(srv, value) case value when true cmds = "ntp server #{srv} prefer" when false cmds = ["no ntp server #{srv} prefer", "ntp server #{srv}"] end configure cmds end |
#set_source_interface(opts = {}) ⇒ Boolean
set_source_interface configures the ntp source value in the nodes running configuration. If the enable keyword is false, then the ntp source is configured with the no keyword argument. If the default keyword argument is provided and set to true, the value is configured used the default keyword. The default keyword takes precedence over the enable keyword if both options are specified.
Commands
ntp source <value>
no ntp source
default ntp source
299 300 301 302 |
# File 'lib/rbeapi/api/ntp.rb', line 299 def set_source_interface(opts = {}) cmd = command_builder('ntp source', opts) configure(cmd) end |
#set_trusted_key(opts = {}) ⇒ Boolean
set_trusted_key configures the ntp trusted-keys in the device running configuration. If the enable keyword is false, then the ntp authentication-key is configured with the no keyword argument. If the default keyword argument is provided and set to true, the value is configured using the default keyword. The default keyword takes precedence over the enable keyword if both options are specified.
Commands
ntp authentication-key <key> <algorithm> <mode> <password>
no ntp authentication-key <key>
default ntp trusted-key <key>
330 331 332 333 |
# File 'lib/rbeapi/api/ntp.rb', line 330 def set_trusted_key(opts = {}) cmd = command_builder('ntp trusted-key', opts) configure(cmd) end |