summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/provider/vlan/cisco.rb34
-rw-r--r--lib/puppet/type/vlan.rb24
-rw-r--r--lib/puppet/util/network_device/cisco/device.rb25
3 files changed, 81 insertions, 2 deletions
diff --git a/lib/puppet/provider/vlan/cisco.rb b/lib/puppet/provider/vlan/cisco.rb
new file mode 100644
index 000000000..46e172c73
--- /dev/null
+++ b/lib/puppet/provider/vlan/cisco.rb
@@ -0,0 +1,34 @@
+require 'puppet/util/network_device/cisco/device'
+require 'puppet/provider/network_device'
+
+Puppet::Type.type(:vlan).provide :cisco, :parent => Puppet::Provider::NetworkDevice do
+
+ desc "Cisco switch/router provider for vlans."
+
+ mk_resource_methods
+
+ def self.lookup(url, id)
+ vlans = {}
+ device = Puppet::Util::NetworkDevice::Cisco::Device.new(url)
+ device.command do |d|
+ vlans = d.parse_vlans || {}
+ end
+ vlans[id]
+ end
+
+ def initialize(*args)
+ super
+ end
+
+ # Clear out the cached values.
+ def flush
+ device.command do |device|
+ device.update_vlan(resource[:name], former_properties, properties)
+ end
+ super
+ end
+
+ def device
+ @device ||= Puppet::Util::NetworkDevice::Cisco::Device.new(resource[:device_url])
+ end
+end
diff --git a/lib/puppet/type/vlan.rb b/lib/puppet/type/vlan.rb
new file mode 100644
index 000000000..6708ea4f5
--- /dev/null
+++ b/lib/puppet/type/vlan.rb
@@ -0,0 +1,24 @@
+#
+# Manages a Vlan on a given router or switch
+#
+
+Puppet::Type.newtype(:vlan) do
+ @doc = "This represents a router or switch vlan."
+
+ ensurable
+
+ newparam(:name) do
+ desc "Vlan id. It must be a number"
+ isnamevar
+
+ newvalues(/^\d+/)
+ end
+
+ newproperty(:description) do
+ desc "Vlan name"
+ end
+
+ newparam(:device_url) do
+ desc "Url to connect to a router or switch."
+ end
+end \ No newline at end of file
diff --git a/lib/puppet/util/network_device/cisco/device.rb b/lib/puppet/util/network_device/cisco/device.rb
index 97489bd8c..1f350991a 100644
--- a/lib/puppet/util/network_device/cisco/device.rb
+++ b/lib/puppet/util/network_device/cisco/device.rb
@@ -163,11 +163,11 @@ class Puppet::Util::NetworkDevice::Cisco::Device < Puppet::Util::NetworkDevice::
case l
# vlan name status
when /^(\d+)\s+(\w+)\s+(\w+)\s+([a-zA-Z0-9,\/. ]+)\s*$/
- vlan = { :id => $1, :name => $2, :status => $3, :interfaces => [] }
+ vlan = { :name => $1, :description => $2, :status => $3, :interfaces => [] }
if $4.strip.length > 0
vlan[:interfaces] = $4.strip.split(/\s*,\s*/).map{ |ifn| canonalize_ifname(ifn) }
end
- vlans[vlan[:id]] = vlan
+ vlans[vlan[:name]] = vlan
when /^\s+([a-zA-Z0-9,\/. ]+)\s*$/
raise "invalid sh vlan summary output" unless vlan
if $1.strip.length > 0
@@ -179,6 +179,27 @@ class Puppet::Util::NetworkDevice::Cisco::Device < Puppet::Util::NetworkDevice::
vlans
end
+ def update_vlan(id, is = {}, should = {})
+ if should[:ensure] == :absent
+ Puppet.info "Removing #{id} from device vlan"
+ transport.command("conf t")
+ transport.command("no vlan #{id}")
+ transport.command("exit")
+ return
+ end
+
+ # We're creating or updating an entry
+ transport.command("conf t")
+ transport.command("vlan #{id}")
+ [is.keys, should.keys].flatten.uniq.each do |property|
+ Puppet.debug("trying property: #{property}: #{should[property]}")
+ next if property != :description
+ transport.command("name #{should[property]}")
+ end
+ transport.command("exit")
+ transport.command("exit")
+ end
+
def parse_trunking(interface)
trunking = {}
out = transport.command("sh interface #{interface} switchport")