-
-
Save cyrus-mc/64641a7b8b30ad112fdd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
file: lib/puppet/provider/cisco_vlan/cisco_ios.rb: | |
require 'puppet/provider/cisco_ios' | |
Puppet::Type.type(:cisco_vlan).provide :cisco_ios, :parent => Puppet::Provider::Cisco_ios do | |
desc "Cisco Switch / Router Provider for VLAN Configuration." | |
mk_resource_methods | |
def initialize(device, *args) | |
super | |
end | |
def self.lookup(device, name) | |
device.switch.vlan(name).params_to_hash | |
end | |
def verify_vtp(device) | |
# make the switch vtp primary if we try to set vlans on this switch | |
unless device.switch.facts['vtp_mode'] == 'primary_server' | |
self.fail("Cant set VLAN's on a VTP Client") if device.switch.facts['vtp_mode'] == 'client' | |
return if device.switch.facts['vtp_mode'] == 'tranparent' | |
return if device.switch.facts['vtp_version'] != '3' | |
unless Puppet[:noop] | |
device.switch.transport.command("end") | |
device.switch.transport.command("vtp primary force") | |
device.switch.facts['vtp_mode'] = 'primary_server' | |
end | |
end | |
end | |
def flush | |
verify_vtp(device) | |
device.switch.vlan(name).update(former_properties, properties) | |
super | |
end | |
end | |
file: lib/puppet/provider/cisco_ios.rb | |
require 'puppet/util/network_device/singelton_ios' | |
require 'puppet/provider/network_device' | |
# This is the base Class of all prefetched cisco device providers | |
class Puppet::Provider::Cisco_ios < Puppet::Provider::NetworkDevice | |
def self.device(url) | |
Puppet::Util::NetworkDevice::Singelton_ios.lookup(url) | |
end | |
def self.prefetch(resources) | |
resources.each do |name, resource| | |
device = Puppet::Util::NetworkDevice.current || device(resource[:device_url]) | |
if result = lookup(device, name) | |
resource.provider = new(device, result) | |
else | |
resource.provider = new(device, :ensure => :absent) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment