Class: Puppet::Provider::RadiusServer::CiscoNexus
- Inherits:
-
ResourceApi::SimpleProvider
- Object
- ResourceApi::SimpleProvider
- Puppet::Provider::RadiusServer::CiscoNexus
- Defined in:
- lib/puppet/provider/radius_server/cisco_nexus.rb
Overview
Implementation for the radius_server type using the Resource API.
Instance Method Summary collapse
- #canonicalize(_context, resources) ⇒ Object
- #create(context, name, should) ⇒ Object
- #create_update(name, should, create_bool) ⇒ Object
- #delete(context, name) ⇒ Object
- #get(context, _names = nil) ⇒ Object
- #munge_flush(val) ⇒ Object
- #update(context, name, should) ⇒ Object
- #validate(should) ⇒ Object
Instance Method Details
#canonicalize(_context, resources) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/puppet/provider/radius_server/cisco_nexus.rb', line 25 def canonicalize(_context, resources) resources.each do |resource| resource[:key] = resource[:key].gsub(/\A"|"\Z/, '') if resource[:key] resource[:key] = 'unset' if resource[:key].nil? resource[:timeout] = 'unset' if resource[:timeout].nil? || resource[:timeout] == (nil || -1) resource[:key_format] = 'unset' if resource[:key_format].nil? || resource[:key_format] == (nil || -1) resource[:retransmit_count] = 'unset' if resource[:retransmit_count].nil? || resource[:retransmit_count] == (nil || -1) end resources end |
#create(context, name, should) ⇒ Object
115 116 117 118 |
# File 'lib/puppet/provider/radius_server/cisco_nexus.rb', line 115 def create(context, name, should) context.notice("Creating '#{name}' with #{should.inspect}") create_update(name, should, true) end |
#create_update(name, should, create_bool) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/puppet/provider/radius_server/cisco_nexus.rb', line 101 def create_update(name, should, create_bool) validate(should) radius_server = Cisco::RadiusServer.new(name, create_bool) RADIUS_SERVER_PROPS.each do |puppet_prop, cisco_prop| if !should[puppet_prop].nil? && radius_server.respond_to?("#{cisco_prop}=") radius_server.send("#{cisco_prop}=", munge_flush(should[puppet_prop])) end end # Handle key and keyformat setting return unless should[:key] radius_server.send('key_set', munge_flush(should[:key]), munge_flush(should[:key_format])) end |
#delete(context, name) ⇒ Object
125 126 127 128 129 |
# File 'lib/puppet/provider/radius_server/cisco_nexus.rb', line 125 def delete(context, name) context.notice("Deleting '#{name}'") radius_server = Cisco::RadiusServer.new(name, false) radius_server.destroy end |
#get(context, _names = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/puppet/provider/radius_server/cisco_nexus.rb', line 47 def get(context, _names=nil) require 'cisco_node_utils' radius_servers = [] Cisco::RadiusServer.radiusservers.each_value do |v| radius_servers << { ensure: 'present', name: v.name, auth_port: v.auth_port ? v.auth_port : nil, acct_port: v.acct_port ? v.acct_port : nil, timeout: v.timeout ? v.timeout : 'unset', retransmit_count: v.retransmit_count ? v.retransmit_count : 'unset', key: v.key ? v.key.gsub(/\A"|"\Z/, '') : 'unset', key_format: v.key_format ? v.key_format.to_i : 'unset', accounting_only: v.accounting, authentication_only: v.authentication } end PuppetX::Cisco::Utils.enforce_simple_types(context, radius_servers) end |
#munge_flush(val) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/puppet/provider/radius_server/cisco_nexus.rb', line 69 def munge_flush(val) if val.is_a?(String) && val.eql?('unset') nil elsif val.is_a?(Integer) && val.eql?(-1) nil elsif val.is_a?(Symbol) val.to_s else val end end |
#update(context, name, should) ⇒ Object
120 121 122 123 |
# File 'lib/puppet/provider/radius_server/cisco_nexus.rb', line 120 def update(context, name, should) context.notice("Updating '#{name}' with #{should.inspect}") create_update(name, should, false) end |
#validate(should) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/puppet/provider/radius_server/cisco_nexus.rb', line 81 def validate(should) raise Puppet::ResourceError, "This provider does not support the 'hostname' property. The namevar should be set to the IP of the Radius Server" \ if should[:hostname] invalid = [] UNSUPPORTED_PROPS.each do |prop| invalid << prop if should[prop] end raise Puppet::ResourceError, "This provider does not support the following properties: #{invalid}" unless invalid.empty? raise Puppet::ResourceError, "The 'key' property must be set when specifying 'key_format'." if should[:key_format] && !should[:key] raise Puppet::ResourceError, "The 'accounting_only' and 'authentication_only' properties cannot both be set to false." if munge_flush(should[:accounting_only]) == false && \ munge_flush(should[:authentication_only]) == false end |