Class: Puppet::Provider::TacacsGlobal::CiscoNexus
- Inherits:
-
Object
- Object
- Puppet::Provider::TacacsGlobal::CiscoNexus
- Defined in:
- lib/puppet/provider/tacacs_global/cisco_nexus.rb
Overview
Implementation for the tacacs_global type using the Resource API.
Instance Method Summary collapse
- #canonicalize(_context, resources) ⇒ Object
- #get(_context, _tacacs = 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 |
# File 'lib/puppet/provider/tacacs_global/cisco_nexus.rb', line 18 def canonicalize(_context, resources) resources.each do |resource| if resource[:key] resource[:key] = resource[:key].gsub(/\A"|"\Z/, '') else resource[:key] = 'unset' end unless resource[:timeout] resource[:timeout] = 'unset' end resource.each do |k, v| unless k == :key_format resource[k] = 'unset' if v.nil? || v == (nil || -1) end end end end |
#get(_context, _tacacs = nil) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/puppet/provider/tacacs_global/cisco_nexus.rb', line 59 def get(_context, _tacacs=nil) require 'cisco_node_utils' @tacacs_global = Cisco::TacacsGlobal.tacacs_global current_states = [] @tacacs_global.each do |name, instance| current_states << { name: name, timeout: instance.timeout ? instance.timeout.to_i : 'unset', key: instance.key.nil? || instance.key.empty? ? 'unset' : instance.key.gsub(/\A"|"\Z/, ''), # Only return the key format if there is a key configured key_format: instance.key.nil? || instance.key.empty? || instance.key == 'unset' ? nil : instance.key_format, # source_interface for NXOS devices will be singular, type however is for an array source_interface: instance.source_interface.nil? || instance.source_interface.empty? ? ['unset'] : [instance.source_interface], } end current_states end |
#munge(value) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/puppet/provider/tacacs_global/cisco_nexus.rb', line 36 def munge(value) if value.nil? nil elsif value.is_a?(String) && value.eql?('unset') nil elsif value.is_a?(Integer) && value.eql?(-1) nil else value end end |
#set(context, changes) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/puppet/provider/tacacs_global/cisco_nexus.rb', line 48 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
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/puppet/provider/tacacs_global/cisco_nexus.rb', line 82 def update(context, name, should) validate_should(should) context.notice("Updating '#{name}' with #{should.inspect}") @tacacs_global = Cisco::TacacsGlobal.tacacs_global [:timeout, :source_interface].each do |property| next unless should[property] should[property] = munge(should[property][0]) if should[property].is_a?(Array) @tacacs_global[name].send("#{property}=", should[property]) if @tacacs_global[name].respond_to?("#{property}=") end @tacacs_global[name].encryption_key_set(munge(should[:key_format]), munge(should[:key])) unless should[:key].nil? end |
#validate_should(should) ⇒ Object
77 78 79 80 |
# File 'lib/puppet/provider/tacacs_global/cisco_nexus.rb', line 77 def validate_should(should) raise Puppet::ResourceError, "This provider only supports namevar of 'default'." unless should[:name] == 'default' raise Puppet::ResourceError, "The 'key' property must be set when specifying 'key_format'." if should[:key_format] && !should[:key] end |