cow 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/README.md +43 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cow.gemspec +32 -0
- data/exe/cow +10 -0
- data/lib/cow.rb +17 -0
- data/lib/cow/application.rb +237 -0
- data/lib/cow/plugins/acs.rb +40 -0
- data/lib/cow/plugins/acs5000.rb +40 -0
- data/lib/cow/plugins/acs6000.rb +39 -0
- data/lib/cow/plugins/cisco.rb +54 -0
- data/lib/cow/plugins/digi_ts.rb +46 -0
- data/lib/cow/plugins/tmpl.rb +99 -0
- data/lib/cow/version.rb +3 -0
- metadata +117 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Cow
|
2
|
+
|
3
|
+
Cow - console server wrapper.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
`gem install cow`
|
8
|
+
|
9
|
+
`mkdir /var/cache/cow`
|
10
|
+
|
11
|
+
`sudo cow add [hostname] [type] [community]`
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Type `cow`. Then you can see usage.
|
16
|
+
|
17
|
+
`cow update` should be run periodically.
|
18
|
+
|
19
|
+
## Example
|
20
|
+
|
21
|
+
```
|
22
|
+
$ cow list
|
23
|
+
console.local/1 - tokyo-core01 | ssh -l kazubu:7001 console.local
|
24
|
+
console.local/2 - tokyo-core02 | ssh -l kazubu:7002 console.local
|
25
|
+
console.local/3 - tokyo-sw01 | ssh -l kazubu:7003 console.local
|
26
|
+
console.local/4 - tokyo-sw02 | ssh -l kazubu:7004 console.local
|
27
|
+
console.local/5 - tokyo-serv01 | ssh -l kazubu:7005 console.local
|
28
|
+
console.local/6 - tokyo-serv02 | ssh -l kazubu:7006 console.local
|
29
|
+
console.local/7 - tokyo-serv03 | ssh -l kazubu:7007 console.local
|
30
|
+
console.local/8 - 0F-B3-10P08 | ssh -l kazubu:7008 console.local
|
31
|
+
|
32
|
+
$ cow find core
|
33
|
+
console.local/1 - tokyo-core01 | ssh -l kazubu:7001 console.local
|
34
|
+
console.local/2 - tokyo-core02 | ssh -l kazubu:7002 console.local
|
35
|
+
|
36
|
+
$ cow connect tokyo-core01
|
37
|
+
Found on console.local/1. Connecting...
|
38
|
+
Password:
|
39
|
+
|
40
|
+
tokyo-core01 (ttyd0)
|
41
|
+
|
42
|
+
login:
|
43
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cow"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/cow.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cow/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cow"
|
8
|
+
spec.version = Cow::VERSION
|
9
|
+
spec.authors = ["Kazuki Shimizu"]
|
10
|
+
spec.email = ["kazubu@kazubu.jp"]
|
11
|
+
|
12
|
+
spec.summary = %q{Console server Wrapper}
|
13
|
+
spec.description = %q{Ease to connect console server ports}
|
14
|
+
spec.homepage = "https://www.kazubu.jp/"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
#if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
#else
|
21
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
#end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_dependency 'snmp'
|
32
|
+
end
|
data/exe/cow
ADDED
data/lib/cow.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "cow/version"
|
2
|
+
require "cow/plugins/acs"
|
3
|
+
require "cow/plugins/acs5000"
|
4
|
+
require "cow/plugins/acs6000"
|
5
|
+
require "cow/plugins/digi_ts"
|
6
|
+
require "cow/plugins/cisco"
|
7
|
+
|
8
|
+
module Cow
|
9
|
+
SERVER_TYPES = {
|
10
|
+
acs: Cow::ACS::Server,
|
11
|
+
acs5000: Cow::ACS5000::Server,
|
12
|
+
acs6000: Cow::ACS6000::Server,
|
13
|
+
digi_ts_telnet: Cow::DIGI_TS::Telnet::Server,
|
14
|
+
cisco_telnet: Cow::Cisco::Telnet::Server,
|
15
|
+
cisco_ssh: Cow::Cisco::SSH::Server
|
16
|
+
}
|
17
|
+
end
|
@@ -0,0 +1,237 @@
|
|
1
|
+
require 'cow'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Cow
|
5
|
+
class Application
|
6
|
+
class Cache
|
7
|
+
attr_accessor :servers
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@servers = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_server(_server)
|
14
|
+
@servers.each_with_index{|server, idx|
|
15
|
+
if server.hostname == _server.hostname
|
16
|
+
@servers[idx] = _server
|
17
|
+
return _server
|
18
|
+
end
|
19
|
+
}
|
20
|
+
|
21
|
+
@servers << _server
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
CACHE_FILE = '/var/cache/cow/cow.cache'
|
27
|
+
|
28
|
+
@cache = nil
|
29
|
+
|
30
|
+
def initialize
|
31
|
+
@name = 'cow'
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_cache(_cache = CACHE_FILE)
|
35
|
+
File.write(_cache, Cow::Application::Cache.new.to_yaml)
|
36
|
+
end
|
37
|
+
|
38
|
+
def load_cache(_cache = CACHE_FILE)
|
39
|
+
unless File.exist?(_cache)
|
40
|
+
puts 'Cache file is not found. Creating...'
|
41
|
+
create_cache(_cache)
|
42
|
+
end
|
43
|
+
|
44
|
+
if File.size(_cache) < 5
|
45
|
+
puts 'Cache file looks empty. Creating...'
|
46
|
+
create_cache(_cache)
|
47
|
+
end
|
48
|
+
|
49
|
+
cache = YAML.load(File.read(_cache))
|
50
|
+
|
51
|
+
if cache.class == Cow::Application::Cache
|
52
|
+
@cache = cache
|
53
|
+
else
|
54
|
+
raise 'Cache file is corrupt?'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def edit_cache(_cache = CACHE_FILE)
|
59
|
+
unless @cache
|
60
|
+
load_cache
|
61
|
+
end
|
62
|
+
|
63
|
+
cache = @cache
|
64
|
+
|
65
|
+
File.open(_cache, 'w') do |file|
|
66
|
+
puts 'Updating cache file.'
|
67
|
+
if file.flock(File::LOCK_EX|File::LOCK_NB)
|
68
|
+
|
69
|
+
begin
|
70
|
+
yield cache
|
71
|
+
rescue
|
72
|
+
cache = @cache
|
73
|
+
end
|
74
|
+
|
75
|
+
if cache.class == Cow::Application::Cache
|
76
|
+
file.write(cache.to_yaml)
|
77
|
+
else
|
78
|
+
file.write(@cache.to_yaml)
|
79
|
+
end
|
80
|
+
else
|
81
|
+
raise 'File is already locked.'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
load_cache(_cache)
|
85
|
+
end
|
86
|
+
|
87
|
+
def run
|
88
|
+
command = ARGV[0]
|
89
|
+
option1 = ARGV[1]
|
90
|
+
option2 = ARGV[2]
|
91
|
+
option3 = ARGV[3]
|
92
|
+
|
93
|
+
case command
|
94
|
+
when 'add', 'a'
|
95
|
+
cmd_add(option1, option2, option3)
|
96
|
+
when 'connect', 'c'
|
97
|
+
cmd_connect(option1)
|
98
|
+
when 'find', 'f'
|
99
|
+
cmd_find(option1)
|
100
|
+
when 'list', 'l'
|
101
|
+
cmd_list(option1)
|
102
|
+
when 'server-list', 's'
|
103
|
+
cmd_server_list
|
104
|
+
when 'update', 'u'
|
105
|
+
cmd_update(option1)
|
106
|
+
else
|
107
|
+
show_help
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def cmd_add(_hostname, _type, _snmp_community)
|
112
|
+
raise ArgumentError unless _hostname.class == String && _type.class == String && _snmp_community.class == String
|
113
|
+
raise ArgumentError unless Cow::SERVER_TYPES.keys.include?(_type.to_sym)
|
114
|
+
|
115
|
+
puts "#{_hostname}(#{_type}) will be added"
|
116
|
+
|
117
|
+
server = Cow::SERVER_TYPES[_type.to_sym].new(_hostname, _snmp_community)
|
118
|
+
|
119
|
+
server.ports.each do |port|
|
120
|
+
puts "%s %s" % ["#{server.hostname.to_s}/#{port.port.to_s}".ljust(30), port.name.to_s.ljust(20) ]
|
121
|
+
end
|
122
|
+
|
123
|
+
load_cache
|
124
|
+
|
125
|
+
edit_cache do |cache|
|
126
|
+
cache.add_server server
|
127
|
+
end if server
|
128
|
+
end
|
129
|
+
|
130
|
+
def cmd_connect(_portname)
|
131
|
+
raise ArgumentError unless _portname.class == String
|
132
|
+
|
133
|
+
load_cache
|
134
|
+
|
135
|
+
@cache.servers.each do |server|
|
136
|
+
server.find(_portname).each do |port|
|
137
|
+
if port.name == _portname
|
138
|
+
puts "Found on #{server.hostname}/#{port.port}. Connecting..."
|
139
|
+
server.connect(port)
|
140
|
+
end
|
141
|
+
return
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def cmd_find(_keyword)
|
147
|
+
raise ArgumentError unless _keyword.class == String
|
148
|
+
|
149
|
+
load_cache
|
150
|
+
puts "%s %s %s" % ["SERVER/PORT".ljust(30), "PORTNAME".ljust(20), "COMMAND"]
|
151
|
+
|
152
|
+
@cache.servers.each do |server|
|
153
|
+
server.find(_keyword).each do |port|
|
154
|
+
puts "%s %s %s" % ["#{server.hostname.to_s}/#{port.port.to_s}".ljust(30), port.name.to_s.ljust(20), server.connect_command(port)]
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def cmd_list(_hostname)
|
160
|
+
load_cache
|
161
|
+
puts "%s %s %s" % ["SERVER/PORT".ljust(30), "PORTNAME".ljust(20), "COMMAND"]
|
162
|
+
|
163
|
+
@cache.servers.each do |server|
|
164
|
+
if _hostname.nil? || server.hostname == _hostname
|
165
|
+
server.ports.each do |port|
|
166
|
+
puts "%s %s %s" % ["#{server.hostname.to_s}/#{port.port.to_s}".ljust(30), port.name.to_s.ljust(20), server.connect_command(port)]
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def cmd_server_list
|
173
|
+
load_cache
|
174
|
+
puts "SERVER(TYPE)"
|
175
|
+
|
176
|
+
@cache.servers.each do |server|
|
177
|
+
type = nil
|
178
|
+
Cow::SERVER_TYPES.each_key{|t| type = t if Cow::SERVER_TYPES[t] == server.class}
|
179
|
+
|
180
|
+
puts "#{server.hostname}(#{type})"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def cmd_update(_hostname)
|
185
|
+
load_cache
|
186
|
+
|
187
|
+
puts "Updating local cache..."
|
188
|
+
puts "%s %s" % ["SERVER/PORT".ljust(30), "PORTNAME".ljust(20)]
|
189
|
+
|
190
|
+
edit_cache do |cache|
|
191
|
+
cache.servers.each do |server|
|
192
|
+
if _hostname.nil? || server.hostname == _hostname
|
193
|
+
puts "Updating server #{server.hostname}"
|
194
|
+
server.update_ports
|
195
|
+
|
196
|
+
server.ports.each do |port|
|
197
|
+
puts "%s %s" % ["#{server.hostname.to_s}/#{port.port.to_s}".ljust(30), port.name.to_s.ljust(20) ]
|
198
|
+
end
|
199
|
+
|
200
|
+
cache.add_server server
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def show_help
|
207
|
+
puts <<EOF
|
208
|
+
cow - Console Server Wrapper
|
209
|
+
|
210
|
+
Usage:
|
211
|
+
cow [command] [options]
|
212
|
+
|
213
|
+
Commands:
|
214
|
+
add [hostname] [type] [snmp_community]
|
215
|
+
Add new console server.
|
216
|
+
available types: #{Cow::SERVER_TYPES.keys.join(' ')}
|
217
|
+
|
218
|
+
connect [portname]
|
219
|
+
Connect to console port.
|
220
|
+
|
221
|
+
find [keyword]
|
222
|
+
Find console port which includes given name.
|
223
|
+
|
224
|
+
list [hostname(optional)]
|
225
|
+
Show console server port list. If hostname is not specified,
|
226
|
+
all console ports will be shown.
|
227
|
+
|
228
|
+
server-list
|
229
|
+
Show all console servers.
|
230
|
+
|
231
|
+
update [hostname(optional)]
|
232
|
+
Update console server port list. If hostname is not specified,
|
233
|
+
all port lists will be updated.
|
234
|
+
EOF
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'cow/plugins/tmpl'
|
2
|
+
require 'snmp'
|
3
|
+
|
4
|
+
module Cow
|
5
|
+
module ACS
|
6
|
+
OID_DESCRIPTION_LIST = '1.3.6.1.4.1.2925.4.2.6.2.1.1.3'
|
7
|
+
OID_TCPPORT_LIST = '1.3.6.1.4.1.2925.4.2.6.2.1.1.26'
|
8
|
+
|
9
|
+
class Port < Cow::Tmpl::Port
|
10
|
+
end
|
11
|
+
|
12
|
+
class Server < Cow::Tmpl::Server
|
13
|
+
def port(_port)
|
14
|
+
return _port if _port.class == Cow::ACS::Port
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def connect_command(_port, _user = ENV['USER'])
|
19
|
+
return "ssh -l #{_user}:#{port(_port).tcp_port} #{@hostname}"
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def get_ports
|
25
|
+
ret = []
|
26
|
+
snmp{|s|
|
27
|
+
s.walk(OID_DESCRIPTION_LIST){|x|
|
28
|
+
next if x.name.last == 0
|
29
|
+
port = x.name.last
|
30
|
+
name = x.value.to_s
|
31
|
+
tcp_port = snmp{|s| break s.get_value(OID_TCPPORT_LIST + ".#{x.name.last.to_s}")}
|
32
|
+
|
33
|
+
ret << Cow::ACS::Port.new(port, name, tcp_port)
|
34
|
+
}
|
35
|
+
}
|
36
|
+
return ret
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'cow/plugins/tmpl'
|
2
|
+
require 'snmp'
|
3
|
+
|
4
|
+
module Cow
|
5
|
+
module ACS5000
|
6
|
+
OID_DESCRIPTION_LIST = '1.3.6.1.4.1.10418.15.2.2.6.2.1.1.3'
|
7
|
+
OID_TCPPORT_LIST = '1.3.6.1.4.1.10418.15.2.2.6.2.1.1.26'
|
8
|
+
|
9
|
+
class Port < Cow::Tmpl::Port
|
10
|
+
end
|
11
|
+
|
12
|
+
class Server < Cow::Tmpl::Server
|
13
|
+
def port(_port)
|
14
|
+
return _port if _port.class == Cow::ACS5000::Port
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def connect_command(_port, _user = ENV['USER'])
|
19
|
+
return "ssh -l #{_user}:#{port(_port).tcp_port} #{@hostname}"
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def get_ports
|
25
|
+
ret = []
|
26
|
+
snmp{|s|
|
27
|
+
s.walk(OID_DESCRIPTION_LIST){|x|
|
28
|
+
next if x.name.last == 0
|
29
|
+
port = x.name.last
|
30
|
+
name = x.value.to_s
|
31
|
+
tcp_port = snmp{|s| break s.get_value(OID_TCPPORT_LIST + ".#{x.name.last.to_s}")}
|
32
|
+
|
33
|
+
ret << Cow::ACS5000::Port.new(port, name, tcp_port)
|
34
|
+
}
|
35
|
+
}
|
36
|
+
return ret
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'cow/plugins/tmpl'
|
2
|
+
require 'snmp'
|
3
|
+
|
4
|
+
module Cow
|
5
|
+
module ACS6000
|
6
|
+
OID_DESCRIPTION_LIST = '1.3.6.1.4.1.10418.16.2.3.2.1.4'
|
7
|
+
|
8
|
+
class Port < Cow::Tmpl::Port
|
9
|
+
end
|
10
|
+
|
11
|
+
class Server < Cow::Tmpl::Server
|
12
|
+
def port(_port)
|
13
|
+
return _port if _port.class == Cow::ACS6000::Port
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def connect_command(_port, _user = ENV['USER'])
|
18
|
+
return "ssh -l #{_user}:#{port(_port).tcp_port} #{@hostname}"
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def get_ports
|
24
|
+
ret = []
|
25
|
+
snmp{|s|
|
26
|
+
s.walk(OID_DESCRIPTION_LIST){|x|
|
27
|
+
next if x.name.last == 0
|
28
|
+
port = x.name.last
|
29
|
+
name = x.value.to_s
|
30
|
+
tcp_port = port.to_i + 7000
|
31
|
+
|
32
|
+
ret << Cow::ACS6000::Port.new(port, name, tcp_port)
|
33
|
+
}
|
34
|
+
}
|
35
|
+
return ret
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'cow/plugins/tmpl'
|
2
|
+
require 'snmp'
|
3
|
+
|
4
|
+
module Cow
|
5
|
+
module Cisco
|
6
|
+
OID_DESCRIPTION_LIST = '1.3.6.1.4.1.9.2.9.2.1.8'
|
7
|
+
|
8
|
+
class Port < Cow::Tmpl::Port
|
9
|
+
end
|
10
|
+
|
11
|
+
module Server
|
12
|
+
def port(_port)
|
13
|
+
return _port if _port.class == Cow::Cisco::Port
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_ports
|
18
|
+
ret = []
|
19
|
+
snmp{|s|
|
20
|
+
s.walk(OID_DESCRIPTION_LIST){|x|
|
21
|
+
next if x.name.last == 0
|
22
|
+
next if x.value.to_s.length == 0
|
23
|
+
port = x.name.last
|
24
|
+
name = x.value.to_s
|
25
|
+
tcp_port = 2000 + port.to_i
|
26
|
+
|
27
|
+
ret << Cow::Cisco::Port.new(port, name, tcp_port)
|
28
|
+
}
|
29
|
+
}
|
30
|
+
return ret
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module Telnet
|
35
|
+
class Server < Cow::Tmpl::Server
|
36
|
+
include Cow::Cisco::Server
|
37
|
+
|
38
|
+
def connect_command(_port, _user = ENV['USER'])
|
39
|
+
return "telnet #{@hostname} #{port(_port).tcp_port}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module SSH
|
45
|
+
class Server < Cow::Tmpl::Server
|
46
|
+
include Cow::Cisco::Server
|
47
|
+
|
48
|
+
def connect_command(_port, _user = ENV['USER'])
|
49
|
+
return "ssh -l #{_user}:#{port(_port).port} #{@hostname}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'cow/plugins/tmpl'
|
2
|
+
require 'snmp'
|
3
|
+
|
4
|
+
module Cow
|
5
|
+
module DIGI_TS
|
6
|
+
OID_DESCRIPTION_LIST = '1.3.6.1.4.1.332.11.5.3.3.25.13.1.29'
|
7
|
+
OID_TCPPORT_BASE = '1.3.6.1.4.1.332.11.5.3.3.20.22.0'
|
8
|
+
|
9
|
+
class Port < Cow::Tmpl::Port
|
10
|
+
end
|
11
|
+
|
12
|
+
module Telnet
|
13
|
+
class Server < Cow::Tmpl::Server
|
14
|
+
def port(_port)
|
15
|
+
return _port if _port.class == Cow::DIGI_TS::Port
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def connect_command(_port, _user = ENV['USER'])
|
20
|
+
#return "ssh -l #{_user}:#{port(_port).tcp_port+500} #{@hostname}"
|
21
|
+
return "telnet #{@hostname} #{port(_port).tcp_port}"
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def get_ports
|
27
|
+
ret = []
|
28
|
+
|
29
|
+
base_port = snmp{|s| break s.get_value(OID_TCPPORT_BASE)}
|
30
|
+
|
31
|
+
snmp{|s|
|
32
|
+
s.walk(OID_DESCRIPTION_LIST){|x|
|
33
|
+
next if x.value.to_s.chomp.length == 0
|
34
|
+
port = x.name.last
|
35
|
+
name = x.value.to_s
|
36
|
+
tcp_port = base_port + port.to_i
|
37
|
+
|
38
|
+
ret << Cow::DIGI_TS::Port.new(port, name, tcp_port)
|
39
|
+
}
|
40
|
+
}
|
41
|
+
return ret
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'snmp'
|
2
|
+
|
3
|
+
module Cow
|
4
|
+
module Tmpl
|
5
|
+
class Port
|
6
|
+
attr_accessor :port, :name, :tcp_port
|
7
|
+
|
8
|
+
@port = nil
|
9
|
+
@name = nil
|
10
|
+
@tcp_port = nil
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(_port, _name, _tcp_port)
|
16
|
+
raise ArgumentError if _port.nil? or _name.nil? or _tcp_port.nil?
|
17
|
+
|
18
|
+
@port = _port.to_s
|
19
|
+
@name = _name.to_s
|
20
|
+
@tcp_port = _tcp_port.to_s
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Server
|
25
|
+
attr_accessor :hostname
|
26
|
+
|
27
|
+
@hostname = nil
|
28
|
+
@snmp_community = nil
|
29
|
+
@ports = nil
|
30
|
+
|
31
|
+
def initialize
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize(_hostname, _snmp_community)
|
35
|
+
@hostname = _hostname
|
36
|
+
@snmp_community = _snmp_community
|
37
|
+
|
38
|
+
@ports = get_ports
|
39
|
+
end
|
40
|
+
|
41
|
+
def ports
|
42
|
+
update_ports unless @ports
|
43
|
+
return @ports
|
44
|
+
end
|
45
|
+
|
46
|
+
def update_ports
|
47
|
+
@ports = get_ports
|
48
|
+
end
|
49
|
+
|
50
|
+
def port(_port)
|
51
|
+
case _port
|
52
|
+
when Fixnum
|
53
|
+
ports.each{|p|
|
54
|
+
return p if p.port == _port
|
55
|
+
}
|
56
|
+
when String
|
57
|
+
ports.each{|p|
|
58
|
+
return p if p.name == _port
|
59
|
+
}
|
60
|
+
else
|
61
|
+
end
|
62
|
+
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
|
66
|
+
def find(_portname)
|
67
|
+
_ports = []
|
68
|
+
ports.each{|p|
|
69
|
+
_ports << p if p.name.include?(_portname)
|
70
|
+
}
|
71
|
+
return _ports
|
72
|
+
end
|
73
|
+
|
74
|
+
def connect_command(_port, _user = ENV['USER'])
|
75
|
+
raise NotImplementedError
|
76
|
+
end
|
77
|
+
|
78
|
+
def connect(_port, _user = nil)
|
79
|
+
if _user
|
80
|
+
system(connect_command(_port, _user))
|
81
|
+
else
|
82
|
+
system(connect_command(_port))
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def get_ports
|
89
|
+
raise NotImplementedError
|
90
|
+
end
|
91
|
+
|
92
|
+
def snmp
|
93
|
+
SNMP::Manager.open(:host => @hostname, :community => @snmp_community) do|snmp|
|
94
|
+
yield(snmp)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/lib/cow/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kazuki Shimizu
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-09-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.12'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.12'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '10.0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '10.0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: snmp
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Ease to connect console server ports
|
63
|
+
email:
|
64
|
+
- kazubu@kazubu.jp
|
65
|
+
executables:
|
66
|
+
- cow
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- bin/console
|
75
|
+
- bin/setup
|
76
|
+
- cow.gemspec
|
77
|
+
- exe/cow
|
78
|
+
- lib/cow.rb
|
79
|
+
- lib/cow/application.rb
|
80
|
+
- lib/cow/plugins/acs.rb
|
81
|
+
- lib/cow/plugins/acs5000.rb
|
82
|
+
- lib/cow/plugins/acs6000.rb
|
83
|
+
- lib/cow/plugins/cisco.rb
|
84
|
+
- lib/cow/plugins/digi_ts.rb
|
85
|
+
- lib/cow/plugins/tmpl.rb
|
86
|
+
- lib/cow/version.rb
|
87
|
+
homepage: https://www.kazubu.jp/
|
88
|
+
licenses: []
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
hash: -2846258190445444436
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
hash: -2846258190445444436
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.8.23
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: Console server Wrapper
|
117
|
+
test_files: []
|