Class: Puppet::Provider::NtpAuthKey::CiscoNexus

Inherits:
ResourceApi::SimpleProvider
  • Object
show all
Defined in:
lib/puppet/provider/ntp_auth_key/cisco_nexus.rb

Overview

Implementation for the ntp_auth_key type using the Resource API.

Instance Method Summary collapse

Instance Method Details

#canonicalize(_context, resources) ⇒ Object



18
19
20
# File 'lib/puppet/provider/ntp_auth_key/cisco_nexus.rb', line 18

def canonicalize(_context, resources)
  resources
end

#delete(context, name) ⇒ Object



63
64
65
66
67
# File 'lib/puppet/provider/ntp_auth_key/cisco_nexus.rb', line 63

def delete(context, name)
  context.notice("Destroying '#{name}'")
  @ntpkeys = Cisco::NtpAuthKey.ntpkeys
  @ntpkeys[name].destroy
end

#get(_context, keys = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/puppet/provider/ntp_auth_key/cisco_nexus.rb', line 22

def get(_context, keys=nil)
  require 'cisco_node_utils'
  current_states = []
  if keys.nil? || keys.empty?
    @ntpkeys = Cisco::NtpAuthKey.ntpkeys
    @ntpkeys.each do |key, instance|
      current_states << get_current_state(key, instance)
    end
  else
    keys.each do |key|
      @ntpkeys = Cisco::NtpAuthKey.ntpkeys
      instance = @ntpkeys[key]
      next if instance.nil?
      current_states << get_current_state(instance.name, instance)
    end
  end
  current_states
end

#get_current_state(name, instance) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/puppet/provider/ntp_auth_key/cisco_nexus.rb', line 41

def get_current_state(name, instance)
  {
    name:      name,
    ensure:    'present',
    algorithm: instance.algorithm,
    mode:      instance.mode.to_i,
    password:  instance.password,
  }
end

#update(context, name, should) ⇒ Object Also known as: create



51
52
53
54
55
56
57
58
59
# File 'lib/puppet/provider/ntp_auth_key/cisco_nexus.rb', line 51

def update(context, name, should)
  validate_should(should)
  context.notice("Setting '#{name}' with #{should.inspect}")
  options = { 'name' => name }
  [:algorithm, :mode, :password].each do |option|
    options[option.to_s] = should[option] if should[option]
  end
  Cisco::NtpAuthKey.new(options)
end

#validate_should(should) ⇒ Object

Raises:

  • (Puppet::ResourceError)


69
70
71
72
73
# File 'lib/puppet/provider/ntp_auth_key/cisco_nexus.rb', line 69

def validate_should(should)
  raise Puppet::ResourceError, 'Invalid name, must be 1-65535' if should[:name].to_i > 65_535 || should[:name].to_i.zero?
  raise Puppet::ResourceError, 'Invalid password length, max length is 15' if should[:password] && should[:password].length > 15
  raise Puppet::ResourceError, 'Invalid mode, supported modes are 0 and 7' if should[:mode] && ![0, 7].include?(should[:mode])
end