Class: Puppet::Provider::IosRadiusServerGroup::CiscoIos
- Inherits:
-
Object
- Object
- Puppet::Provider::IosRadiusServerGroup::CiscoIos
- Defined in:
- lib/puppet/provider/ios_radius_server_group/cisco_ios.rb
Overview
Configure rad of the device
Class Method Summary collapse
- .commands_from_instance(property_hash) ⇒ Object
- .commands_from_is_should(is, should) ⇒ Object
- .commands_hash ⇒ Object
- .instances_from_cli(output) ⇒ Object
Instance Method Summary collapse
- #canonicalize(_context, resources) ⇒ Object
- #commands_hash ⇒ Object
- #create(context, name, is, should) ⇒ Object (also: #update)
- #delete(context, name) ⇒ Object
- #get(context, _names = nil) ⇒ Object
- #set(context, changes) ⇒ Object
Class Method Details
.commands_from_instance(property_hash) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/puppet/provider/ios_radius_server_group/cisco_ios.rb', line 27 def self.commands_from_instance(property_hash) commands_array = [] # servers are special property_hash[:servers] = nil unless property_hash[:servers].nil? property_hash[:private_servers] = nil unless property_hash[:private_servers].nil? command = PuppetX::CiscoIOS::Utility.set_values(property_hash, commands_hash) commands_array.push(command) commands_array end |
.commands_from_is_should(is, should) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/puppet/provider/ios_radius_server_group/cisco_ios.rb', line 37 def self.commands_from_is_should(is, should) array_of_commands = [] array_of_commands += PuppetX::CiscoIOS::Utility.commands_from_diff_of_two_arrays(commands_hash, is[:servers], should[:servers], 'servers') array_of_commands += PuppetX::CiscoIOS::Utility.commands_from_diff_of_two_arrays(commands_hash, is[:private_servers], should[:private_servers], 'private_servers') array_of_commands end |
.commands_hash ⇒ Object
6 7 8 9 10 |
# File 'lib/puppet/provider/ios_radius_server_group/cisco_ios.rb', line 6 def self.commands_hash local_commands_hash = PuppetX::CiscoIOS::Utility.load_yaml(File.(__dir__) + '/command.yaml') radius_server_group_commands_hash ||= PuppetX::CiscoIOS::Utility.load_yaml(File.(__dir__) + '/../radius_server_group/command.yaml') @commands_hash = local_commands_hash.merge(radius_server_group_commands_hash) { |_key, oldval, newval| (oldval.to_a + newval.to_a).to_h } end |
.instances_from_cli(output) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/puppet/provider/ios_radius_server_group/cisco_ios.rb', line 12 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[:ensure] = 'present' new_instance[:servers] = [].push(new_instance[:servers]) if new_instance[:servers].is_a?(String) new_instance[:private_servers] = [].push(new_instance[:private_servers]) if new_instance[:private_servers].is_a?(String) new_instance[:servers] = new_instance[:servers].sort if new_instance[:servers] new_instance[:private_servers] = new_instance[:private_servers].sort if new_instance[:private_servers] 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
95 96 97 98 99 100 |
# File 'lib/puppet/provider/ios_radius_server_group/cisco_ios.rb', line 95 def canonicalize(_context, resources) resources.each do |resource| resource[:servers] = resource[:servers].sort if resource[:servers] resource[:private_servers] = resource[:private_servers].sort if resource[:private_servers] end end |
#commands_hash ⇒ Object
44 45 46 |
# File 'lib/puppet/provider/ios_radius_server_group/cisco_ios.rb', line 44 def commands_hash Puppet::Provider::IosRadiusServerGroup::CiscoIos.commands_hash end |
#create(context, name, is, should) ⇒ Object Also known as: update
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/puppet/provider/ios_radius_server_group/cisco_ios.rb', line 80 def create(context, name, is, should) saved_should = Marshal.load(Marshal.dump(should)) array_of_commands_to_run = Puppet::Provider::IosRadiusServerGroup::CiscoIos.commands_from_instance(should) array_of_commands_to_run.each do |command| context.transport.run_command_conf_t_mode(command) end # only called if adding/removing servers array_of_commands_to_run = Puppet::Provider::IosRadiusServerGroup::CiscoIos.commands_from_is_should(is, saved_should) array_of_commands_to_run.each do |command| context.transport.run_command_radius_mode(name, command) end end |
#delete(context, name) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/puppet/provider/ios_radius_server_group/cisco_ios.rb', line 73 def delete(context, name) array_of_commands_to_run = Puppet::Provider::IosRadiusServerGroup::CiscoIos.commands_from_instance(name: name, ensure: 'absent') array_of_commands_to_run.each do |command| context.transport.run_command_conf_t_mode(command) end end |
#get(context, _names = nil) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/puppet/provider/ios_radius_server_group/cisco_ios.rb', line 48 def get(context, _names = nil) output = context.transport.run_command_enable_mode(PuppetX::CiscoIOS::Utility.get_values(commands_hash)) return [] if output.nil? return_value = Puppet::Provider::IosRadiusServerGroup::CiscoIos.instances_from_cli(output) PuppetX::CiscoIOS::Utility.enforce_simple_types(context, return_value) end |
#set(context, changes) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/puppet/provider/ios_radius_server_group/cisco_ios.rb', line 55 def set(context, changes) changes.each do |name, change| is = change.key?(:is) ? change[:is] : (get(context) || []).find { |r| r[:name] == name } should = change[:should] is = { name: name, ensure: 'absent' } if is.nil? should = { name: name, ensure: 'absent' } if should.nil? if should[:ensure].to_s == 'present' context.updating(name) do create(context, name, is, should) end elsif is[:ensure].to_s == 'present' && should[:ensure].to_s == 'absent' context.deleting(name) do delete(context, name) end end end end |