Class: Rbeapi::Api::Ntp

Inherits:
Entity
  • Object
show all
Defined in:
lib/rbeapi/api/ntp.rb

Overview

The Ntp class provides an instance for working with the nodes NTP configuration.

Constant Summary collapse

DEFAULT_SRC_INTF =
''.freeze

Instance Attribute Summary

Attributes inherited from Entity

#config, #error, #node

Instance Method Summary collapse

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) ⇒ 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.

Parameters:

  • server (String)

    The IP address or FQDN of the NTP server to be removed from the configuration.

  • prefer (Boolean) (defaults to: false)

    Appends the prefer keyword argument to the command if this value is true.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.



145
146
147
148
149
# File 'lib/rbeapi/api/ntp.rb', line 145

def add_server(server, prefer = false)
  cmd = "ntp server #{server}"
  cmd << ' prefer' if prefer
  configure cmd
end

#getnil, Hash<Symbol, Object>

get returns the nodes current ntp configure as a resource hash.

Examples:

{
  source_interface: <string>,
  servers: {
    prefer: [true, false]
  }
}

Returns:

  • (nil, Hash<Symbol, Object>)

    Returns the ntp resource as a Hash.



59
60
61
62
63
64
# File 'lib/rbeapi/api/ntp.rb', line 59

def get
  response = {}
  response.merge!(parse_source_interface)
  response.merge!(parse_servers)
  response
end

#remove_server(server) ⇒ 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

Parameters:

  • server (String)

    The IP address or FQDN of the NTP server to be removed from the configuration.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.



160
161
162
# File 'lib/rbeapi/api/ntp.rb', line 160

def remove_server(server)
  configure("no ntp server #{server}")
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

Parameters:

  • srv (String)

    The IP address or hostname of the ntp server to configure with the prefer value.

  • value (Boolean)

    The value to configure for prefer. If true the prefer value is configured for the server. If false, then the prefer value is removed.

Returns:

  • (Boolean)

    Returns true if the commands completed successfully.

Since:

  • eos_version 4.13.7M



183
184
185
186
187
188
189
190
191
# File 'lib/rbeapi/api/ntp.rb', line 183

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

Parameters:

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

    Optional keyword arguments.

Options Hash (opts):

  • value (String)

    The value to configure the ntp source in the nodes configuration.

  • enable (Boolean)

    If false then the command is negated. Default is true.

  • default (Boolean)

    Configure the ntp source value using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



127
128
129
130
# File 'lib/rbeapi/api/ntp.rb', line 127

def set_source_interface(opts = {})
  cmd = command_builder('ntp source', opts)
  configure(cmd)
end