Class: Puppet::Provider::IosAaaAuthorization::CiscoIos
- Inherits:
-
Object
- Object
- Puppet::Provider::IosAaaAuthorization::CiscoIos
- Defined in:
- lib/puppet/provider/ios_aaa_authorization/cisco_ios.rb
Overview
Configure AAA Authorization on the device
Class Method Summary collapse
- .commands_from_instance(instance) ⇒ Object
- .commands_hash ⇒ Object
- .instances_from_cli(output) ⇒ Object
Instance Method Summary collapse
- #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
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/puppet/provider/ios_aaa_authorization/cisco_ios.rb', line 38 def self.commands_from_instance(instance) # if service is commands but enable level is not specified, we need to fail raise "ios_aaa_authorization requires commands_enable_level to be set if authorization_service is 'commands'" if !instance[:authorization_service].nil? && instance[:authorization_service].to_s == 'commands' && instance[:commands_enable_level].nil? if !instance[:authorization_service].nil? && instance[:authorization_service].to_s == 'commands' && instance[:commands_enable_level] instance[:authorization_service] = "#{instance[:authorization_service]} #{instance[:commands_enable_level]}" end commands = [] instance[:if_authenticated] = if instance[:if_authenticated] ' if-authenticated' else '' end instance[:local] = if instance[:local] ' local' else '' 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_authorization/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 |
# File 'lib/puppet/provider/ios_aaa_authorization/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) new_instance[:name] = (new_instance[:authorization_service]).to_s if new_instance[:authorization_service] == 'commands' && new_instance[:commands_enable_level] new_instance[:name] = new_instance[:name] + " #{new_instance[:commands_enable_level]}" end new_instance[:name] = new_instance[:name] + " #{new_instance[:authorization_list]}" new_instance[:local] = if new_instance[:local] true else false end new_instance[:if_authenticated] = if new_instance[:if_authenticated] true else false 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
#commands_hash ⇒ Object
67 68 69 |
# File 'lib/puppet/provider/ios_aaa_authorization/cisco_ios.rb', line 67 def commands_hash Puppet::Provider::IosAaaAuthorization::CiscoIos.commands_hash end |
#delete(context, _name, is) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/puppet/provider/ios_aaa_authorization/cisco_ios.rb', line 101 def delete(context, _name, is) is[:ensure] = 'absent' array_of_commands_to_run = Puppet::Provider::IosAaaAuthorization::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
71 72 73 74 75 76 |
# File 'lib/puppet/provider/ios_aaa_authorization/cisco_ios.rb', line 71 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::IosAaaAuthorization::CiscoIos.instances_from_cli(output) PuppetX::CiscoIOS::Utility.enforce_simple_types(context, return_value) end |
#set(context, changes) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/puppet/provider/ios_aaa_authorization/cisco_ios.rb', line 78 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
94 95 96 97 98 99 |
# File 'lib/puppet/provider/ios_aaa_authorization/cisco_ios.rb', line 94 def update(context, _name, should) array_of_commands_to_run = Puppet::Provider::IosAaaAuthorization::CiscoIos.commands_from_instance(should) array_of_commands_to_run.each do |command| context.transport.run_command_conf_t_mode(command) end end |