Class: Cisco::NtpAuthKey

Inherits:
NodeUtil show all
Defined in:
lib/cisco_node_utils/ntp_auth_key.rb

Overview

NtpAuthKey - node utility class for NTP authentication-key management

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NodeUtil

#client, client, #config_get, config_get, #config_get_default, config_get_default, config_set, #config_set, #get, #ios_xr?, #nexus?, node, #node, platform, #platform, supports?, #supports?

Constructor Details

#initialize(opts, instantiate = true) ⇒ NtpAuthKey


26
27
28
29
30
31
32
33
# File 'lib/cisco_node_utils/ntp_auth_key.rb', line 26

def initialize(opts, instantiate=true)
  @algorithm = opts['algorithm'].nil? ? 'md5' : opts['algorithm']
  @key = opts['name']
  @mode = opts['mode'].nil? ? '7' : opts['mode']
  @password = opts['password']

  create if instantiate
end

Instance Attribute Details

#algorithmObject (readonly)

Returns the value of attribute algorithm


24
25
26
# File 'lib/cisco_node_utils/ntp_auth_key.rb', line 24

def algorithm
  @algorithm
end

#modeObject (readonly)

Returns the value of attribute mode


24
25
26
# File 'lib/cisco_node_utils/ntp_auth_key.rb', line 24

def mode
  @mode
end

#passwordObject (readonly)

Returns the value of attribute password


24
25
26
# File 'lib/cisco_node_utils/ntp_auth_key.rb', line 24

def password
  @password
end

Class Method Details

.ntpkeysObject


35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cisco_node_utils/ntp_auth_key.rb', line 35

def self.ntpkeys
  keys = %w(name algorithm password mode)
  hash = {}
  ntp_auth_key_list = config_get('ntp_auth_key', 'key')
  return hash if ntp_auth_key_list.empty?

  ntp_auth_key_list.each do |id|
    hash[id[0]] = NtpAuthKey.new(Hash[keys.zip(id)], false)
  end

  hash
end

Instance Method Details

#==(other) ⇒ Object


48
49
50
# File 'lib/cisco_node_utils/ntp_auth_key.rb', line 48

def ==(other)
  name == other.name
end

#createObject


52
53
54
55
# File 'lib/cisco_node_utils/ntp_auth_key.rb', line 52

def create
  config_set('ntp_auth_key', 'key', state: '', key: @key,
              algorithm: @algorithm, password: @password, mode: @mode)
end

#destroyObject


57
58
59
60
61
# File 'lib/cisco_node_utils/ntp_auth_key.rb', line 57

def destroy
  # There appears to be a bug in NXOS that requires the password be passed
  config_set('ntp_auth_key', 'key', state: 'no', key: @key,
              algorithm: @algorithm, password: @password, mode: @mode)
end

#nameObject


63
64
65
# File 'lib/cisco_node_utils/ntp_auth_key.rb', line 63

def name
  @key
end