Sha256: 3b7212e52b836fafe8e7609bd9bb6dd73fc0ab1debad57f100916a7964f1667d

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

require 'netutils/parser'

module Cisco

class Interface < Parser
	def cmd
		return 'show interfaces capabilities'
	end

	def initialize(sw)
		super()
		add('Init',	:init)
		add('Name',	:name,	/^ +Model: +(.+)$/)
		add('Model',	:model,	/^ +Type: +(.+)$/)
		add('Type',	:type)
		add('Speed',	:speed,	/^ +Duplex: +(.+)$/)
		@sw = sw
	end

	private

	def init(l, m)
		return unless l =~ /^([^ ]+)$/
		@name = $1
		@model = nil
		@type = nil
		@speed = nil
		@duplex = nil
		changeto('Name')
	end

	def name(l, m)
		@model = m[1]
		changeto('Model')
	end

	def model(l, m)
		@type = m[1]
		changeto('Type')
	end

	def type(l, m)
		if l =~ /^ +Speed: +(.+)$/
			@speed = m[1]
			changeto('Speed')
		else
			@speed = 'unknown'
			done
		end
	end

	def speed(l, m)
		@duplex = m[1]
		done
	end

	def done
		changeto('Init')
		return if @model === 'not applicable'	# port-channel
		return if @model === 'N/A'		# port-channel
		return if @type === 'WiSM'
		return if @type === 'unknown'		# port-channel
		@sw.ports.add(@name, @model, @type, @speed, @duplex)
	end
end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
netutils-0.1.2 lib/netutils/cli/cisco/interface.rb
netutils-0.1.1 lib/netutils/cli/cisco/interface.rb