Class: Switch::Port

Inherits:
Object
  • Object
show all
Defined in:
lib/netutils/switch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, model, type, speed, duplex) ⇒ Port

Returns a new instance of Port.



76
77
78
79
80
81
82
83
84
# File 'lib/netutils/switch.rb', line 76

def initialize(name, model, type, speed, duplex)
	@name = PortName.new(name)
	@model = model
	@type = type_name(type)
	@speed = speed
	@duplex = duplex
	@peers = Peers.new
	@up = false
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



73
74
75
# File 'lib/netutils/switch.rb', line 73

def name
  @name
end

#peersObject (readonly)

Returns the value of attribute peers.



73
74
75
# File 'lib/netutils/switch.rb', line 73

def peers
  @peers
end

#upObject

Returns the value of attribute up.



74
75
76
# File 'lib/netutils/switch.rb', line 74

def up
  @up
end

Instance Method Details

#dump(p) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/netutils/switch.rb', line 95

def dump(p)
	up = @up? '*' : ' '
	s = sprintf "#{p}#{up}#{@name.to_s} #{@model} #{@type} "
	print s
	indent = 0
	@peers.each { |peer|
		l = peer.has_backlink? ? '<->' : '->'
		printf "% *s#{l} #{peer.to_s}\n", indent, ''
		indent = s.length
	}
	puts '' if @peers.length == 0
end

#dump_csv(p) ⇒ Object



108
109
110
111
112
113
114
115
# File 'lib/netutils/switch.rb', line 108

def dump_csv(p)
	up = @up? '*' : ' '
	printf "#{p},#{up},#{@name.to_csv},#{@type}"
	@peers.each { |peer|
		printf ",#{peer.to_csv}"
	}
	puts ''
end

#type_name(type) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/netutils/switch.rb', line 86

def type_name(type)
	type = $1 if type =~ %r{10/100/(1000BaseT).?}
	type = $1 if type =~ %r{10/(100BaseTX)}
	type = '1000BaseT' if type =~ %r{10/100/1000-T.?}
	type = $1 if type =~ /^(.*) SFP/
	type = 'none' if type =~ /^Not? .*/
	return type
end