Class: Puppet::Provider::NetworkSnmp::CiscoIos
- Inherits:
-
Object
- Object
- Puppet::Provider::NetworkSnmp::CiscoIos
- Defined in:
- lib/puppet/provider/network_snmp/cisco_ios.rb
Overview
Network SNMP 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
- #get(context, _names = nil) ⇒ Object
- #set(context, changes) ⇒ Object
- #update(context, _name, should) ⇒ Object
Class Method Details
.commands_from_instance(property_hash) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/puppet/provider/network_snmp/cisco_ios.rb', line 23 def self.commands_from_instance(property_hash) commands_array = [] if property_hash[:enable] == false # when disabling, dont change the other attributes property_hash = { enable: false } else # we dont enable we only disable property_hash.delete(:enable) end commands_array += PuppetX::CiscoIOS::Utility.build_commmands_from_attribute_set_values(property_hash, commands_hash) commands_array end |
.commands_hash ⇒ Object
8 9 10 |
# File 'lib/puppet/provider/network_snmp/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 |
# File 'lib/puppet/provider/network_snmp/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.delete_if { |_k, v| v.nil? } # if only name is populated, snmp is disabled new_instance[:enable] = new_instance.size != 1 new_instance_fields << new_instance new_instance_fields end |
Instance Method Details
#canonicalize(_context, resources) ⇒ Object
63 64 65 |
# File 'lib/puppet/provider/network_snmp/cisco_ios.rb', line 63 def canonicalize(_context, resources) resources end |
#commands_hash ⇒ Object
36 37 38 |
# File 'lib/puppet/provider/network_snmp/cisco_ios.rb', line 36 def commands_hash Puppet::Provider::NetworkSnmp::CiscoIos.commands_hash end |
#get(context, _names = nil) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/puppet/provider/network_snmp/cisco_ios.rb', line 40 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::NetworkSnmp::CiscoIos.instances_from_cli(output) PuppetX::CiscoIOS::Utility.enforce_simple_types(context, return_value) end |
#set(context, changes) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/puppet/provider/network_snmp/cisco_ios.rb', line 47 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
56 57 58 59 60 61 |
# File 'lib/puppet/provider/network_snmp/cisco_ios.rb', line 56 def update(context, _name, should) array_of_commands_to_run = Puppet::Provider::NetworkSnmp::CiscoIos.commands_from_instance(should) array_of_commands_to_run.each do |command| context.transport.run_command_conf_t_mode(command) end end |