netutils 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/LICENSE +25 -0
- data/README.md +71 -15
- data/bin/alaxala-deploy +129 -29
- data/bin/host-locate-on-demand +1 -1
- data/config/.gitignore +1 -0
- data/config/config-sample.rb +92 -0
- data/lib/netutils.rb +9 -7
- data/lib/netutils/cli.rb +1 -1
- data/lib/netutils/cli/alaxala/lldp.rb +2 -2
- data/lib/netutils/cli/cisco/cdp.rb +1 -1
- data/lib/netutils/switch.rb +8 -5
- data/lib/netutils/version.rb +1 -1
- data/netutils.gemspec +1 -1
- metadata +6 -4
- data/CODE_OF_CONDUCT.md +0 -74
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 176c7c7e84a695a50232cfc98df3d378bbc03e07a76867fad7e23751bc15dc71
|
4
|
+
data.tar.gz: 7bb9a7ecb00953e1bd69453afbf282d2dcb905d1ace951b3da3aeeb1c05bf50c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cff333eb3ba6c9a399ca85348f996e0d16a09920378be17637f86578213aaac8c1c1f4330ea321826671fb6d554aa9128e4b550453fdccd5fb8879432f56270b
|
7
|
+
data.tar.gz: a2abe839d16ade6788f76994e6c3ed335b182392538f95ff2a9c973e3a29a49985b1fe8d3229adefc5d8963b030d49bcbc0a6fa6094a8521ddfeb133cea10b78
|
data/.travis.yml
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
Copyright (c) 2016-2017 Motoyuki OHMORI <ohmori@tottori-u.ac.jp>
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions
|
7
|
+
are met:
|
8
|
+
1. Redistributions of source code must retain the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright
|
11
|
+
notice, this list of conditions and the following disclaimer in the
|
12
|
+
documentation and/or other materials provided with the distribution.
|
13
|
+
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
15
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
16
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
17
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
18
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
19
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
20
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
21
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
22
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
23
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
24
|
+
SUCH DAMAGE.
|
25
|
+
|
data/README.md
CHANGED
@@ -1,28 +1,85 @@
|
|
1
1
|
# Netutils
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
Netutils is a set of utilities to operate network equipment such as routers, switches, firewalls, wireless controller and so on.
|
4
|
+
Netutils currently can:
|
5
|
+
* automatically find network equipment,
|
6
|
+
* collect configurations,
|
7
|
+
* deploy certificate files to switches,
|
8
|
+
* reboot switches in safer order,
|
9
|
+
* locate a switch and port to which a host connects to,
|
10
|
+
* add/delete a MAC address filter,
|
11
|
+
* shut down or bring up a port, and so on.
|
12
|
+
|
13
|
+
## Features
|
14
|
+
|
15
|
+
* vendor lock free
|
16
|
+
* multiple accounts support
|
17
|
+
* auto neighbor discovery using Link Layer Discovery Protocol (LLDP) and Cisco Discovery Protocol (CDP)
|
18
|
+
* static neighbor definition support
|
19
|
+
|
20
|
+
## Acutually Tested Equipment
|
21
|
+
|
22
|
+
* Cisco
|
23
|
+
* C1812J, catalyst 6500, 3560, 2960
|
24
|
+
* AlaxalA
|
25
|
+
* AX8600, AX3800, AX3650, AX2530, AX2200, AX620
|
26
|
+
* Palo Alto Networks
|
27
|
+
* PA-5220, PA-3020, PA-850
|
28
|
+
* Aruba wireless LAN controller
|
29
|
+
* Aruba7210-JP
|
30
|
+
* NEC IX series
|
31
|
+
* IX2215, Palo Alto Networks
|
6
32
|
|
7
33
|
## Installation
|
8
34
|
|
9
|
-
|
35
|
+
$ git clone https://github.com/ohmori7/netutils
|
36
|
+
$ cd netutils
|
37
|
+
$ bundle install
|
38
|
+
$ cp config/config-sample.rb config/config.rb
|
39
|
+
$ vi config/config.rb
|
40
|
+
|
41
|
+
## Usage
|
10
42
|
|
11
|
-
|
12
|
-
|
13
|
-
|
43
|
+
$ bundle exec netutils/bin/config-gets
|
44
|
+
$ bundle exec netutils/bin/alaxala-deploy
|
45
|
+
$ bundle exec netutils/bin/host-locate-on-demand
|
46
|
+
$ bundle exec netutils/bin/acl
|
47
|
+
$ bundle exec netutils/bin/port-shutdown
|
14
48
|
|
15
|
-
|
49
|
+
## Example
|
16
50
|
|
17
|
-
|
51
|
+
For example, one can locate a host of a given IP address as follows:
|
18
52
|
|
19
|
-
|
53
|
+
$ bundle exec bin/host-locate-on-demand 10.0.0.1
|
54
|
+
locating directly connected router for 10.0.0.1...
|
55
|
+
"tottori-c01" (192.168.0.1)
|
56
|
+
resolving MAC address for 10.0.0.1... found
|
57
|
+
10.0.0.1 dead.beef.dead on VRF "1" VLAN1001
|
58
|
+
locating MAC address dead.beef.dead...
|
59
|
+
tottori-c01 (192.168.0.1) GigabitEthernet 0/1
|
60
|
+
koyama-e01 (192.168.0.2) GigabitEthernet 0/24
|
20
61
|
|
21
|
-
|
62
|
+
For more detailed information, please consult with a help message of a command.
|
22
63
|
|
23
|
-
##
|
64
|
+
## Why not SNMP???
|
24
65
|
|
25
|
-
|
66
|
+
Ones may think why SNMP is not used to automatically find network equipment.
|
67
|
+
The reason is that we have experienced network stalls due to SNMP.
|
68
|
+
Receiving the small number of SNMP packets, our core switch, Cisco catalyst 6500, could not forward any packets due to high CPU utilization even there was no SNMP configuration enabled.
|
69
|
+
This was a design issue that all SNMP packets were always punt to CPU of a routing engine.
|
70
|
+
We have then decided to employ LLDP and CDP instead of SNMP.
|
71
|
+
|
72
|
+
## TODO
|
73
|
+
|
74
|
+
* clean up code, name space issues, and switch class method abandon
|
75
|
+
* more gemification
|
76
|
+
* remove global methods
|
77
|
+
* use yaml for configuration
|
78
|
+
* out-of-band CLI output message handling (partially done but..)
|
79
|
+
* restructure class methods and variables
|
80
|
+
* introduce test codes
|
81
|
+
* more product support
|
82
|
+
* netconf or other REST API support
|
26
83
|
|
27
84
|
## Development
|
28
85
|
|
@@ -32,5 +89,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
89
|
|
33
90
|
## Contributing
|
34
91
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/ohmori7/netutils.
|
36
|
-
|
92
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ohmori7/netutils.
|
data/bin/alaxala-deploy
CHANGED
@@ -38,8 +38,8 @@ def usage(errmsg = nil)
|
|
38
38
|
STDERR.print "\
|
39
39
|
Usage:
|
40
40
|
#{progname} -h
|
41
|
-
#{progname} [-c] [-w] [-r] -a
|
42
|
-
#{progname} [-c] [-w] [-r] <switch IP
|
41
|
+
#{progname} [-c] [-d] [-f] [-w] [-r] -a
|
42
|
+
#{progname} [-c] [-d] [-f] [-w] [-r] <switch IP address 1> ...
|
43
43
|
Description:
|
44
44
|
deploy files to Alaxala switches, such as certificate files (i.e.,
|
45
45
|
certificate itself, private key, intermediate CA certificate), HTML
|
@@ -54,6 +54,8 @@ Arguments:
|
|
54
54
|
Options:
|
55
55
|
-h: output this help message.
|
56
56
|
-c: deploy certificate files.
|
57
|
+
-d: dry run (do not actually reboot).
|
58
|
+
-f: force to consider all switches as requiring reboots.
|
57
59
|
-w: deploy HTML files.
|
58
60
|
-r: reload a switch if necessary (only for certificate files).
|
59
61
|
-a: deploy to all switches.
|
@@ -74,9 +76,78 @@ Example:
|
|
74
76
|
exit 1
|
75
77
|
end
|
76
78
|
|
79
|
+
##
|
80
|
+
ROOT_DEPTH = 0
|
81
|
+
|
82
|
+
class Vertices
|
83
|
+
class Vertex
|
84
|
+
attr_reader :sw, :depth
|
85
|
+
|
86
|
+
def initialize(sw)
|
87
|
+
@sw = sw
|
88
|
+
depth_compute
|
89
|
+
end
|
90
|
+
|
91
|
+
def depth
|
92
|
+
@sw.note
|
93
|
+
end
|
94
|
+
|
95
|
+
def depth_compute
|
96
|
+
return if ! @sw.note.nil?
|
97
|
+
depth = 0
|
98
|
+
nparent = @sw.parent
|
99
|
+
loop do
|
100
|
+
parent = nparent
|
101
|
+
if parent.nil?
|
102
|
+
break
|
103
|
+
end
|
104
|
+
nparent = parent.parent
|
105
|
+
if ! parent.note.nil?
|
106
|
+
depth += parent.note + 1
|
107
|
+
break
|
108
|
+
end
|
109
|
+
end
|
110
|
+
@sw.note = depth
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
attr_reader :maxdepth
|
115
|
+
|
116
|
+
def initialize
|
117
|
+
@vertices = [ Queue.new ]
|
118
|
+
@maxdepth = 0
|
119
|
+
@mutex = Thread::Mutex.new
|
120
|
+
end
|
121
|
+
|
122
|
+
def length(depth)
|
123
|
+
@vertices[depth].length
|
124
|
+
end
|
125
|
+
|
126
|
+
def push(sw)
|
127
|
+
v = Vertex.new(sw)
|
128
|
+
@mutex.synchronize do
|
129
|
+
if @vertices[v.depth].nil?
|
130
|
+
@vertices[v.depth] = Queue.new
|
131
|
+
end
|
132
|
+
end
|
133
|
+
@vertices[v.depth].push(v)
|
134
|
+
if v.depth > @maxdepth
|
135
|
+
@maxdepth = v.depth
|
136
|
+
end
|
137
|
+
return v
|
138
|
+
end
|
139
|
+
|
140
|
+
def pop(depth)
|
141
|
+
@vertices[depth].pop(true)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
vertices = Vertices.new
|
146
|
+
|
77
147
|
##
|
78
148
|
# inject() requires Ruby2.4... take a more operational way.
|
79
|
-
options0 = ARGV.getopts(
|
149
|
+
options0 = ARGV.getopts(
|
150
|
+
'hcdfwra', 'help', 'certificate', 'dry', 'force', 'web', 'reload', 'all')
|
80
151
|
options = {}
|
81
152
|
options0.map { |k, v| options[k.to_sym] = v }
|
82
153
|
|
@@ -86,10 +157,12 @@ if options[:a]
|
|
86
157
|
usage('Extra argument specified')
|
87
158
|
end
|
88
159
|
Switch.set_retrieve_all
|
89
|
-
SWITCHES.each
|
160
|
+
SWITCHES.each do |name, ia|
|
161
|
+
Switch.new(name, Switch::Type::ROUTER, ia, ).note = 0
|
162
|
+
end
|
90
163
|
elsif ARGV.length > 0
|
91
164
|
ARGV.each do |ia|
|
92
|
-
Switch.new(nil, Switch::Type::ROUTER, ia)
|
165
|
+
Switch.new(nil, Switch::Type::ROUTER, ia).note = 0
|
93
166
|
end
|
94
167
|
else
|
95
168
|
usage('No IP address is given.')
|
@@ -103,11 +176,11 @@ if options[:c] || options[:w]
|
|
103
176
|
user = STDIN.gets.strip
|
104
177
|
print 'Input FTP password: '
|
105
178
|
password = STDIN.noecho(&:gets).strip
|
106
|
-
puts
|
107
179
|
end
|
108
180
|
|
109
181
|
##
|
110
|
-
|
182
|
+
retrieve_start_time = Time.now
|
183
|
+
|
111
184
|
Switch.retrieve do |sw|
|
112
185
|
if sw.name
|
113
186
|
print "Connecting: ``#{sw.name}'' (#{sw.ia})\n"
|
@@ -150,8 +223,8 @@ Switch.retrieve do |sw|
|
|
150
223
|
v = $1.strip
|
151
224
|
boottime = Time.parse(v)
|
152
225
|
msg += ", boot: #{v}"
|
153
|
-
if boottime < installedtime || options[:c]
|
154
|
-
|
226
|
+
if boottime < installedtime || options[:c] || options[:f]
|
227
|
+
v = vertices.push(sw)
|
155
228
|
msg += ' (need reboot)'
|
156
229
|
end
|
157
230
|
end
|
@@ -239,33 +312,60 @@ Switch.retrieve do |sw|
|
|
239
312
|
end
|
240
313
|
Switch.warn
|
241
314
|
|
315
|
+
retrieve_end_time = Time.now
|
316
|
+
|
242
317
|
exit if ! options[:r]
|
243
318
|
|
319
|
+
reboot_times = [ Time.now ]
|
320
|
+
reboot_counts = []
|
321
|
+
|
244
322
|
thread_concurrency = 64
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
323
|
+
for rdepth in 0 .. vertices.maxdepth do
|
324
|
+
depth = vertices.maxdepth - rdepth
|
325
|
+
reboot_counts[depth] = vertices.length(depth)
|
326
|
+
puts "examine: #{depth}-th depth (#{vertices.length(depth)} switches)"
|
327
|
+
threads = []
|
328
|
+
for i in 1..thread_concurrency do
|
329
|
+
threads <<= Thread.new do
|
330
|
+
begin
|
331
|
+
while v = vertices.pop(depth) do
|
332
|
+
sw = v.sw
|
333
|
+
if ! options[:d]
|
334
|
+
sw.configure
|
335
|
+
sw.cmd('save')
|
336
|
+
sw.unconfigure
|
337
|
+
#
|
338
|
+
# note that pager configuration
|
339
|
+
# or other configurations barks
|
340
|
+
# without an option, ``-f.''
|
341
|
+
#
|
342
|
+
begin
|
343
|
+
sw.cmd('reload -f')
|
344
|
+
rescue
|
345
|
+
end
|
346
|
+
end
|
347
|
+
puts " Reboot: ``#{sw.name}'' " +
|
348
|
+
"(#{sw.ia}) done"
|
261
349
|
end
|
262
|
-
|
350
|
+
rescue
|
263
351
|
end
|
264
|
-
rescue
|
265
352
|
end
|
266
353
|
end
|
354
|
+
|
355
|
+
threads.each do |thread|
|
356
|
+
thread.join
|
357
|
+
end
|
358
|
+
|
359
|
+
reboot_times.push(Time.now)
|
267
360
|
end
|
268
361
|
|
269
|
-
|
270
|
-
|
362
|
+
puts "Retrieve time : #{retrieve_start_time.iso8601(3)}" +
|
363
|
+
" (#{retrieve_end_time - retrieve_start_time})"
|
364
|
+
puts " Reboot time: #{reboot_times.first.iso8601(3)}" +
|
365
|
+
" (#{reboot_times.last - reboot_times.first})"
|
366
|
+
|
367
|
+
for depth in 0 .. vertices.maxdepth do
|
368
|
+
printf "% 10d-th depth: % 4d switches: " +
|
369
|
+
"#{reboot_times[depth + 1] - reboot_times[depth]}\n",
|
370
|
+
depth, reboot_counts[depth]
|
271
371
|
end
|
data/bin/host-locate-on-demand
CHANGED
data/config/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
config.rb
|
@@ -0,0 +1,92 @@
|
|
1
|
+
#
|
2
|
+
# possible usernames, login passwords and enable passwords.
|
3
|
+
#
|
4
|
+
USERS = [
|
5
|
+
'hogehoge',
|
6
|
+
'fugafuga',
|
7
|
+
'bakeratta',
|
8
|
+
]
|
9
|
+
PASSWORDS = [
|
10
|
+
'secret1',
|
11
|
+
'secret2',
|
12
|
+
'secret3',
|
13
|
+
]
|
14
|
+
ENABLES = [
|
15
|
+
'secret4',
|
16
|
+
'secret5',
|
17
|
+
'secret6',
|
18
|
+
]
|
19
|
+
|
20
|
+
#
|
21
|
+
# Logging directory to which debug messages go.
|
22
|
+
#
|
23
|
+
LOGDIR = 'log'
|
24
|
+
|
25
|
+
#
|
26
|
+
# List of CLI session types. SSH or telnet or both of them must be specified.
|
27
|
+
#
|
28
|
+
CLI_SESSION_TYPES = [ :ssh, :telnet ]
|
29
|
+
|
30
|
+
#
|
31
|
+
# pairs of a host name of core switch and IP address.
|
32
|
+
#
|
33
|
+
SWITCHES = [
|
34
|
+
# Koyama
|
35
|
+
[ 'koyama-c01', '10.0.0.1' ],
|
36
|
+
# Yonago
|
37
|
+
[ 'yonago-c01', '10.100.0.1' ],
|
38
|
+
# Dry land
|
39
|
+
[ 'hamasaka-c01', '10.200.0.1' ],
|
40
|
+
]
|
41
|
+
|
42
|
+
#
|
43
|
+
# Mail notification configurations.
|
44
|
+
#
|
45
|
+
MAILFROM = 'example@example.tottori-u.ac.jp'
|
46
|
+
MAILTO = 'example@example.tottori-u.ac.jp'
|
47
|
+
MAILSERVER = 'example.tottori-u.ac.jp'
|
48
|
+
|
49
|
+
#
|
50
|
+
# List of neighbors that cannot run both of LLDP and CDP.
|
51
|
+
#
|
52
|
+
STATIC_NEIGHBOR = {
|
53
|
+
#
|
54
|
+
# XXX: Special hack for AX3800
|
55
|
+
# XXX: AX3800 cannot run LLDP with stack configuration...
|
56
|
+
#
|
57
|
+
'koyama-c01_TenGigabitEthernet 1/1' =>
|
58
|
+
{ name: 'koyama-me2f-sw1', ia: '192.168.0.1' },
|
59
|
+
}
|
60
|
+
|
61
|
+
#
|
62
|
+
# Preferred L3 nexthops when connecting to neighboring routers.
|
63
|
+
#
|
64
|
+
PREFERRED_NEXTHOPS = [
|
65
|
+
'192.168.0.0/24', # Koyama
|
66
|
+
'192.168.1.0/24', # Yonago
|
67
|
+
]
|
68
|
+
|
69
|
+
#
|
70
|
+
# List of nexthop routers that are out of scope of our operations.
|
71
|
+
#
|
72
|
+
OTHER_NEXTHOPS = [
|
73
|
+
'192.168.0.1',
|
74
|
+
]
|
75
|
+
|
76
|
+
#
|
77
|
+
# List of VLAN IDs to filter out a MAC address.
|
78
|
+
# XXX: will be deprecated.
|
79
|
+
#
|
80
|
+
VLANS = {
|
81
|
+
# KOYAMA
|
82
|
+
'koyama-c01' => [ 100, 200, ],
|
83
|
+
# YONAGO
|
84
|
+
'yonago-c01' => [ 1000, 2000, ],
|
85
|
+
}
|
86
|
+
|
87
|
+
#
|
88
|
+
# FTP server and Web authentication server for ``alaxala-deploy'' script.
|
89
|
+
# XXX: should be moved to other place???
|
90
|
+
#
|
91
|
+
FTP_SERVER = '10.0.1.1'
|
92
|
+
WEBAUTH_HOST = 'webauth.example.tottori-u.ac.jp'
|
data/lib/netutils.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
require "netutils/version"
|
2
1
|
require 'mail'
|
2
|
+
require 'netutils/version'
|
3
3
|
require 'netutils/switch'
|
4
4
|
require 'config/config'
|
5
|
-
require 'config/passwd'
|
6
5
|
|
7
6
|
module Netutils
|
8
7
|
|
@@ -14,6 +13,11 @@ ACL_MAX_SEQ = 4294967294
|
|
14
13
|
#
|
15
14
|
$log = ''
|
16
15
|
|
16
|
+
end # XXX: module
|
17
|
+
|
18
|
+
#
|
19
|
+
# XXX: These are global methods!!!!
|
20
|
+
#
|
17
21
|
def mail(s, b)
|
18
22
|
m = Mail.new do
|
19
23
|
delivery_method :smtp, address: MAILSERVER
|
@@ -66,11 +70,11 @@ def interface_name_vlan_id(name)
|
|
66
70
|
nil
|
67
71
|
end
|
68
72
|
|
69
|
-
def static_neighbor_resolve(
|
70
|
-
key = "#{name}_#{ifname}"
|
73
|
+
def static_neighbor_resolve(sw, ifname)
|
74
|
+
key = "#{sw.name}_#{ifname}"
|
71
75
|
n = STATIC_NEIGHBOR[key]
|
72
76
|
return nil if n.nil?
|
73
|
-
Switch.get(n[:name], Switch::Type::ROUTER, nil, nil, nil, n[:ia])
|
77
|
+
Switch.get(n[:name], Switch::Type::ROUTER, nil, nil, nil, n[:ia], sw)
|
74
78
|
end
|
75
79
|
|
76
80
|
def tunnel_nexthop_resolve(sw, rt)
|
@@ -114,5 +118,3 @@ def router_locate(ia)
|
|
114
118
|
sw.login
|
115
119
|
end
|
116
120
|
end
|
117
|
-
|
118
|
-
end
|
data/lib/netutils/cli.rb
CHANGED
@@ -157,8 +157,8 @@ class LLDP < Parser
|
|
157
157
|
else
|
158
158
|
time = 'unknown'
|
159
159
|
end
|
160
|
-
static_neighbor_resolve(@sw
|
161
|
-
@rsw = Switch.get(rname, type, platform, firmware, time)
|
160
|
+
static_neighbor_resolve(@sw, lport)
|
161
|
+
@rsw = Switch.get(rname, type, platform, firmware, time, nil, @sw)
|
162
162
|
@sw.ports[lport].peers.add(@rsw, nil) # XXX: no way to know remote port...
|
163
163
|
end
|
164
164
|
end
|
data/lib/netutils/switch.rb
CHANGED
@@ -147,21 +147,23 @@ class Switch
|
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
150
|
-
attr_reader :name, :type, :ports, :ia
|
151
|
-
attr_accessor :platform, :firmware, :time
|
150
|
+
attr_reader :name, :type, :ports, :ia, :parent
|
151
|
+
attr_accessor :platform, :firmware, :time, :note
|
152
152
|
|
153
153
|
@@retrieve_all = false
|
154
154
|
@@db = Hash.new
|
155
155
|
@@unretrieved = OnceQueue.new
|
156
156
|
@@warn = Array.new
|
157
157
|
|
158
|
-
def initialize(name, type, ia, retrieve = true)
|
158
|
+
def initialize(name, type, ia, retrieve = true, parent = nil)
|
159
159
|
name_set(name)
|
160
160
|
@type = type
|
161
161
|
@ports = Ports.new
|
162
162
|
@retrieve = retrieve
|
163
163
|
@cli = nil
|
164
164
|
ip_address_set(ia)
|
165
|
+
@parent = parent
|
166
|
+
@note = nil
|
165
167
|
|
166
168
|
return self
|
167
169
|
end
|
@@ -190,6 +192,7 @@ class Switch
|
|
190
192
|
#
|
191
193
|
# retrieve interfaces because many commands require
|
192
194
|
# interface name.
|
195
|
+
# XXX: should improve this...
|
193
196
|
#
|
194
197
|
interface_gets
|
195
198
|
end
|
@@ -309,7 +312,7 @@ class Switch
|
|
309
312
|
end
|
310
313
|
|
311
314
|
def self.get(name, type, platform = nil, firmware = nil, time = nil,
|
312
|
-
ia = nil)
|
315
|
+
ia = nil, parent = nil)
|
313
316
|
# XXX should lock
|
314
317
|
if @@db.key?(name)
|
315
318
|
sw = @@db[name]
|
@@ -318,7 +321,7 @@ class Switch
|
|
318
321
|
sw.time = time if sw.time == nil
|
319
322
|
sw.ip_address_set(ia)
|
320
323
|
else
|
321
|
-
sw = Switch.new(name, type, ia, @@retrieve_all)
|
324
|
+
sw = Switch.new(name, type, ia, @@retrieve_all, parent)
|
322
325
|
end
|
323
326
|
return sw
|
324
327
|
end
|
data/lib/netutils/version.rb
CHANGED
data/netutils.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["ohmori@tottori-u.ac.jp"]
|
11
11
|
|
12
12
|
spec.summary = %q{Networking utitlities to operate network equipment.}
|
13
|
-
spec.description = %q{Networking utitlities to operate network equipment made by Cisco, AlaxalA, NEC IX, Palo Alto, Aruba Wireless Controller and so on.}
|
13
|
+
spec.description = %q{Networking utitlities to operate network equipment made by Cisco, AlaxalA, NEC IX, Palo Alto, Aruba Wireless LAN Controller and so on.}
|
14
14
|
spec.homepage = "https://github.com/ohmori7/netutils"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netutils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Motoyuki OHMORI
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
description: Networking utitlities to operate network equipment made by Cisco, AlaxalA,
|
112
|
-
NEC IX, Palo Alto, Aruba Wireless Controller and so on.
|
112
|
+
NEC IX, Palo Alto, Aruba Wireless LAN Controller and so on.
|
113
113
|
email:
|
114
114
|
- ohmori@tottori-u.ac.jp
|
115
115
|
executables: []
|
@@ -119,8 +119,8 @@ files:
|
|
119
119
|
- ".gitignore"
|
120
120
|
- ".rspec"
|
121
121
|
- ".travis.yml"
|
122
|
-
- CODE_OF_CONDUCT.md
|
123
122
|
- Gemfile
|
123
|
+
- LICENSE
|
124
124
|
- README.md
|
125
125
|
- Rakefile
|
126
126
|
- bin/acl
|
@@ -135,6 +135,8 @@ files:
|
|
135
135
|
- bin/mac-nodrop
|
136
136
|
- bin/port-shutdown
|
137
137
|
- bin/setup
|
138
|
+
- config/.gitignore
|
139
|
+
- config/config-sample.rb
|
138
140
|
- lib/netutils.rb
|
139
141
|
- lib/netutils/arp.rb
|
140
142
|
- lib/netutils/cli.rb
|
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
2
|
-
|
3
|
-
## Our Pledge
|
4
|
-
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
-
orientation.
|
11
|
-
|
12
|
-
## Our Standards
|
13
|
-
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
15
|
-
include:
|
16
|
-
|
17
|
-
* Using welcoming and inclusive language
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
* Gracefully accepting constructive criticism
|
20
|
-
* Focusing on what is best for the community
|
21
|
-
* Showing empathy towards other community members
|
22
|
-
|
23
|
-
Examples of unacceptable behavior by participants include:
|
24
|
-
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
-
advances
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
-
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
30
|
-
address, without explicit permission
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
-
professional setting
|
33
|
-
|
34
|
-
## Our Responsibilities
|
35
|
-
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
38
|
-
response to any instances of unacceptable behavior.
|
39
|
-
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
-
threatening, offensive, or harmful.
|
45
|
-
|
46
|
-
## Scope
|
47
|
-
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
-
when an individual is representing the project or its community. Examples of
|
50
|
-
representing a project or community include using an official project e-mail
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
53
|
-
further defined and clarified by project maintainers.
|
54
|
-
|
55
|
-
## Enforcement
|
56
|
-
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at ohmori@tottori-u.ac.jp. All
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
63
|
-
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
66
|
-
members of the project's leadership.
|
67
|
-
|
68
|
-
## Attribution
|
69
|
-
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
-
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
-
|
73
|
-
[homepage]: http://contributor-covenant.org
|
74
|
-
[version]: http://contributor-covenant.org/version/1/4/
|