Class: Puppet::Provider::SnmpNotification::CiscoIos
- Inherits:
-
Object
- Object
- Puppet::Provider::SnmpNotification::CiscoIos
- Defined in:
- lib/puppet/provider/snmp_notification/cisco_ios.rb
Overview
SNMP Notification Puppet Provider for Cisco IOS devices
Class Method Summary collapse
- .commands_from_instance(property_hash) ⇒ 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(property_hash) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/puppet/provider/snmp_notification/cisco_ios.rb', line 33 def self.commands_from_instance(property_hash) commands_array = [] command = PuppetX::CiscoIOS::Utility.set_values(property_hash, commands_hash) command = command.to_s.gsub(%r{^snmp-server}, 'no snmp-server') command = command.to_s.gsub(%r{true }, '') commands_array.push(command) commands_array end |
.commands_hash ⇒ Object
8 9 10 |
# File 'lib/puppet/provider/snmp_notification/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 21 22 23 24 25 26 27 |
# File 'lib/puppet/provider/snmp_notification/cisco_ios.rb', line 12 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[:enable] = if new_instance[:enable].nil? true else false end 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
79 80 81 |
# File 'lib/puppet/provider/snmp_notification/cisco_ios.rb', line 79 def canonicalize(_context, resources) resources end |
#commands_hash ⇒ Object
29 30 31 |
# File 'lib/puppet/provider/snmp_notification/cisco_ios.rb', line 29 def commands_hash Puppet::Provider::SnmpNotification::CiscoIos.commands_hash end |
#delete(context, _name, should) ⇒ Object
77 |
# File 'lib/puppet/provider/snmp_notification/cisco_ios.rb', line 77 def delete(context, _name, should); end |
#get(context, names = nil) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/puppet/provider/snmp_notification/cisco_ios.rb', line 42 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::SnmpNotification::CiscoIos.instances_from_cli(output) if names && !names.empty? instances_by_name = Hash[return_value.map { |v| [v[:name], v] }] # When trying to disable snmp_notifications that are already disabled, puppet does not create a proper # `ensure => absent` resource, because netdev_stdlib types are not ensurable. # This leads to annoying/buggy "Snmp_notification[X]: changed 'enable' property from to 'false'" # messages and useless calls to the provider. # If we get passed a `name` we can work around this by synthesising a disabled resource. names.each { |n| instances_by_name[n] ||= { name: n, enable: false } } return_value = instances_by_name.values end PuppetX::CiscoIOS::Utility.enforce_simple_types(context, return_value) end |
#set(context, changes) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/puppet/provider/snmp_notification/cisco_ios.rb', line 59 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 Also known as: create
68 69 70 71 72 73 |
# File 'lib/puppet/provider/snmp_notification/cisco_ios.rb', line 68 def update(context, _name, should) array_of_commands_to_run = Puppet::Provider::SnmpNotification::CiscoIos.commands_from_instance(should) array_of_commands_to_run.each do |command| context.transport.run_command_conf_t_mode(command) end end |