Class: PuppetX::Eos::Ntp

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(api) ⇒ PuppetX::Eos::Ntp

Initialize instance of Snmp

Parameters:



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

Parameters:

  • name (String)

    The name of the interface to add

Returns:

  • (Boolean)

    True if the command succeeds otherwise False



93
94
95
# File 'lib/puppet_x/eos/modules/ntp.rb', line 93

def add_server(name)
  @api.config("ntp server #{name}") == [{}]
end

#getHash

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": {...}
  }
}

Returns:

  • (Hash)

    returns a Hash of attributes derived from eAPI



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

Parameters:

  • name (String)

    The name of the interface to remove

Returns:

  • (Boolean)

    True if the command succeeds otherwise False



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

Parameters:

  • opts (Hash) (defaults to: {})

    The configuration parameters for mlag

Options Hash (opts):

  • :value (string)

    The value to set the domain-id to

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



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