Class: Puppet::Provider::RadiusGlobal::CiscoIos
- Inherits:
-
Object
- Object
- Puppet::Provider::RadiusGlobal::CiscoIos
- Defined in:
- lib/puppet/provider/radius_global/cisco_ios.rb
Overview
Configure the domain name of 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
- #get(context, _names = nil) ⇒ Object
- #set(context, changes) ⇒ Object
- #update(context, _name, should) ⇒ Object
Class Method Details
.commands_from_instance(instance) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/puppet/provider/radius_global/cisco_ios.rb', line 22 def self.commands_from_instance(instance) commands = [] # if key exists but not key_format, we need to fail raise 'radius_global requires key_format to be set if setting key' if !instance[:key].nil? && instance[:key_format].nil? unless instance[:key].nil? # build a single command for key_format + key if PuppetX::CiscoIOS::Utility.attribute_safe_to_run(commands_hash, 'key') && PuppetX::CiscoIOS::Utility.attribute_safe_to_run(commands_hash, 'key_format') command = PuppetX::CiscoIOS::Utility.attribute_value_foraged_from_command_hash(commands_hash, 'key', 'set_value') command = PuppetX::CiscoIOS::Utility.insert_attribute_into_command_line(command, 'key_format', instance[:key_format], false) command = PuppetX::CiscoIOS::Utility.insert_attribute_into_command_line(command, 'key', instance[:key], false) commands.push(command) end # remove key and key_format, so we dont add twice instance.delete(:key_format) instance.delete(:key) end raise 'radius_global only accepts a single source_interface' if !instance[:source_interface].nil? && instance[:source_interface].size != 1 instance[:source_interface] = instance[:source_interface].first unless instance[:source_interface].nil? commands += PuppetX::CiscoIOS::Utility.build_commmands_from_attribute_set_values(instance, commands_hash) commands end |
.commands_hash ⇒ Object
8 9 10 |
# File 'lib/puppet/provider/radius_global/cisco_ios.rb', line 8 def self.commands_hash @commands_hash ||= PuppetX::CiscoIOS::Utility.load_yaml(File.(__dir__) + '/command.yaml') end |
.instances_from_cli(output) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/puppet/provider/radius_global/cisco_ios.rb', line 12 def self.instances_from_cli(output) new_instance_fields = [] new_instance = PuppetX::CiscoIOS::Utility.parse_resource(output, commands_hash) new_instance[:name] = 'default' new_instance[:source_interface] = [].push(new_instance[:source_interface]) if new_instance[:source_interface].is_a?(String) new_instance.delete_if { |_k, v| v.nil? } new_instance_fields << new_instance new_instance_fields end |
Instance Method Details
#canonicalize(_context, resources) ⇒ Object
71 72 73 |
# File 'lib/puppet/provider/radius_global/cisco_ios.rb', line 71 def canonicalize(_context, resources) resources end |
#commands_hash ⇒ Object
44 45 46 |
# File 'lib/puppet/provider/radius_global/cisco_ios.rb', line 44 def commands_hash Puppet::Provider::RadiusGlobal::CiscoIos.commands_hash end |
#get(context, _names = nil) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/puppet/provider/radius_global/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::RadiusGlobal::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 |
# File 'lib/puppet/provider/radius_global/cisco_ios.rb', line 55 def set(context, changes) changes.each do |name, change| should = change[:should] context.updating(name) do update(context, name, should) end end end |
#update(context, _name, should) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/puppet/provider/radius_global/cisco_ios.rb', line 64 def update(context, _name, should) array_of_commands_to_run = Puppet::Provider::RadiusGlobal::CiscoIos.commands_from_instance(should) array_of_commands_to_run.each do |command| context.transport.run_command_conf_t_mode(command) end end |