xlogin 0.12.4 → 0.12.5
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/README.md +8 -8
- data/lib/xlogin/cli.rb +3 -3
- data/lib/xlogin/rake_task.rb +11 -8
- data/lib/xlogin/session.rb +1 -1
- data/lib/xlogin/version.rb +1 -1
- data/lib/xlogin.rb +4 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81f206f9e13d4c7554c774e78b2f1922c38b2dbca8e159f4874f027a82c82c99
|
4
|
+
data.tar.gz: 03e07c95b87a97dd6865013b829c3da4468ee599d3262430f81a6e230551198f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73af1ca92ea918891c286f1f1a5b9d0e5fbc6acf878cc4d823739350d6af9edfb85ad1da9b9e2bcbe1e3e75f51c907850c81c885c3243087e588cc7f1e38ed1b
|
7
|
+
data.tar.gz: 56835cfe13e9f94a41b3a20681cc6ba883b429276f7d1ec5665a5da040f6be8c1c4c9a342cb46809436d5d4771d1435d924e0726f1177874eda1bfc5b322e5df
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# xlogin
|
2
2
|
|
3
3
|
rancid clogin alternative.
|
4
|
-
xlogin is a tool to login devices and execute series of
|
4
|
+
xlogin is a tool to login devices and execute series of commands with ease.
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
|
@@ -21,8 +21,9 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
-
Write a template
|
25
|
-
|
24
|
+
Write a firmware template that describe how to manage the device, and store it to `~/.xlogin.d/`.
|
25
|
+
Be aware that the name of the template file should match the hosttype of the device in the inventory file.
|
26
|
+
Take vyos as an example, template file `vyos.rb` would be:
|
26
27
|
|
27
28
|
```ruby
|
28
29
|
prompt(/[$#] (?:\e\[K)?\z/n)
|
@@ -34,11 +35,10 @@ login do |username, password|
|
|
34
35
|
end
|
35
36
|
```
|
36
37
|
|
37
|
-
Some other
|
38
|
+
Some other example templates are in [lib/xlogin/templates](https://github.com/haccht/xlogin/tree/master/lib/xlogin/templates).
|
38
39
|
You can just load these built-in templates by adding `require "xlogin/template"` in your script.
|
39
40
|
|
40
|
-
|
41
|
-
In this file, you need to write all information required to login each device.
|
41
|
+
Besides template files, you need to prepare an inventory file `~/.xloginrc` that list all information required to login each devices.
|
42
42
|
|
43
43
|
```
|
44
44
|
#hosttype hostname uri scheme
|
@@ -46,13 +46,13 @@ vyos 'vyos01', 'telnet://vagrant:vagrant@127.0.0.1:2200'
|
|
46
46
|
vyos 'vyos02', 'telnet://vagrant:vagrant@127.0.0.1:2201'
|
47
47
|
```
|
48
48
|
|
49
|
-
Now you can login
|
49
|
+
Now you can login the device in your `.xloginrc` file.
|
50
50
|
|
51
51
|
```sh
|
52
52
|
$ xlogin vyos01
|
53
53
|
```
|
54
54
|
|
55
|
-
And execute multiple operations with just a single command
|
55
|
+
And execute multiple operations with just a single command.
|
56
56
|
|
57
57
|
~~~sh
|
58
58
|
$ xlogin 'vyos*' -e 'show configuration command | no-more; exit' -j 2
|
data/lib/xlogin/cli.rb
CHANGED
@@ -21,8 +21,8 @@ module Xlogin
|
|
21
21
|
def self.getopts(args)
|
22
22
|
config = OpenStruct.new(
|
23
23
|
jobs: 1,
|
24
|
-
auth: false,
|
25
24
|
task: [:tty, nil],
|
25
|
+
assume_yes: false,
|
26
26
|
inventory: DEFAULT_INVENTORY_FILE,
|
27
27
|
template_dir: DEFAULT_TEMPLATE_DIR,
|
28
28
|
)
|
@@ -40,12 +40,12 @@ module Xlogin
|
|
40
40
|
parser.on('-e COMMAND', '--exec', 'Execute commands and quit.') { |v| config.task = [:exec, v] }
|
41
41
|
|
42
42
|
parser.on('-j NUM', '--jobs', Integer, 'The NUM of jobs to execute in parallel(default: 1).') { |v| config.jobs = v }
|
43
|
-
parser.on('-y', '--assume-yes', TrueClass, 'Automatically answer yes to prompts.') { |v| config.auth = v }
|
44
43
|
parser.on('-E', '--enable', TrueClass, 'Try to gain enable priviledge.') { |v| config.enable = v }
|
44
|
+
parser.on('-y', '--assume-yes', TrueClass, 'Automatically answer yes to prompts.') { |v| config.assume_yes = v }
|
45
45
|
|
46
46
|
parser.parse!(args)
|
47
47
|
Xlogin.configure do
|
48
|
-
|
48
|
+
assume_yes(true)
|
49
49
|
source(File.expand_path(config.inventory, ENV['PWD']))
|
50
50
|
template(File.expand_path(config.template_dir, ENV['PWD']))
|
51
51
|
end
|
data/lib/xlogin/rake_task.rb
CHANGED
@@ -85,14 +85,6 @@ module Xlogin
|
|
85
85
|
logger.push buffer if !silent && Rake.application.options.always_multitask
|
86
86
|
|
87
87
|
session = Xlogin.get(name, log: logger, timeout: timeout)
|
88
|
-
def session.msg(text, prefix: "[INFO]", chomp: false, **color)
|
89
|
-
default_color = { color: :green }
|
90
|
-
|
91
|
-
log("\n")
|
92
|
-
log(Time.now.iso8601.colorize(**color) + ' ') if !Rake.application.options.always_multitask
|
93
|
-
log("#{prefix} #{text}".colorize(**default_color.merge(color)))
|
94
|
-
cmd('') unless chomp
|
95
|
-
end
|
96
88
|
|
97
89
|
@runner.call(session)
|
98
90
|
$stdout.print format_log(buffer.string)
|
@@ -117,4 +109,15 @@ module Xlogin
|
|
117
109
|
end
|
118
110
|
|
119
111
|
end
|
112
|
+
|
113
|
+
module SessionModule
|
114
|
+
def msg(text, prefix: "[INFO]", chomp: false, **color)
|
115
|
+
default_color = { color: :green }
|
116
|
+
|
117
|
+
log("\n")
|
118
|
+
log(Time.now.iso8601.colorize(**color) + ' ') if !Rake.application.options.always_multitask
|
119
|
+
log("#{prefix} #{text}".colorize(**default_color.merge(color)))
|
120
|
+
cmd('') unless chomp
|
121
|
+
end
|
122
|
+
end
|
120
123
|
end
|
data/lib/xlogin/session.rb
CHANGED
@@ -62,7 +62,7 @@ module Xlogin
|
|
62
62
|
|
63
63
|
def puts(*args, &block)
|
64
64
|
args = [instance_exec(*args, &@template.interrupt!)].flatten.compact if @template.interrupt!
|
65
|
-
super(
|
65
|
+
args.empty? ? super('', &block) : super(*args, &block)
|
66
66
|
end
|
67
67
|
|
68
68
|
def waitfor(*args, &block)
|
data/lib/xlogin/version.rb
CHANGED
data/lib/xlogin.rb
CHANGED
@@ -8,7 +8,6 @@ module Xlogin
|
|
8
8
|
|
9
9
|
class SessionError < StandardError; end
|
10
10
|
class TemplateError < StandardError; end
|
11
|
-
class AuthorizationError < StandardError; end
|
12
11
|
|
13
12
|
class << self
|
14
13
|
|
@@ -46,8 +45,8 @@ module Xlogin
|
|
46
45
|
instance_eval(&block)
|
47
46
|
end
|
48
47
|
|
49
|
-
def
|
50
|
-
@
|
48
|
+
def assume_yes?
|
49
|
+
@assume_yes == true
|
51
50
|
end
|
52
51
|
|
53
52
|
def generate_templates(dir)
|
@@ -57,8 +56,8 @@ module Xlogin
|
|
57
56
|
end
|
58
57
|
|
59
58
|
private
|
60
|
-
def
|
61
|
-
@
|
59
|
+
def assume_yes(boolean = true, &block)
|
60
|
+
@assume_yes = boolean == true || (block && block.call == true)
|
62
61
|
end
|
63
62
|
|
64
63
|
def source(*sources, &block)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xlogin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- haccht
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-telnet
|