class PuppetX::Eos::Ntp
The Ntp
class provides a base class instance for working with the global NTP configuration
Public Class Methods
Public Instance Methods
Adds a new NTP server to the configured list
@param [String] name The name of the interface to add
@return [Boolean] True if the command succeeds otherwise False
# File lib/puppet_x/eos/modules/ntp.rb, line 93 def add_server(name) @api.config("ntp server #{name}") == [{}] end
Returns the Ntp
hash representing current running ntp configuration from eAPI. Currently the servers element returns a hash of server keys with an empty hash value. Additional server attributes will be added in subsequent versions
Example
{ "source_interface": <String>, "servers": { "A.B.C.D": {...} } }
@return [Hash] returns a Hash of attributes derived from eAPI
# File lib/puppet_x/eos/modules/ntp.rb, line 69 def get result = @api.enable('show running-config section ntp', format: 'text') output = result.first['output'] m_source = /(?<=source\s)(\w|\d)+$/.match(output) servers = {} output.scan(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/).each do |srv| servers[srv] = {} end attr_hash = { 'source_interface' => m_source.nil? ? '' : m_source[0], 'servers' => servers } attr_hash end
Removes a previously configured interface from the Mlag
domain
@param [String] name The name of the interface to remove
@return [Boolean] True if the command succeeds otherwise False
# File lib/puppet_x/eos/modules/ntp.rb, line 103 def remove_server(name) @api.config("no ntp server #{name}") == [{}] end
Configures the ntp source interface
@param [Hash] opts The configuration parameters for mlag @option opts [string] :value The value to set the domain-id to @option opts [Boolean] :default The value should be set to default
@return [Boolean] True if the commands succeed otherwise False
# File lib/puppet_x/eos/modules/ntp.rb, line 115 def set_source_interface(opts = {}) value = opts[:value] || false default = opts[:default] || false case default when true cmd = 'default ntp source' when false cmd = (value ? "ntp source #{value}" : 'no ntp source') end @api.config(cmd) == [{}] end