Top Level Namespace
Defined Under Namespace
Modules: Alaxala, Aruba, Cisco, NEC, Netutils, Paloalto
Classes: ARPTable, CLI, FSM, MACAddr, OnceQueue, Parser, RIB, Switch, Tunnel, VRFTable
Instance Method Summary
collapse
Instance Method Details
#interface_name_vlan_id(name) ⇒ Object
68
69
70
71
|
# File 'lib/netutils.rb', line 68
def interface_name_vlan_id(name)
return $1 if name =~ /^vlan([0-9]+)$/i
nil
end
|
#interface_sanity_check(host, port) ⇒ Object
39
40
41
42
43
44
|
# File 'lib/netutils.rb', line 39
def interface_sanity_check(host, port)
if port !~ /^[gf]/i
raise "Suppress shutdown #{port}, which may be backbone link."
end
end
|
#log(m) ⇒ Object
51
52
53
54
|
# File 'lib/netutils.rb', line 51
def log(m)
puts m
$log += m + "\n"
end
|
#log_buffer ⇒ Object
56
57
58
|
# File 'lib/netutils.rb', line 56
def log_buffer
return $log
end
|
#log_without_newline(m) ⇒ Object
46
47
48
49
|
# File 'lib/netutils.rb', line 46
def log_without_newline(m)
print m
$log += m
end
|
#mail(s, b) ⇒ Object
XXX: These are global methods!!!!
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/netutils.rb', line 21
def mail(s, b)
m = Mail.new do
delivery_method :smtp, address: MAILSERVER
from MAILFROM
to MAILTO
subject s
body b
end
m.charset = 'ascii'
m.deliver!
end
|
#router_locate(ia) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/netutils.rb', line 87
def router_locate(ia)
root = SWITCHES[0]
sw = Switch.new(root[0], Switch::Type::ROUTER, root[1])
sw.login
while true
rts = sw.route_gets(ia)
raise "No route found for #{ia}" if ! rts
bestrt = nil
rts.each do |rt|
case rt.proto
when 'connected'
return sw, ia
when 'static', 'rip', 'ospf', 'bgp'
next if rt.nh === nil && ! rt.tunnel?
bestrt = rt.compare(bestrt)
end
end
raise "No valid route found for #{ia}" if ! bestrt
if OTHER_NEXTHOPS.include?(bestrt.nh)
return sw, bestrt.nh
end
if bestrt.tunnel?
nh = tunnel_nexthop_resolve(sw, bestrt)
else
nh = bestrt.nh
end
sw = Switch.new(nil, Switch::Type::ROUTER, nh)
sw.login
end
end
|
#static_neighbor_resolve(sw, ifname) ⇒ Object
73
74
75
76
77
78
|
# File 'lib/netutils.rb', line 73
def static_neighbor_resolve(sw, ifname)
key = "#{sw.name}_#{ifname}"
n = STATIC_NEIGHBOR[key]
return nil if n.nil?
Switch.get(n[:name], Switch::Type::ROUTER, nil, nil, nil, n[:ia], sw)
end
|
#tunnel_nexthop_resolve(sw, rt) ⇒ Object
80
81
82
83
84
85
|
# File 'lib/netutils.rb', line 80
def tunnel_nexthop_resolve(sw, rt)
return rt.nh if rt.nh
c = CDP.new(nil)
c.parse(sw.cli.cmd("show cdp neighbors #{rt.interface} detail"))
c.ias[0]
end
|
#valid_ip_address?(s) ⇒ Boolean
33
34
35
36
37
|
# File 'lib/netutils.rb', line 33
def valid_ip_address?(s)
return false if s !~ /^(?:[0-9]+\.){3}[0-9]+$/
results = s.split('.').collect { |i| i.to_i.between?(0, 255) }
return results.count(true) === 4
end
|
#vlans_by_switch_name(swname, vlan) ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/netutils.rb', line 60
def vlans_by_switch_name(swname, vlan)
vlan = vlan.to_i
vlans = []
vlans = VLANS[swname].dup if VLANS.has_key?(swname)
vlans.unshift(vlan) if vlan && ! vlans.include?(vlan)
return vlans
end
|