Class: Puppet::Provider::SnmpNotificationReceiver::CiscoIos
- Inherits:
-
ResourceApi::SimpleProvider
- Object
- ResourceApi::SimpleProvider
- Puppet::Provider::SnmpNotificationReceiver::CiscoIos
- Defined in:
- lib/puppet/provider/snmp_notification_receiver/cisco_ios.rb
Overview
SNMP Notification Receiver Puppet Provider for Cisco IOS devices
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, should) ⇒ Object
- #get(context, _names = nil) ⇒ Object
- #set(context, changes) ⇒ Object
- #update(context, _name, should) ⇒ Object (also: #create)
Class Method Details
.commands_from_instance(instance) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/puppet/provider/snmp_notification_receiver/cisco_ios.rb', line 38 def self.commands_from_instance(instance) # extract host instance[:name] = instance[:name][%r{(^\S*)}, 1] instance[:version] = instance[:version][%r{^v(\S*)}, 1] unless instance[:version].nil? array_of_commands = [] command = PuppetX::CiscoIOS::Utility.set_values(instance, commands_hash) # flip port to be udp-port command = command.to_s.gsub(%r{port}, 'udp-port') array_of_commands.push(command) array_of_commands end |
.commands_hash ⇒ Object
9 10 11 |
# File 'lib/puppet/provider/snmp_notification_receiver/cisco_ios.rb', line 9 def self.commands_hash @commands_hash ||= PuppetX::CiscoIOS::Utility.load_yaml(File.(__dir__) + '/command.yaml') end |
.instances_from_cli(output) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/puppet/provider/snmp_notification_receiver/cisco_ios.rb', line 13 def self.instances_from_cli(output) commands = PuppetX::CiscoIOS::Utility.load_yaml(File.(__dir__) + '/command.yaml') 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) new_instance[:ensure] = 'present' # making a composite key name_field = '' name_field += new_instance[:name] + ' ' unless new_instance[:name].nil? name_field += new_instance[:username] + ' ' unless new_instance[:username].nil? name_field += new_instance[:vrf] + ' ' unless new_instance[:vrf].nil? name_field += new_instance[:port] + ' ' unless new_instance[:port].nil? name_field.strip! new_instance[:name] = name_field new_instance[:version] = "v#{new_instance[:version]}" if !new_instance[:version].nil? && new_instance[:version][0] != 'v' 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 |
# File 'lib/puppet/provider/snmp_notification_receiver/cisco_ios.rb', line 95 def canonicalize(_context, resources) resources end |
#commands_hash ⇒ Object
34 35 36 |
# File 'lib/puppet/provider/snmp_notification_receiver/cisco_ios.rb', line 34 def commands_hash Puppet::Provider::SnmpNotificationReceiver::CiscoIos.commands_hash end |
#delete(context, name, should) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/puppet/provider/snmp_notification_receiver/cisco_ios.rb', line 81 def delete(context, name, should) clear_hash = { name: name, vrf: should[:vrf], ensure: 'absent', username: should[:username], port: should[:port] } array_of_commands_to_run = Puppet::Provider::SnmpNotificationReceiver::CiscoIos.commands_from_instance(clear_hash) array_of_commands_to_run.each do |command| context.transport.run_command_conf_t_mode(command) end end |
#get(context, _names = nil) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/puppet/provider/snmp_notification_receiver/cisco_ios.rb', line 50 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::SnmpNotificationReceiver::CiscoIos.instances_from_cli(output) PuppetX::CiscoIOS::Utility.enforce_simple_types(context, return_value) end |
#set(context, changes) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/puppet/provider/snmp_notification_receiver/cisco_ios.rb', line 57 def set(context, changes) changes.each do |name, change| should = change[:should] should = { name: name, ensure: 'absent' } if should.nil? if should[:ensure].to_s == 'present' context.updating(name) do update(context, name, should) end elsif should[:ensure].to_s == 'absent' context.deleting(name) do delete(context, name, should) end end end end |
#update(context, _name, should) ⇒ Object Also known as: create
74 75 76 77 78 79 |
# File 'lib/puppet/provider/snmp_notification_receiver/cisco_ios.rb', line 74 def update(context, _name, should) array_of_commands_to_run = Puppet::Provider::SnmpNotificationReceiver::CiscoIos.commands_from_instance(should) array_of_commands_to_run.each do |command| context.transport.run_command_conf_t_mode(command) end end |