# class Puppet::Util::NetworkDevice::Cisco::Interface

this manages setting properties to an interface in a cisco switch or router

### Constants

COMMANDS

### Attributes

name[R]
transport[R]

### Public Class Methods

new(name, transport) click to toggle source

    # File lib/puppet/util/network_device/cisco/interface.rb, line 12
    def initialize(name, transport)
      @name = name
      @transport = transport
    end

### Public Instance Methods

command(command) click to toggle source

    # 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 =~ /^%/mo
      end
    end

execute(property, value, prefix='') click to toggle source

    # 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

update(is={}, should={}) click to toggle source

    # 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