Class: Puppet::Provider::NtpConfig::CiscoNexus
- Inherits:
-
Object
- Object
- Puppet::Provider::NtpConfig::CiscoNexus
- Defined in:
- lib/puppet/provider/ntp_config/cisco_nexus.rb
Overview
Implementation for the ntp_config type using the Resource API.
Instance Method Summary collapse
- #canonicalize(_context, resources) ⇒ Object
- #get(_context, _names = nil) ⇒ Object
- #handle_trusted_keys(should_trusted_keys) ⇒ Object
- #set(context, changes) ⇒ Object
- #update(context, name, should) ⇒ Object
- #validate_should(should) ⇒ Object
Instance Method Details
#canonicalize(_context, resources) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/puppet/provider/ntp_config/cisco_nexus.rb', line 18 def canonicalize(_context, resources) require 'cisco_node_utils' resources.each do |resource| resource[:trusted_key] = resource[:trusted_key].sort_by(&:to_i).map(&:to_s) if resource[:trusted_key] end resources end |
#get(_context, _names = nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/puppet/provider/ntp_config/cisco_nexus.rb', line 38 def get(_context, _names=nil) require 'cisco_node_utils' @ntp_config = Cisco::NtpConfig.ntpconfigs['default'] current_state = { name: 'default', authenticate: @ntp_config.authenticate ? true : false, source_interface: @ntp_config.source_interface ? @ntp_config.source_interface : 'unset', trusted_key: @ntp_config.trusted_key ? @ntp_config.trusted_key : ['unset'], } [current_state] end |
#handle_trusted_keys(should_trusted_keys) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/puppet/provider/ntp_config/cisco_nexus.rb', line 62 def handle_trusted_keys(should_trusted_keys) @ntp_config = Cisco::NtpConfig.ntpconfigs['default'] if should_trusted_keys == ['unset'] remove = @ntp_config.trusted_key.map(&:to_s) if @ntp_config.trusted_key elsif @ntp_config.trusted_key # Otherwise calculate the delta remove = @ntp_config.trusted_key.map(&:to_s).sort - should_trusted_keys.map(&:to_s).sort remove.delete('unset') end remove.each do |key| @ntp_config.trusted_key_set(false, key) unless key == 'unset' end if remove # Get array of keys to add return if should_trusted_keys == ['unset'] if @ntp_config.trusted_key add = should_trusted_keys.map(&:to_s).sort - @ntp_config.trusted_key.map(&:to_s).sort else add = should_trusted_keys.map(&:to_s).sort end remove.delete('unset') if remove add.each do |key| @ntp_config.trusted_key_set(true, key) end end |
#set(context, changes) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/puppet/provider/ntp_config/cisco_nexus.rb', line 27 def set(context, changes) changes.each do |name, change| is = change[:is] should = change[:should] if should != is update(context, name, should) end end end |
#update(context, name, should) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/puppet/provider/ntp_config/cisco_nexus.rb', line 53 def update(context, name, should) validate_should(should) context.notice("Updating '#{name}' with #{should.inspect}") @ntp_config = Cisco::NtpConfig.ntpconfigs[name] @ntp_config.authenticate = should[:authenticate] unless should[:authenticate].nil? @ntp_config.source_interface = should[:source_interface] == 'unset' ? nil : should[:source_interface] handle_trusted_keys(should[:trusted_key]) if should[:trusted_key] end |
#validate_should(should) ⇒ Object
90 91 92 93 94 |
# File 'lib/puppet/provider/ntp_config/cisco_nexus.rb', line 90 def validate_should(should) raise Puppet::ResourceError, 'Invalid name, `name` must be `default`' if should[:name] != 'default' raise Puppet::ResourceError, 'Invalid source interface, `source_interface` must not contain any spaces' if should[:source_interface] && should[:source_interface] =~ /\s+/ raise Puppet::ResourceError, 'Invalid source interface, `source_interface` must not contain any uppercase characters' if should[:source_interface] && should[:source_interface] =~ /[A-Z]+/ end |