Skip to content

Commit

Permalink
Merge pull request #577 from cisco/develop
Browse files Browse the repository at this point in the history
Release 2.1.0
  • Loading branch information
chrisvanheuveln authored Aug 19, 2019
2 parents 3dc250f + 2d19bbf commit 854f1bd
Show file tree
Hide file tree
Showing 37 changed files with 672 additions and 387 deletions.
38 changes: 38 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,43 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [2.1.0] - 2019-08-19

### Added

### Changed
* Added performance enhancement to `cisco_interface` to improve processing time with small numbers of managed interfaces.

### Removed
- Removal of deprecated `cisco_interface` 'private-vlan' properties.

| Deprecated/Removed Name | New Name |
|:---|:---:|
| `private_vlan_mapping` | `pvlan_mapping`
| `switchport_mode_private_vlan_host` | `switchport_pvlan_host`, `switchport_pvlan_promiscuous`,
| `switchport_mode_private_vlan_host_association` | `switchport_pvlan_host_association`
| `switchport_mode_private_vlan_host_promiscous` | `switchport_pvlan_mapping`
| `switchport_mode_private_vlan_trunk_promiscuous`| `switchport_pvlan_trunk_promiscuous`
| `switchport_mode_private_vlan_trunk_secondary` | `switchport_pvlan_trunk_secondary`
| `switchport_private_vlan_association_trunk` | `switchport_pvlan_trunk_association`
| `switchport_private_vlan_mapping_trunk` | `switchport_pvlan_mapping_trunk`
| `switchport_private_vlan_trunk_allowed_vlan` | `switchport_pvlan_trunk_allowed_vlan`
| `switchport_private_vlan_trunk_native_vlan` | `switchport_pvlan_trunk_native_vlan`

- Removal of deprecated `cisco_vlan` 'private-vlan' properties.

| Deprecated/Removed Name | New Name |
|:---|:---:|
| `private_vlan_association` | `pvlan_association`
| `private_vlan_type` | `pvlan_type`

- Removed cisco_interface attribute:
* `purge_config`

### Issues Addressed

