this manages setting properties to an interface in a cisco switch or router
# File lib/puppet/util/network_device/cisco/interface.rb, line 12 def initialize(name, transport) @name = name @transport = transport end
# File lib/puppet/util/network_device/cisco/interface.rb, line 77 def command(command) transport.command(command) do |out| Puppet.err "Error while executing #{command}, device returned #{out}" if out =~ /^%/o end end
# File lib/puppet/util/network_device/cisco/interface.rb, line 59 def execute(property, value, prefix='') case COMMANDS[property][1] when Array COMMANDS[property][1].each do |command| transport.command(prefix + command % value) do |out| break unless out =~ /^%/ end end when String command(prefix + COMMANDS[property][1] % value) when Proc value = [value] unless value.is_a?(Array) value.each do |value| command(prefix + COMMANDS[property][1].call(*value)) end end end
# File lib/puppet/util/network_device/cisco/interface.rb, line 35 def update(is={}, should={}) Puppet.debug("Updating interface #{name}") command("conf t") command("interface #{name}") # apply changes in a defined orders for cisco IOS devices [is.keys, should.keys].flatten.uniq.sort {|a,b| COMMANDS[a][0] <=> COMMANDS[b][0] }.each do |property| # They're equal, so do nothing. next if is[property] == should[property] # We're deleting it if should[property] == :absent or should[property].nil? execute(property, is[property], "no ") next end # We're replacing an existing value or creating a new one execute(property, should[property]) end command("exit") command("exit") end