Class: Puppet::Provider::NetworkInterface::CiscoIos
- Inherits:
-
Object
- Object
- Puppet::Provider::NetworkInterface::CiscoIos
- Defined in:
- lib/puppet/provider/network_interface/cisco_ios.rb
Overview
Network Interface 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
26 27 28 29 30 31 32 33 34 |
# File 'lib/puppet/provider/network_interface/cisco_ios.rb', line 26 def self.commands_from_instance(property_hash) # Convert 10m/100m/1g speed values to modelled 10/100/1000 on Cisco 6500 unless property_hash[:speed].nil? property_hash[:speed] = PuppetX::CiscoIOS::Utility.convert_modelled_speed_value_to_int(property_hash[:speed]) end # Enable attribute is strange: enable == 'no shutdown' and disable == 'shutdown' property_hash[:enable] = (property_hash[:enable]) ? 'no' : '' PuppetX::CiscoIOS::Utility.build_commmands_from_attribute_set_values(property_hash, commands_hash) end |
.commands_hash ⇒ Object
8 9 10 |
# File 'lib/puppet/provider/network_interface/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
16 17 18 19 20 21 22 23 24 |
# File 'lib/puppet/provider/network_interface/cisco_ios.rb', line 16 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[:enable] = new_instance[:enable].nil? ? true : false new_instance_fields << PuppetX::CiscoIOS::Utility.device_safe_instance(new_instance, commands_hash) end new_instance_fields end |
Instance Method Details
#canonicalize(_context, resources) ⇒ Object
12 13 14 |
# File 'lib/puppet/provider/network_interface/cisco_ios.rb', line 12 def canonicalize(_context, resources) resources end |
#commands_hash ⇒ Object
36 37 38 |
# File 'lib/puppet/provider/network_interface/cisco_ios.rb', line 36 def commands_hash Puppet::Provider::NetworkInterface::CiscoIos.commands_hash end |
#get(context, _names = nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/puppet/provider/network_interface/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::NetworkInterface::CiscoIos.instances_from_cli(output) instances = PuppetX::CiscoIOS::Utility.enforce_simple_types(context, return_value) # Retrieve status for all the interfaces status_output = context.transport.run_command_enable_mode(PuppetX::CiscoIOS::Utility.value_foraged_from_command_hash(commands_hash, 'get_speed_status')) if status_output =~ %r{% Unrecognized command} instances else data = PuppetX::CiscoIOS::Utility.read_table(status_output) instance_data = [] data.each do |interface| instance_data << { name: PuppetX::CiscoIOS::Utility.shorthand_to_full(interface['Port']), # Convert 10/100/1000 speed values to modelled 10m/100m/1g speed: (interface['Speed'][0] == 'a') ? 'auto' : PuppetX::CiscoIOS::Utility.convert_speed_int_to_modelled_value(interface['Speed']), duplex: (interface['Duplex'][0] == 'a') ? 'auto' : interface['Duplex'], } end # combine the two arrays (instances + instance_data).group_by { |interface| interface[:name] }.map { |_, values| values.inject({}, :merge) } end end |
#set(context, changes) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/puppet/provider/network_interface/cisco_ios.rb', line 68 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
77 78 79 80 81 82 |
# File 'lib/puppet/provider/network_interface/cisco_ios.rb', line 77 def update(context, name, should) array_of_commands_to_run = Puppet::Provider::NetworkInterface::CiscoIos.commands_from_instance(should) array_of_commands_to_run.each do |command| context.transport.run_command_interface_mode(name, command) end end |