- [Very slow execution when managing interfaces #496](https://github.com/cisco/cisco-network-puppet-module/issues/496)

## [2.0.1] - 2019-06-24

### Changed
Expand Down Expand Up @@ -561,6 +598,7 @@ This version was never released.
- Initial release of puppetlabs-ciscopuppet module, supporting Cisco NX-OS software release 7.0(3)I2(1) on Cisco Nexus switch platforms: N95xx, N93xx, N30xx and N31xx.
- Please note: 0.9.0 is an EFT pre-release for a limited audience with access to NX-OS 7.0(3)I2(1). Additional code changes may occur in 0.9.x prior to the final 1.0.0 release.

[2.1.0]: https://github.com/cisco/cisco-network-puppet-module/compare/v2.0.1...v2.1.0
[2.0.1]: https://github.com/cisco/cisco-network-puppet-module/compare/v2.0.0...v2.0.1
[2.0.0]: https://github.com/cisco/cisco-network-puppet-module/compare/v1.10.0...v2.0.0
[1.10.0]: https://github.com/cisco/cisco-network-puppet-module/compare/v1.9.0...v1.10.0
Expand Down
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2359,7 +2359,6 @@ Manages a Cisco Network Interface. Any resource dependency should be run before
| `load_interval_counter_1_delay` | Minimum puppet module version 1.6.0 |
| `load_interval_counter_2_delay` | Minimum puppet module version 1.6.0 |
| `load_interval_counter_3_delay` | Minimum puppet module version 1.6.0 |
| `purge_config` | Minimum puppet module version 1.7.0 |
| Ensure absent for ethernet interfaces | Minimum puppet module version 1.8.0 |
| `ipv6_redirects` | Minimum puppet module version 1.10.0 |

Expand Down Expand Up @@ -2393,17 +2392,6 @@ Description of the interface. Valid values are a string or the keyword 'default'
###### `duplex`
Duplex of the interface. Valid values are 'full', and 'auto'.

###### `purge_config`
Puts the ethernet interface into default state. Valid value is 'true'. When this property is set to 'true', the manifest can have no other properties.

#### Example Usage

```puppet
cisco_interface { 'ethernet1/10':
purge_config => true,
}
```

###### `speed`
Speed of the interface. Valid values are 100, 1000, 10000, 40000, 100000, and 'auto'.

Expand Down
41 changes: 37 additions & 4 deletions lib/facter/cisco_nexus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ def self.platform_facts
platform = Cisco::Platform
feature = Cisco::Feature

# sh hardware
facts['images']['system_image'] = platform.system_image
facts['images']['full_version'] = platform.image_version

facts['images']['packages'] = platform.packages

facts['hardware'] = {}
facts['hardware']['type'] = platform.hardware_type
facts['hardware']['cpu'] = platform.cpu
facts['hardware']['memory'] = platform.memory
facts['hardware']['board'] = platform.board
facts['hardware']['last_reset'] = platform.last_reset
facts['hardware']['reset_reason'] = platform.reset_reason

# sh system resources
facts['hardware']['memory'] = platform.memory

# show inventory
facts['inventory'] = {}
facts['inventory']['chassis'] = platform.chassis
platform.slots.each do |slot, info|
Expand All @@ -33,13 +34,45 @@ def self.platform_facts
facts['inventory'][fan] = info
end

facts.update(interface_threshold(facts['hardware']['type']))

# show install patches
facts['images']['packages'] = platform.packages

# show virtual-service detail
facts['virtual_service'] = platform.virtual_services

# show feature + slot compare
facts['feature_compatible_module_iflist'] = {}
interface_list = feature.compatible_interfaces('fabricpath')
facts['feature_compatible_module_iflist']['fabricpath'] = interface_list

# sh system uptime
facts['hardware']['uptime'] = platform.uptime

facts
end

def self.interface_threshold(hw_type)
# Count interfaces and compute a lookup efficiency threshold. The threshold
# is a cutoff for determining when to get each interface one at a time versus
# getting all interfaces at once. The threshold is only useful to a certain
# point - it depends on the total number of interfaces on the device - after
# which it's better to just get all interfaces.
facts = {}
if Gem::Version.new(CiscoNodeUtils::VERSION) <= Gem::Version.new('2.0.2')
info '## Notice: Please upgrade cisco_node_utils gem to v2.1.0 or newer'
facts['interface_threshold'] = 0
else
facts['interface_count'] = Cisco::Interface.interface_count
if facts['interface_count'] < 1000 && hw_type[/Nexus7/]
# N7 uses a less efficient show cmd get_value to workaround an image bug
thresh_pct = 0.075
else
thresh_pct = 0.15
end
facts['interface_threshold'] = (facts['interface_count'] * thresh_pct).to_i
end
facts
end
end
2 changes: 1 addition & 1 deletion lib/puppet/feature/cisco_node_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def cisco_node_utils?
@results['cisco_node_utils'] = test('cisco_node_utils',
libs: ['cisco_node_utils'])
if @results['cisco_node_utils']
rec_version = Gem::Version.new('2.0.2')
rec_version = Gem::Version.new('2.1.0')
gem_version = Gem::Version.new(CiscoNodeUtils::VERSION)
if gem_version < rec_version
warn "This module works best with version #{rec_version} of gem "\
Expand Down
95 changes: 50 additions & 45 deletions lib/puppet/provider/cisco_interface/cisco.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
require 'cisco_node_utils' if Puppet.features.cisco_node_utils?
begin
require 'puppet_x/cisco/autogen'
require 'puppet_x/cisco/cmnutils'
rescue LoadError # seen on master, not on agent
# See longstanding Puppet issues #4248, #7316, #14073, #14149, etc. Ugh.
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..',
Expand Down Expand Up @@ -99,7 +100,6 @@
:ipv6_redirects,
:negotiate_auto,
:pim_bfd,
:purge_config,
:shutdown,
:switchport_autostate_exclude,
:switchport_pvlan_host,
Expand Down Expand Up @@ -129,40 +129,6 @@
:switchport_pvlan_trunk_association,
]

# TBD: These DEPRECATED arrays will be removed with release 2.0.0
DEPRECATED_INTF_FLAT = [
:private_vlan_mapping,
# Replaced by: pvlan_mapping
:switchport_mode_private_vlan_host_association,
# Replaced by: switchport_pvlan_host_association
:switchport_mode_private_vlan_host_promisc,
# Replaced by: switchport_pvlan_mapping,
:switchport_private_vlan_trunk_allowed_vlan,
# Replaced by: switchport_pvlan_trunk_allowed_vlan,
:switchport_private_vlan_association_trunk,
# Replaced by: switchport_pvlan_trunk_association
:switchport_private_vlan_mapping_trunk,
# Replaced by: switchport_pvlan_mapping_trunk
]
DEPRECATED_INTF_BOOL = [
:switchport_mode_private_vlan_trunk_promiscuous,
# Replaced by: switchport_pvlan_trunk_promiscuous,
:switchport_mode_private_vlan_trunk_secondary,
# Replaced by: switchport_pvlan_trunk_secondary,
]
DEPRECATED_INTF_NON_BOOL = [
:switchport_mode_private_vlan_host,
# Replaced by: switchport_pvlan_host,
:switchport_private_vlan_trunk_allowed_vlan,
# Replaced by: switchport_pvlan_trunk_allowed_vlan,
:switchport_private_vlan_trunk_native_vlan,
# Replaced by: switchport_pvlan_trunk_native_vlan,
]
INTF_ARRAY_FLAT_PROPS.concat(DEPRECATED_INTF_FLAT)
INTF_BOOL_PROPS.concat(DEPRECATED_INTF_BOOL)
INTF_NON_BOOL_PROPS.concat(DEPRECATED_INTF_NON_BOOL)
# End DEPRECATED

