xlogin 0.4.14 → 0.5.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/Gemfile.lock +5 -1
- data/bin/xlogin +8 -5
- data/lib/xlogin.rb +40 -32
- data/lib/xlogin/cli.rb +108 -127
- data/lib/xlogin/firmware.rb +1 -1
- data/lib/xlogin/firmware_factory.rb +21 -12
- data/lib/xlogin/rake_task.rb +3 -3
- data/lib/xlogin/templates/ios.rb +1 -19
- data/lib/xlogin/templates/iosxr.rb +0 -11
- data/lib/xlogin/templates/junos.rb +0 -8
- data/lib/xlogin/templates/sros.rb +1 -11
- data/lib/xlogin/templates/vyos.rb +0 -16
- data/lib/xlogin/version.rb +1 -1
- data/xlogin.gemspec +2 -0
- metadata +30 -3
- data/bin/cmd_exec +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d656e29734d6e44b7e0e695c4cfa141c854ab562
|
4
|
+
data.tar.gz: 0f7ca0a2ba490af8ea8a3dba9c4e2b6fcb7e5e45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3da45706566105b37510e176fd01a9535f4f7f45fd9452b885b8120b7794eee34b056def26e4c8e0381046428d423064122f1b0996eb06aac4c7045d6fb763d
|
7
|
+
data.tar.gz: abb59cbe0a4af8d2f3dbe75a2a8913f00d105317a962028df28e27529b321191c5db163b823ba294fa4145bca6d81df2f4732dd185f9ad010272472432c59d6f
|
data/Gemfile.lock
CHANGED
@@ -1,21 +1,25 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
xlogin (0.
|
4
|
+
xlogin (0.5.2)
|
5
|
+
io-console
|
5
6
|
net-ssh
|
6
7
|
net-ssh-gateway
|
7
8
|
net-ssh-telnet
|
8
9
|
net-telnet
|
10
|
+
parallel
|
9
11
|
|
10
12
|
GEM
|
11
13
|
remote: https://rubygems.org/
|
12
14
|
specs:
|
15
|
+
io-console (0.4.6)
|
13
16
|
net-ssh (4.1.0)
|
14
17
|
net-ssh-gateway (2.0.0)
|
15
18
|
net-ssh (>= 4.0.0)
|
16
19
|
net-ssh-telnet (0.2.0)
|
17
20
|
net-ssh (>= 2.0.1)
|
18
21
|
net-telnet (0.1.1)
|
22
|
+
parallel (1.12.0)
|
19
23
|
rake (10.5.0)
|
20
24
|
|
21
25
|
PLATFORMS
|
data/bin/xlogin
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
require 'xlogin/cli'
|
3
|
+
appdir = File.dirname(File.symlink?(__FILE__)? File.readlink(__FILE__) : __FILE__)
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
require 'bundler'
|
6
|
+
ENV['BUNDLE_GEMFILE'] = File.join(appdir, '..', 'Gemfile')
|
7
|
+
|
8
|
+
Bundler.require
|
9
|
+
|
10
|
+
require File.join(appdir, '..', 'lib', 'xlogin.rb')
|
11
|
+
require File.join(appdir, '..', 'lib', 'xlogin', 'cli.rb')
|
8
12
|
|
9
|
-
Xlogin.source
|
10
13
|
Xlogin::CLI.run
|
data/lib/xlogin.rb
CHANGED
@@ -6,51 +6,40 @@ require 'xlogin/version'
|
|
6
6
|
|
7
7
|
module Xlogin
|
8
8
|
|
9
|
-
|
9
|
+
DEFAULT_SOURCE_FILE = File.join(ENV['HOME'], '.xloginrc')
|
10
|
+
DEFAULT_TEMPLATE_DIR = File.join(ENV['HOME'], '.xlogin.d')
|
11
|
+
BUILTIN_TEMPLATE_FILES = Dir.glob(File.join(File.dirname(__FILE__), 'xlogin', 'templates', '*.rb'))
|
10
12
|
|
11
|
-
|
13
|
+
class GeneralError < StandardError; end
|
12
14
|
|
13
15
|
class << self
|
14
|
-
def factory
|
15
|
-
@factory ||= load_templates
|
16
|
-
end
|
17
16
|
|
18
|
-
def
|
19
|
-
|
17
|
+
def init(&block)
|
18
|
+
instance_eval(&block)
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
factory = Xlogin::FirmwareFactory.instance
|
21
|
+
factory.source(DEFAULT_SOURCE_FILE) if factory.list.empty?
|
22
|
+
if factory.list_templates.empty?
|
23
|
+
unless File.exist?(DEFAULT_TEMPLATE_DIR)
|
24
|
+
FileUtils.mkdir_p(DEFAULT_TEMPLATE_DIR)
|
25
|
+
Xlogin::BUILTIN_TEMPLATE_FILES.each { |file| FileUtils.cp(file, DEFAULT_TEMPLATE_DIR) }
|
26
|
+
end
|
27
|
+
factory.load_template_files(*Dir.glob(File.join(DEFAULT_TEMPLATE_DIR, '*.rb')))
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
|
-
def source(
|
30
|
-
|
31
|
-
|
32
|
-
source_names = ['_xloginrc', '.xloginrc']
|
33
|
-
source_files += source_dirs.product(source_names).map { |d, n| File.join(d, n) }
|
34
|
-
end
|
35
|
-
|
36
|
-
_factory = Xlogin::FirmwareFactory.instance
|
37
|
-
_factory.source(*source_files)
|
31
|
+
def source(source_file)
|
32
|
+
factory = Xlogin::FirmwareFactory.instance
|
33
|
+
factory.source(source_file)
|
38
34
|
end
|
39
35
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
yield template if block_given?
|
44
|
-
_factory.set_template(name, template)
|
45
|
-
end
|
46
|
-
|
47
|
-
def alias(new_name, name)
|
48
|
-
_factory = Xlogin::FirmwareFactory.instance
|
49
|
-
_factory.alias_template(new_name, name)
|
36
|
+
def template(*template_files)
|
37
|
+
factory = Xlogin::FirmwareFactory.instance
|
38
|
+
factory.load_template_files(*template_files)
|
50
39
|
end
|
51
40
|
|
52
41
|
def get(hostname, args = {})
|
53
|
-
|
42
|
+
factory = Xlogin::FirmwareFactory.instance
|
54
43
|
session = factory.build_from_hostname(hostname, args)
|
55
44
|
|
56
45
|
if block_given?
|
@@ -59,6 +48,25 @@ module Xlogin
|
|
59
48
|
session
|
60
49
|
end
|
61
50
|
end
|
51
|
+
|
52
|
+
def template_dir(*template_dirs)
|
53
|
+
template_dirs.each do |template_dir|
|
54
|
+
template(*Dir.glob(File.join(template_dir, '*.rb')))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def configure(name)
|
59
|
+
factory = Xlogin::FirmwareFactory.instance
|
60
|
+
template = factory.get_template(name) || Xlogin::Firmware.new
|
61
|
+
yield template if block_given?
|
62
|
+
factory.set_template(name, template)
|
63
|
+
end
|
64
|
+
|
65
|
+
def alias(new_name, name)
|
66
|
+
factory = Xlogin::FirmwareFactory.instance
|
67
|
+
factory.alias_template(new_name, name)
|
68
|
+
end
|
69
|
+
|
62
70
|
end
|
63
71
|
|
64
72
|
end
|
data/lib/xlogin/cli.rb
CHANGED
@@ -1,168 +1,149 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
|
3
|
+
require 'fileutils'
|
3
4
|
require 'optparse'
|
5
|
+
require 'ostruct'
|
6
|
+
require 'parallel'
|
4
7
|
require 'readline'
|
5
8
|
require 'stringio'
|
6
9
|
require 'thread'
|
7
10
|
|
8
11
|
module Xlogin
|
9
|
-
|
10
|
-
class ThreadPool
|
11
|
-
|
12
|
-
def initialize(size)
|
13
|
-
@jobs = Array.new
|
14
|
-
@lock = Queue.new
|
15
|
-
|
16
|
-
@size = size
|
17
|
-
@size.times { @lock.push :token }
|
18
|
-
|
19
|
-
begin yield(self) ensure join end if block_given?
|
20
|
-
end
|
21
|
-
|
22
|
-
def run
|
23
|
-
@jobs << Thread.new do
|
24
|
-
token = @lock.pop
|
25
|
-
yield
|
26
|
-
@lock.push token
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def join
|
31
|
-
@jobs.each { |job| job.join }
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
12
|
class CLI
|
37
13
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
opt = OptionParser.new
|
42
|
-
opt.on('-e', '--enable', 'Try to gain enable priviledge.') { |v| options[:e] = v }
|
43
|
-
opt.on('-l', '--log', 'Enable logging.') { |v| options[:l] = v }
|
14
|
+
DEFAULT_INVENTORY_PATH = File.join(ENV['HOME'], '.xloginrc')
|
15
|
+
DEFAULT_TEMPLATE_DIR = File.join(ENV['HOME'], '.xlogin.d')
|
44
16
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
17
|
+
def self.getopts(args)
|
18
|
+
config = OpenStruct.new(
|
19
|
+
func: 'tty',
|
20
|
+
inventory: DEFAULT_INVENTORY_PATH,
|
21
|
+
parallels: 5,
|
22
|
+
templates: [],
|
23
|
+
hostexprs: [],
|
24
|
+
hostlist: [],
|
25
|
+
)
|
26
|
+
|
27
|
+
parser = OptionParser.new
|
28
|
+
parser.banner += ' HOST-PATTERN'
|
29
|
+
|
30
|
+
parser.on('-f FUNCTION', '--func', String, 'Execute the FUNCTION (default: tty).') { |v| config.func = v }
|
31
|
+
parser.on('-a ARGUMENTS', '--args', String, 'The ARGUMENTS to pass to the function.') { |v| config.args = v }
|
32
|
+
|
33
|
+
parser.on('-i PATH', '--inventory', String, 'The PATH to the inventory file (default: $HOME/.xloginrc).') { |v| config.inventory = v }
|
34
|
+
parser.on('-t PATH', '--template', String, 'The PATH to the template file.') { |v| config.templates << v }
|
35
|
+
parser.on('-T DIRECTORY', '--template-dir', String, 'The DIRECTORY to the template files.') { |v| config.templates += Dir.glob(File.join(v, '*.rb')) }
|
36
|
+
parser.on('-l [DIRECTORY]', '--log', String, 'The DIRECTORY to the output log file (default: $PWD/log).') { |v| config.logdir = v || Dir.pwd }
|
37
|
+
|
38
|
+
parser.on('-p NUM', '--parallels', Integer, 'The NUM of the threads. (default: 5).') { |v| config.parallels = v }
|
39
|
+
parser.on('-e', '--enable', TrueClass, 'Try to gain enable priviledge.') { |v| config.enable = v }
|
40
|
+
parser.on('-y', '--assumeyes', TrueClass, 'Always answer "yes" if confirmed.') { |v| config.assumeyes = v }
|
41
|
+
parser.on('-h', '--help', 'Show this message.') { Xlogin::CLI.usage }
|
49
42
|
|
50
43
|
self.class.module_eval do
|
51
|
-
define_method(:usage) do |
|
52
|
-
puts
|
53
|
-
puts
|
44
|
+
define_method(:usage) do |message = nil|
|
45
|
+
puts message, '' if message
|
46
|
+
puts parser.to_s
|
54
47
|
exit 1
|
55
48
|
end
|
56
49
|
end
|
57
50
|
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
def self.run(args = ARGV)
|
63
|
-
options, args = getopts(args)
|
51
|
+
config.hostexprs = parser.parse(args)
|
52
|
+
config.templates = Dir.glob(File.join(DEFAULT_TEMPLATE_DIR, '*.rb')) if config.templates.empty?
|
64
53
|
|
65
|
-
|
66
|
-
|
67
|
-
|
54
|
+
Xlogin.init do
|
55
|
+
source(config.inventory)
|
56
|
+
template(*config.templates)
|
68
57
|
end
|
69
58
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
loggers.push("#{target}.log") if options[:l]
|
59
|
+
factory = Xlogin::FirmwareFactory.instance
|
60
|
+
config.hostlist += config.hostexprs.flat_map { |expr| factory.list(expr) }
|
61
|
+
config
|
62
|
+
end
|
75
63
|
|
76
|
-
|
77
|
-
|
64
|
+
def self.run(args = ARGV)
|
65
|
+
config = getopts(args)
|
66
|
+
client = Xlogin::CLI.new
|
67
|
+
func = config.func.gsub(/([a-z\d])([A-Z])/, '\1_\2').gsub(/[-_]+/, '_').downcase
|
78
68
|
|
79
|
-
|
80
|
-
|
81
|
-
rescue => e
|
82
|
-
$stderr.puts("#{e}\n\n")
|
83
|
-
raise
|
69
|
+
Xlogin::CLI.usage("Function not found - #{config.func}") unless client.respond_to?(func)
|
70
|
+
client.method(func).call(config)
|
84
71
|
end
|
85
72
|
|
86
|
-
|
73
|
+
def list(config)
|
74
|
+
if config.hostexprs.empty?
|
75
|
+
factory = Xlogin::FirmwareFactory.instance
|
76
|
+
config.hostlist = factory.list
|
77
|
+
end
|
87
78
|
|
88
|
-
|
79
|
+
length = config.hostlist.map { |e| e[:name].length }.max
|
80
|
+
matrix = config.hostlist.map { |e| "#{e[:name].to_s.ljust(length)} #{e[:type]}" }.sort
|
81
|
+
puts matrix
|
82
|
+
end
|
89
83
|
|
90
|
-
def
|
91
|
-
|
84
|
+
def tty(config)
|
85
|
+
Xlogin::CLI.usage('Invalid HOST-PATTERN') if config.hostlist.empty?
|
92
86
|
|
93
|
-
|
94
|
-
|
95
|
-
opt.on('-e', '--enable', 'Try to gain enable priviledge.') { |v| options[:e] = v }
|
96
|
-
opt.on('-l', '--log', 'Enable logging.') { |v| options[:l] = v }
|
97
|
-
opt.on('-H', 'Display hostnames for each response.') { |v| options[:H] = v }
|
87
|
+
puts "Trying #{config.hostlist.first}..."
|
88
|
+
puts "Escape character is '^]'."
|
98
89
|
|
99
|
-
|
90
|
+
config.hostlist = [config.hostlist.shift]
|
91
|
+
login(config) do |session|
|
92
|
+
session.interact!
|
93
|
+
end
|
94
|
+
end
|
100
95
|
|
101
|
-
|
102
|
-
|
96
|
+
def command(config)
|
97
|
+
Xlogin::CLI.usage('Missing argument') unless config.args
|
103
98
|
|
104
|
-
|
105
|
-
|
99
|
+
login(config) do |session|
|
100
|
+
command_lines = ['', *config.args.split(';')]
|
101
|
+
command_lines.each { |command| session.cmd(command) }
|
102
|
+
end
|
103
|
+
end
|
106
104
|
|
107
|
-
|
108
|
-
|
105
|
+
def command_load(config)
|
106
|
+
Xlogin::CLI.usage('Missing argument') unless config.args
|
109
107
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
puts "error: #{msg}" if msg
|
114
|
-
exit 1
|
115
|
-
end
|
108
|
+
login(config) do |session|
|
109
|
+
command_lines = ['', *IO.readlines(config.args.to_s)]
|
110
|
+
command_lines.each { |command| session.cmd(command) }
|
116
111
|
end
|
117
|
-
|
118
|
-
opt.parse!(args)
|
119
|
-
return options, args
|
120
112
|
end
|
121
113
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
['', *commands].map { |command| resp.print session.cmd(command) }
|
152
|
-
elsif options[:c]
|
153
|
-
resp.puts session.send(options[:c].to_sym)
|
154
|
-
end
|
155
|
-
|
156
|
-
content = resp.string
|
157
|
-
content = content.lines.map { |line| "#{node}: #{line}" }.join if options[:H]
|
158
|
-
|
159
|
-
$stdout.puts content if size > 1
|
160
|
-
rescue => e
|
161
|
-
$stderr.puts "Something goes wrong with '#{node}' - #{e}"
|
162
|
-
end
|
114
|
+
private
|
115
|
+
def login(config)
|
116
|
+
display = Mutex.new
|
117
|
+
config.parallels = [config.parallels, config.hostlist.size].min
|
118
|
+
FileUtils.mkdir_p(config.logdir) if config.logdir
|
119
|
+
|
120
|
+
Parallel.each(config.hostlist, in_thread: config.parallels) do |host|
|
121
|
+
begin
|
122
|
+
hostname = host[:name]
|
123
|
+
buffer = StringIO.new
|
124
|
+
loggers = []
|
125
|
+
loggers << buffer if config.parallels != 1
|
126
|
+
loggers << $stdout if config.parallels == 1
|
127
|
+
loggers << File.join(config.logdir, "#{hostname}.log") if config.logdir
|
128
|
+
|
129
|
+
session = Xlogin.get(hostname, assumeyes: config.assumeyes, enable: config.enable, log: loggers)
|
130
|
+
yield session
|
131
|
+
|
132
|
+
if config.parallels > 1
|
133
|
+
output = buffer.string.lines.map { |line| "#{hostname}: #{line}" }.join
|
134
|
+
display.synchronize { $stdout.puts output }
|
135
|
+
end
|
136
|
+
rescue => e
|
137
|
+
if config.parallels > 1
|
138
|
+
output = "\n#{hostname}: [Error] #{e}"
|
139
|
+
display.synchronize { $stderr.puts output }
|
140
|
+
else
|
141
|
+
output = "\n[Error] #{e}"
|
142
|
+
display.synchronize { $stderr.puts output }
|
163
143
|
end
|
164
144
|
end
|
165
145
|
end
|
166
146
|
end
|
147
|
+
|
167
148
|
end
|
168
149
|
end
|
data/lib/xlogin/firmware.rb
CHANGED
@@ -12,11 +12,13 @@ module Xlogin
|
|
12
12
|
@database = Hash.new
|
13
13
|
@templates = Hash.new
|
14
14
|
@aliases = Hash.new
|
15
|
+
@group = nil
|
15
16
|
end
|
16
17
|
|
17
|
-
def
|
18
|
+
def load_template_files(*files)
|
18
19
|
files.each do |file|
|
19
|
-
|
20
|
+
next unless File.exist?(file) && file =~ /.rb$/
|
21
|
+
require file
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
@@ -38,11 +40,9 @@ module Xlogin
|
|
38
40
|
@aliases[new_name.to_s.downcase] = name.to_s.downcase
|
39
41
|
end
|
40
42
|
|
41
|
-
def source(
|
42
|
-
|
43
|
-
|
44
|
-
instance_eval(IO.read(file))
|
45
|
-
end
|
43
|
+
def source(file)
|
44
|
+
return unless File.exist?(file)
|
45
|
+
instance_eval(IO.read(file))
|
46
46
|
end
|
47
47
|
|
48
48
|
def get(name)
|
@@ -53,8 +53,17 @@ module Xlogin
|
|
53
53
|
@database[opts[:name]] = opts
|
54
54
|
end
|
55
55
|
|
56
|
-
def list
|
57
|
-
@database.
|
56
|
+
def list(name = nil)
|
57
|
+
keys = @database.keys
|
58
|
+
keys = keys.select { |key| key =~ /^#{name}(:|$)/ } unless name.nil?
|
59
|
+
@database.values_at(*keys)
|
60
|
+
end
|
61
|
+
|
62
|
+
def group(group_name)
|
63
|
+
current_group = @group
|
64
|
+
@group = [current_group, group_name].compact.join(':')
|
65
|
+
yield
|
66
|
+
@group = current_group
|
58
67
|
end
|
59
68
|
|
60
69
|
def build(args)
|
@@ -76,11 +85,11 @@ module Xlogin
|
|
76
85
|
build(hostinfo.merge(args))
|
77
86
|
end
|
78
87
|
|
79
|
-
def method_missing(
|
88
|
+
def method_missing(method_name, *args, &block)
|
80
89
|
super unless caller_locations.first.label =~ /source/ and args.size >= 2
|
81
90
|
|
82
|
-
type =
|
83
|
-
name = args.shift
|
91
|
+
type = method_name.to_s.downcase
|
92
|
+
name = [@group, args.shift].compact.join(':')
|
84
93
|
uri = args.shift
|
85
94
|
opts = args.shift || {}
|
86
95
|
set(type: type, name: name, uri: uri, **opts)
|
data/lib/xlogin/rake_task.rb
CHANGED
@@ -56,7 +56,7 @@ module Xlogin
|
|
56
56
|
attr_accessor :silent
|
57
57
|
attr_accessor :lockfile
|
58
58
|
attr_accessor :logfile
|
59
|
-
attr_accessor :
|
59
|
+
attr_accessor :assumeyes
|
60
60
|
attr_accessor :uncomment
|
61
61
|
|
62
62
|
def initialize(name)
|
@@ -69,7 +69,7 @@ module Xlogin
|
|
69
69
|
@silent = Rake.application.options.silent
|
70
70
|
@lockfile = nil
|
71
71
|
@logfile = nil
|
72
|
-
@
|
72
|
+
@assumeyes = false
|
73
73
|
@uncomment = false
|
74
74
|
|
75
75
|
yield(self) if block_given?
|
@@ -125,7 +125,7 @@ module Xlogin
|
|
125
125
|
end
|
126
126
|
|
127
127
|
@xlogin_opts[:log] = loggers unless loggers.empty?
|
128
|
-
@xlogin_opts[:
|
128
|
+
@xlogin_opts[:assumeyes] ||= assumeyes
|
129
129
|
|
130
130
|
begin
|
131
131
|
@session = Xlogin.factory.build(@xlogin_opts)
|
data/lib/xlogin/templates/ios.rb
CHANGED
@@ -2,7 +2,7 @@ Xlogin.configure :ios do |os|
|
|
2
2
|
os.timeout(300)
|
3
3
|
os.prompt(/[>$#]/)
|
4
4
|
os.prompt(/yes \/ no: /) do
|
5
|
-
puts opts[:
|
5
|
+
puts opts[:assumeyes] ? 'y' : 'n'
|
6
6
|
end
|
7
7
|
|
8
8
|
os.bind(:login) do |password|
|
@@ -15,22 +15,4 @@ Xlogin.configure :ios do |os|
|
|
15
15
|
waitfor(/Password: /) && puts(password)
|
16
16
|
waitfor
|
17
17
|
end
|
18
|
-
|
19
|
-
os.bind(:config) do
|
20
|
-
begin
|
21
|
-
cmd('terminal length 0')
|
22
|
-
resp = cmd('show run')
|
23
|
-
resp.lines[4..-2].join.to_s
|
24
|
-
ensure
|
25
|
-
cmd('exit')
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
os.bind(:save) do
|
30
|
-
begin
|
31
|
-
cmd('write memory')
|
32
|
-
ensure
|
33
|
-
cmd('exit')
|
34
|
-
end
|
35
|
-
end
|
36
18
|
end
|
@@ -8,15 +8,4 @@ Xlogin.configure :iosxr do |os|
|
|
8
8
|
waitfor(/Password: /) && puts(password)
|
9
9
|
waitfor
|
10
10
|
end
|
11
|
-
|
12
|
-
os.bind(:config) do
|
13
|
-
begin
|
14
|
-
cmd('terminal width 0')
|
15
|
-
cmd('terminal length 0')
|
16
|
-
resp = cmd('show run')
|
17
|
-
resp.lines[3..-3].join.to_s
|
18
|
-
ensure
|
19
|
-
cmd('exit')
|
20
|
-
end
|
21
|
-
end
|
22
11
|
end
|
@@ -2,7 +2,7 @@ Xlogin.configure :sros do |os|
|
|
2
2
|
os.timeout(300)
|
3
3
|
os.prompt(/[>$#] /)
|
4
4
|
os.prompt(/y\/n:/) do
|
5
|
-
puts opts[:
|
5
|
+
puts opts[:assumeyes] ? 'y' : 'n'
|
6
6
|
end
|
7
7
|
|
8
8
|
os.bind(:login) do |*args|
|
@@ -17,14 +17,4 @@ Xlogin.configure :sros do |os|
|
|
17
17
|
waitfor(/Password:\s?/) && puts(password)
|
18
18
|
waitfor
|
19
19
|
end
|
20
|
-
|
21
|
-
os.bind(:config) do
|
22
|
-
begin
|
23
|
-
cmd('environment no more')
|
24
|
-
resp = cmd('admin display-config')
|
25
|
-
resp.lines[2..-2].join.to_s
|
26
|
-
ensure
|
27
|
-
cmd('logout')
|
28
|
-
end
|
29
|
-
end
|
30
20
|
end
|
@@ -7,20 +7,4 @@ Xlogin.configure :vyos do |os|
|
|
7
7
|
waitfor(/Password:\s/) && puts(password)
|
8
8
|
waitfor
|
9
9
|
end
|
10
|
-
|
11
|
-
os.bind(:config) do
|
12
|
-
begin
|
13
|
-
cmd('show configuration | no-more')
|
14
|
-
ensure
|
15
|
-
cmd('exit')
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
os.bind(:save) do
|
20
|
-
begin
|
21
|
-
cmd('save')
|
22
|
-
ensure
|
23
|
-
cmd('exit')
|
24
|
-
end
|
25
|
-
end
|
26
10
|
end
|
data/lib/xlogin/version.rb
CHANGED
data/xlogin.gemspec
CHANGED
@@ -30,10 +30,12 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
|
+
spec.add_dependency "io-console"
|
33
34
|
spec.add_dependency "net-telnet"
|
34
35
|
spec.add_dependency "net-ssh"
|
35
36
|
spec.add_dependency "net-ssh-telnet"
|
36
37
|
spec.add_dependency "net-ssh-gateway"
|
38
|
+
spec.add_dependency "parallel"
|
37
39
|
|
38
40
|
spec.add_development_dependency "bundler", "~> 1.13"
|
39
41
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xlogin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- haccht
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: io-console
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: net-telnet
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +80,20 @@ dependencies:
|
|
66
80
|
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: parallel
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: bundler
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,7 +136,6 @@ files:
|
|
108
136
|
- LICENSE.txt
|
109
137
|
- README.md
|
110
138
|
- Rakefile
|
111
|
-
- bin/cmd_exec
|
112
139
|
- bin/console
|
113
140
|
- bin/setup
|
114
141
|
- bin/xlogin
|
data/bin/cmd_exec
DELETED