Class: Puppet::Provider::RadiusGlobal::CiscoNexus
- Inherits:
-
Object
- Object
- Puppet::Provider::RadiusGlobal::CiscoNexus
- Defined in:
- lib/puppet/provider/radius_global/cisco_nexus.rb
Overview
Implementation for the radius_global type using the Resource API.
Instance Method Summary collapse
- #canonicalize(_context, resources) ⇒ Object
- #get(_context, _names = nil) ⇒ Object
- #munge(value) ⇒ 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 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/puppet/provider/radius_global/cisco_nexus.rb', line 18 def canonicalize(_context, resources) require 'cisco_node_utils' resources.each do |resource| resource[:key] = resource[:key].gsub(/\A"|"\Z/, '') if resource[:key] resource.each do |k, v| unless k == :key_format resource[k] = 'unset' if v.nil? || v == (nil || -1) end if k == :timeout && (v == 'unset' || v == -1) resource[k] = 5 end if k == :retransmit_count && (v == 'unset' || v == -1) resource[k] = 1 end end end resources end |
#get(_context, _names = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/puppet/provider/radius_global/cisco_nexus.rb', line 48 def get(_context, _names=nil) require 'cisco_node_utils' @radius_global = Cisco::RadiusGlobal.new('default') current_state = { name: 'default', timeout: @radius_global.timeout ? @radius_global.timeout : 'unset', retransmit_count: @radius_global.retransmit_count ? @radius_global.retransmit_count : 'unset', key: @radius_global.key ? @radius_global.key.gsub(/\A"|"\Z/, '') : 'unset', # Only return the key format if there is a key configured key_format: @radius_global.key.nil? || @radius_global.key.empty? ? nil : @radius_global.key_format, source_interface: @radius_global.source_interface.nil? || @radius_global.source_interface.empty? ? ['unset'] : [@radius_global.source_interface], } [current_state] end |
#munge(value) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/puppet/provider/radius_global/cisco_nexus.rb', line 81 def munge(value) if value.eql?('unset') nil else value end end |
#set(context, changes) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/puppet/provider/radius_global/cisco_nexus.rb', line 37 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
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/puppet/provider/radius_global/cisco_nexus.rb', line 65 def update(context, name, should) validate_should(should) context.notice("Updating '#{name}' with #{should.inspect}") @radius_global = Cisco::RadiusGlobal.new('default') [:retransmit_count, :source_interface, :timeout].each do |property| next unless should[property] # Other platforms require array for some types - Nexus does not should[property] = should[property][0] if should[property].is_a?(Array) should[property] = nil if should[property] == 'unset' @radius_global.send("#{property}=", should[property]) if @radius_global.respond_to?("#{property}=") end # Handle key and keyformat setting @radius_global.key_set(munge(should[:key]), should[:key_format]) end |
#validate_should(should) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/puppet/provider/radius_global/cisco_nexus.rb', line 89 def validate_should(should) raise Puppet::ResourceError, '`name` must be `default`' if should[:name] != 'default' raise Puppet::ResourceError, 'This provider does not support the `enable` property.' if should[:enable] raise Puppet::ResourceError, 'The `key` property must be set when specifying `key_format`.' if should[:key_format] && (!should[:key] || should[:key] == 'unset') raise Puppet::ResourceError, 'This provider does not support the `vrf` property.' if should[:vrf] end |