PuppetX::Cisco::AutoGen.mk_puppet_methods(:non_bool, self, '@nu',
INTF_NON_BOOL_PROPS)
PuppetX::Cisco::AutoGen.mk_puppet_methods(:bool, self, '@nu',
Expand All @@ -177,16 +143,32 @@

def initialize(value={})
super(value)
@nu = Cisco::Interface.interfaces[@property_hash[:name]]
if value.is_a?(Hash)
# value is_a hash when initialized from properties_get()
all_intf = value[:all_intf]
single_intf = value[:interface]
else
# @property_hash[:name] is nil in this codepath; since it's nil
# it will cause @nu to become nil, thus @nu instantiation is just
# skipped altogether.
all_intf = false
end
if all_intf
@nu = Cisco::Interface.interfaces[@property_hash[:name]]
elsif single_intf
# 'puppet agent' caller
@nu = Cisco::Interface.interfaces(nil, single_intf)[@property_hash[:name]]
end
@property_flush = {}
end

def self.properties_get(interface_name, nu_obj)
def self.properties_get(interface_name, nu_obj, all_intf: nil)
debug "Checking instance, #{interface_name}."
current_state = {
interface: interface_name,
name: interface_name,
ensure: :present,
all_intf: all_intf,
}
# Call node_utils getter for each property
INTF_NON_BOOL_PROPS.each do |prop|
Expand All @@ -203,24 +185,44 @@ def self.properties_get(interface_name, nu_obj)
new(current_state)
end # self.properties_get

def self.instances
def self.instances(single_intf=nil, interface_threshold=0)
# 'puppet resource' calls here directly; will always get all interfaces.
# 'puppet agent' callpath is initialize->prefetch; may pass a single intf.
if single_intf && interface_threshold > 0
all_intf = false
nu_interfaces = Cisco::Interface.interfaces(nil, single_intf)
else
all_intf = true
nu_interfaces = Cisco::Interface.interfaces
end
interfaces = []
Cisco::Interface.interfaces.each do |interface_name, nu_obj|
nu_interfaces.each do |interface_name, nu_obj|
begin
# Some interfaces cannot or should not be managed by this type.
# - NVE Interfaces (managed by cisco_vxlan_vtep type)
next if interface_name.match(/nve/i)
interfaces << properties_get(interface_name, nu_obj)
interfaces << properties_get(interface_name, nu_obj, all_intf: all_intf)
end
end
interfaces
end # self.instances

def self.prefetch(resources)
interfaces = instances
resources.keys.each do |name|
provider = interfaces.find { |intf| intf.instance_name == name }
resources[name].provider = provider unless provider.nil?
interface_threshold = PuppetX::Cisco::Utils.interface_threshold
if resources.keys.length > interface_threshold
info '[prefetch all interfaces]:begin - please be patient...'
interfaces = instances
resources.keys.each do |name|
provider = interfaces.find { |intf| intf.instance_name == name }
resources[name].provider = provider unless provider.nil?
end
info "[prefetch all interfaces]:end - found: #{interfaces.length}"
else
info "[prefetch each interface independently] (threshold: #{interface_threshold})"
resources.keys.each do |name|
provider = instances(name, interface_threshold).find { |intf| intf.instance_name == name }
resources[name].provider = provider unless provider.nil?
end
end
end # self.prefetch

Expand Down Expand Up @@ -382,7 +384,10 @@ def flush
# Create/Update
if @nu.nil? || @nu.state_default
new_interface = true
@nu = Cisco::Interface.new(@resource[:interface])
@nu = Cisco::Interface.new(@resource[:interface],
true,
false,
@resource[:interface])
end
properties_set(new_interface)
end
Expand Down
Loading

0 comments on commit 854f1bd

Please sign in to comment.