Class: Puppet::Provider::IosAaaAuthentication::CiscoIos
- Inherits:
-
Object
- Object
- Puppet::Provider::IosAaaAuthentication::CiscoIos
- Defined in:
- lib/puppet/provider/ios_aaa_authentication/cisco_ios.rb
Overview
Configure AAA Authentication on the device
Class Method Summary collapse
- .commands_from_instance(instance) ⇒ Object
- .commands_hash ⇒ Object
- .instances_from_cli(output) ⇒ Object
Instance Method Summary collapse
- #canonicalize(_context, resources) ⇒ Object
- #commands_hash ⇒ Object
- #delete(context, _name, is) ⇒ Object
- #get(context) ⇒ Object
- #set(context, changes) ⇒ Object
- #update(context, _name, should) ⇒ Object
Class Method Details
.commands_from_instance(instance) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/puppet/provider/ios_aaa_authentication/cisco_ios.rb', line 48 def self.commands_from_instance(instance) commands = [] instance[:enable_password] = if instance[:enable_password] ' enable' else '' end instance[:local] = if instance[:local] ' local' else '' end if instance[:suppress_null_username] instance[:authentication_list] = 'null-username' elsif instance[:authentication_list_set].casecmp('suppress').zero? raise 'Cannot set suppress without a type of user. Is this device compatible?' end instance[:server_groups] = PuppetX::CiscoIOS::Utility.generate_server_groups_command_string(instance) command = PuppetX::CiscoIOS::Utility.set_values(instance, commands_hash) if instance[:ensure].to_s == 'absent' command = 'no ' + command end commands << command commands end |
.commands_hash ⇒ Object
6 7 8 |
# File 'lib/puppet/provider/ios_aaa_authentication/cisco_ios.rb', line 6 def self.commands_hash @commands_hash ||= PuppetX::CiscoIOS::Utility.load_yaml(File.(__dir__) + '/command.yaml') end |
.instances_from_cli(output) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/puppet/provider/ios_aaa_authentication/cisco_ios.rb', line 10 def self.instances_from_cli(output) new_instance_fields = [] output.scan(%r{#{PuppetX::CiscoIOS::Utility.get_instances(commands_hash)}}).each do |raw_instance_fields| new_instance = PuppetX::CiscoIOS::Utility.parse_resource(raw_instance_fields, commands_hash) if new_instance[:authentication_list_set] == 'suppress' if new_instance[:suppress_null_username] new_instance[:name] = "#{new_instance[:authentication_list_set]} null-username" end else new_instance[:name] = "#{new_instance[:authentication_list_set]} #{new_instance[:authentication_list]}" end new_instance[:enable_password] = if new_instance[:enable_password] true else false end new_instance[:local] = if new_instance[:local] true else false end new_instance[:switch_auth] = if new_instance[:switch_auth] true else false end new_instance[:suppress_null_username] = if new_instance[:suppress_null_username] true end # Convert any single items to expected array new_instance[:server_groups] = [new_instance[:server_groups]].flatten(1) unless new_instance[:server_groups].nil? new_instance[:ensure] = 'present' new_instance.delete_if { |_k, v| v.nil? } new_instance_fields << new_instance end new_instance_fields end |
Instance Method Details
#canonicalize(_context, resources) ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/puppet/provider/ios_aaa_authentication/cisco_ios.rb', line 116 def canonicalize(_context, resources) resources.each do |resource| resource[:cache_groups] = resource[:cache_groups].sort if resource[:cache_groups] resource[:server_groups] = resource[:server_groups].sort if resource[:server_groups] end resources end |
#commands_hash ⇒ Object
74 75 76 |
# File 'lib/puppet/provider/ios_aaa_authentication/cisco_ios.rb', line 74 def commands_hash Puppet::Provider::IosAaaAuthentication::CiscoIos.commands_hash end |
#delete(context, _name, is) ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/puppet/provider/ios_aaa_authentication/cisco_ios.rb', line 108 def delete(context, _name, is) is[:ensure] = 'absent' array_of_commands_to_run = Puppet::Provider::IosAaaAuthentication::CiscoIos.commands_from_instance(is) array_of_commands_to_run.each do |command| context.transport.run_command_conf_t_mode(command) end end |
#get(context) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/puppet/provider/ios_aaa_authentication/cisco_ios.rb', line 78 def get(context) output = context.transport.run_command_enable_mode(PuppetX::CiscoIOS::Utility.get_values(commands_hash)) return [] if output.nil? return_value = Puppet::Provider::IosAaaAuthentication::CiscoIos.instances_from_cli(output) PuppetX::CiscoIOS::Utility.enforce_simple_types(context, return_value) end |
#set(context, changes) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/puppet/provider/ios_aaa_authentication/cisco_ios.rb', line 85 def set(context, changes) changes.each do |name, change| is = change.key?(:is) ? change[:is] : (get(context) || []).find { |key| key[:name] == name } should = change[:should] if should[:ensure].to_s == 'absent' context.deleting(name) do delete(context, name, is) end else context.updating(name) do update(context, name, should) end end end end |
#update(context, _name, should) ⇒ Object
101 102 103 104 105 106 |
# File 'lib/puppet/provider/ios_aaa_authentication/cisco_ios.rb', line 101 def update(context, _name, should) array_of_commands_to_run = Puppet::Provider::IosAaaAuthentication::CiscoIos.commands_from_instance(should) array_of_commands_to_run.each do |command| context.transport.run_command_conf_t_mode(command) end end |