Class: PuppetX::Eos::Ntp
- Inherits:
-
Object
- Object
- PuppetX::Eos::Ntp
- Defined in:
- lib/puppet_x/eos/modules/ntp.rb
Overview
The Ntp class provides a base class instance for working with the global NTP configuration
Instance Method Summary collapse
-
#add_server(name) ⇒ Boolean
Adds a new NTP server to the configured list.
-
#get ⇒ Hash
Returns the Ntp hash representing current running ntp configuration from eAPI.
-
#initialize(api) ⇒ PuppetX::Eos::Ntp
constructor
Initialize instance of Snmp.
-
#remove_server(name) ⇒ Boolean
Removes a previously configured interface from the Mlag domain.
-
#set_source_interface(opts = {}) ⇒ Boolean
Configures the ntp source interface.
Constructor Details
#initialize(api) ⇒ PuppetX::Eos::Ntp
Initialize instance of Snmp
50 51 52 |
# File 'lib/puppet_x/eos/modules/ntp.rb', line 50 def initialize(api) @api = api end |
Instance Method Details
#add_server(name) ⇒ Boolean
Adds a new NTP server to the configured list
93 94 95 |
# File 'lib/puppet_x/eos/modules/ntp.rb', line 93 def add_server(name) @api.config("ntp server #{name}") == [{}] end |
#get ⇒ Hash
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": {...}
}
}
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# 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 |
#remove_server(name) ⇒ Boolean
Removes a previously configured interface from the Mlag domain
103 104 105 |
# File 'lib/puppet_x/eos/modules/ntp.rb', line 103 def remove_server(name) @api.config("no ntp server #{name}") == [{}] end |
#set_source_interface(opts = {}) ⇒ Boolean
Configures the ntp source interface
115 116 117 118 119 120 121 122 123 124 125 126 |
# 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 |