expectacle 0.0.2 → 0.0.3
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 +41 -20
- data/exe/run_command +24 -5
- data/lib/expectacle/version.rb +1 -1
- data/vendor/commands/cisco_show_arp.yml +0 -2
- data/vendor/commands/ssg_get_arp.yml +0 -2
- data/vendor/hosts/fw.yml +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2548d2071903bbd5b0f1c0ed3f0e46a928feb9d6
|
4
|
+
data.tar.gz: 0fd63708608402d9de553df1b36403dc9499cbb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00791cb556c54d6b6d27081f1a9887ccc80469e1d4bcfa7a24d0df55de2d29e51af56a1956e512849470ab6c32f97b174922ad049acd9156ada255dae682bd95
|
7
|
+
data.tar.gz: 4c9679ba35e87619793823285ebf4c3d11eea1419122c595bbd107062601992ec487eb9581e0e433231d65c5a5fde136c502b06ff1eaca37244a07e72200310e
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Expectacle
|
2
|
+
[](https://badge.fury.io/rb/expectacle)
|
2
3
|
|
3
4
|
Expectacle ("expect + spectacle") is a small wrapper of `pty`/`expect`.
|
4
5
|
It can send commands (command-list) to hosts (including network devices etc)
|
@@ -26,32 +27,33 @@ Or install it yourself as:
|
|
26
27
|
|
27
28
|
## Usage
|
28
29
|
|
29
|
-
###
|
30
|
-
See
|
30
|
+
### Send commands to hosts
|
31
|
+
See [exe/run_command](./exe/run_command) and [vendor directory](./vendor).
|
31
32
|
|
32
|
-
`run_command` can send commands to hosts.
|
33
|
+
`run_command` can send commands to hosts with `-r`/`--run` option.
|
33
34
|
|
34
|
-
$ bundle exec
|
35
|
+
$ bundle exec run_command -r -h l2switch.yml -c cisco_show_arp.yml
|
35
36
|
|
36
|
-
-
|
37
|
+
- See details of command line options with `--help` option.
|
38
|
+
- [l2switch.yml](./vendor/hosts/l2switch.yml) is host-list file.
|
37
39
|
It is a data definitions for each hosts to send commands.
|
38
40
|
- At username and password (login/enable) parameter,
|
39
41
|
you can write environment variables with ERB manner to avoid write raw login information.
|
40
|
-
-
|
42
|
+
- [exe/readne](./exe/readne) is a small bash script to set environment variable in your shell.
|
41
43
|
|
42
44
|
```
|
43
|
-
$ export L2SW_USER=`./
|
45
|
+
$ export L2SW_USER=`./exe/readne`
|
44
46
|
Input: (type username)
|
45
|
-
$ export L2SW_PASS=`./
|
47
|
+
$ export L2SW_PASS=`./exe/readne`
|
46
48
|
Input: (type password)
|
47
49
|
```
|
48
50
|
|
49
51
|
- `Expectacle::Thrower` read prompt-file by "type" parameter in host-list file.
|
50
52
|
- In prompt-file, prompt regexps that used for interactive operation to host
|
51
53
|
are defined. (These regexp are common information for some host-groups. (vendor, OS, ...))
|
52
|
-
- Prompt-file is searched by filename: `#{type}_prompt.yml
|
54
|
+
- Prompt-file is searched by filename: `#{type}_prompt.yml` from [prompts directory](./vendor/prompts).
|
53
55
|
`type` parameter defined in host-list file.
|
54
|
-
-
|
56
|
+
- [cisco_show_arp.yml](./vendor/commands/cisco_show_arp.yml) is command-list file.
|
55
57
|
- it is a list of commands.
|
56
58
|
- Each files are written by YAML.
|
57
59
|
|
@@ -95,7 +97,7 @@ stereocat@tftpserver:~/expectacle$ bundle exec run_command -p -h l2switch.yml -c
|
|
95
97
|
---
|
96
98
|
(snip)
|
97
99
|
```
|
98
|
-
**Notice** : Passwords were masked above example, but actually, raw password
|
100
|
+
**Notice** : Passwords were masked above example, but actually, raw password strings are printed out.
|
99
101
|
|
100
102
|
### Use Syslog
|
101
103
|
|
@@ -104,6 +106,19 @@ So, log messages are printed out to syslog on localhost.
|
|
104
106
|
|
105
107
|
$ bundle exec run_command -rs -h l2switch.yml -c cisco_show_arp.yml
|
106
108
|
|
109
|
+
### Quiet mode
|
110
|
+
|
111
|
+
With `-q`/`--quiet`, [run_command](./exe/run_command) stop printing out results
|
112
|
+
received from a host to standard out. For example:
|
113
|
+
|
114
|
+
$ bundle exec run_command -rq -h l2switch.yml -c cisco_show_arp.yml
|
115
|
+
|
116
|
+
the command prints only log message (without host output) to standard out.
|
117
|
+
If you use options syslog(`-s`) and quiet(`-q`),
|
118
|
+
there is nothing to be appeared in terminal (standard out).
|
119
|
+
|
120
|
+
$ bundle exec run_command -rqs -h l2switch.yml -c cisco_show_arp.yml
|
121
|
+
|
107
122
|
## Parameter Definitions
|
108
123
|
|
109
124
|
### Expectacle::Thrower
|
@@ -139,7 +154,7 @@ Host-list file is a list of host-parameters.
|
|
139
154
|
It can use ERB to set values from environment variable in `:username`, `:password` and `:enable`.
|
140
155
|
|
141
156
|
You can add other parameter(s) to refer in command-list files.
|
142
|
-
See also:
|
157
|
+
See also: [Command list](#command-list-with-erb) section.
|
143
158
|
|
144
159
|
### Prompt parameter
|
145
160
|
Prompt file is a table of prompt regexp of host group(type).
|
@@ -159,30 +174,31 @@ Command-list is a simple list of command-string.
|
|
159
174
|
A command-string can contain host-parameter reference by ERB.
|
160
175
|
|
161
176
|
For example, if you want to save configuration of a Cisco device to tftp server:
|
162
|
-
- Add a parameter to tftp server info (IP address) in host-list file
|
177
|
+
- Add a parameter to tftp server info (IP address) in [host-list file](vendor/hosts/l2switch.yml).
|
163
178
|
```YAML
|
164
179
|
- :hostname : 'l2sw1'
|
165
180
|
:type : 'c3750g'
|
166
|
-
:ipaddr : '192.168.
|
181
|
+
:ipaddr : '192.168.20.150'
|
167
182
|
:protocol : 'ssh'
|
168
183
|
:username : "<%= ENV['L2SW_USER'] %>"
|
169
184
|
:password : "<%= ENV['L2SW_PASS'] %>"
|
170
185
|
:enable : "<%= ENV['L2SW_PASS'] %>"
|
171
|
-
:tftp_server: '192.168.
|
186
|
+
:tftp_server: '192.168.20.170'
|
172
187
|
- :hostname : 'l2sw2'
|
173
188
|
:type : 'c3750g'
|
174
|
-
:ipaddr : '192.168.
|
189
|
+
:ipaddr : '192.168.20.151'
|
175
190
|
:protocol : 'ssh'
|
176
191
|
:username : "<%= ENV['L2SW_USER'] %>"
|
177
192
|
:password : "<%= ENV['L2SW_PASS'] %>"
|
178
193
|
:enable : "<%= ENV['L2SW_PASS'] %>"
|
179
|
-
:tftp_server: '192.168.
|
194
|
+
:tftp_server: '192.168.20.170'
|
180
195
|
```
|
181
196
|
|
182
|
-
- Write command-list file using ERB.
|
197
|
+
- Write [command-list file](vendor/commands/cisco_save_config_tftp.yml) using ERB.
|
183
198
|
When send a command to host, ERB string was evaluated in `Expectacle::Thrower` bindings.
|
184
|
-
Then, it can refer host-parameter as `@host_param` hash.
|
185
|
-
-
|
199
|
+
Then, it can refer host-parameter as `@host_param` hash.
|
200
|
+
- When exec below command-list, host configuration will be saved a file as `l2sw1.confg` on tftp server.
|
201
|
+
- See also: [parameter preview](#parameter-expansion-and-preview) section.
|
186
202
|
|
187
203
|
```YAML
|
188
204
|
- "copy run start"
|
@@ -198,6 +214,11 @@ Now, Expectacle sends fixed command for sub-prompt.
|
|
198
214
|
- Yex/No (`:yn`) : always sends "yes"
|
199
215
|
- Sub prompt (`:sub1` and `:sub2`) : always sends Empty string (RETURN)
|
200
216
|
|
217
|
+
### Error handling
|
218
|
+
Expectacle does not have error message handling feature.
|
219
|
+
If a host returns a error message when expectacle sent a command,
|
220
|
+
then expectacle ignores it and continue sending rest commands (until command list is empty).
|
221
|
+
|
201
222
|
## Contributing
|
202
223
|
|
203
224
|
Bug reports and pull requests are welcome on GitHub at <https://github.com/stereocat/expectacle>.
|
data/exe/run_command
CHANGED
@@ -8,13 +8,13 @@ require 'syslog/logger'
|
|
8
8
|
|
9
9
|
option = {}
|
10
10
|
opt = OptionParser.new
|
11
|
-
opt.on('-h', '--hosts=FILE', '
|
11
|
+
opt.on('-h', '--hosts=FILE', 'Set host-list file') do |value|
|
12
12
|
option[:hosts] = value
|
13
13
|
end
|
14
|
-
opt.on('-c', '--commands=FILE', '
|
14
|
+
opt.on('-c', '--commands=FILE', 'Set command-list file') do |value|
|
15
15
|
option[:commands] = value
|
16
16
|
end
|
17
|
-
opt.on('-b', '--base-dir=DIR', '
|
17
|
+
opt.on('-b', '--base-dir=DIR', 'Set base directory path') do |value|
|
18
18
|
option[:base_dir] = value
|
19
19
|
end
|
20
20
|
opt.on('-p', '--preview', 'Preview parameter') do |value|
|
@@ -23,24 +23,43 @@ end
|
|
23
23
|
opt.on('-r', '--run', 'Run(exec) commands to each hosts') do |value|
|
24
24
|
option[:run] = value
|
25
25
|
end
|
26
|
-
opt.on('-s', '--syslog', '
|
26
|
+
opt.on('-s', '--syslog', 'Set syslog logger (localhost syslog)') do |value|
|
27
27
|
option[:syslog] = value
|
28
28
|
end
|
29
|
+
opt.on('-t', '--timeout=SEC', 'Set seconds to timeout') do |value|
|
30
|
+
option[:timeout] = value
|
31
|
+
end
|
32
|
+
opt.on('-q', '--quiet', 'Stop printing results to standard out') do |value|
|
33
|
+
option[:quiet] = value
|
34
|
+
end
|
35
|
+
opt.on('-d', '--debug', 'Set logging level to DEBUG') do |value|
|
36
|
+
option[:debug] = value
|
37
|
+
end
|
29
38
|
opt.parse!(ARGV)
|
30
39
|
|
40
|
+
# basic setting
|
41
|
+
verbose = option.key?(:quiet) ? false : true
|
42
|
+
timeout = option.key?(:timeout) ? option[:timeout] : 60
|
31
43
|
base_dir = if option.key?(:base_dir)
|
32
44
|
option[:base_dir]
|
33
45
|
else
|
34
46
|
file_dir = File.dirname(File.expand_path(__FILE__))
|
35
47
|
File.expand_path('../vendor', file_dir)
|
36
48
|
end
|
37
|
-
thrower = Expectacle::Thrower.new(base_dir: base_dir)
|
38
49
|
|
50
|
+
# create thrower
|
51
|
+
thrower = Expectacle::Thrower.new(base_dir: base_dir,
|
52
|
+
verbose: verbose,
|
53
|
+
timeout: timeout)
|
54
|
+
|
55
|
+
# setup logger options
|
39
56
|
if option[:syslog]
|
40
57
|
thrower.logger = Syslog::Logger.new 'Expectacle'
|
41
58
|
thrower.setup_logger
|
42
59
|
end
|
60
|
+
thrower.logger.level = Logger::DEBUG if option.key?(:debug) && option[:debug]
|
43
61
|
|
62
|
+
# run or preview
|
44
63
|
hosts = YAML.load_file(File.join(thrower.hosts_dir, option[:hosts]))
|
45
64
|
commands = YAML.load_file(File.join(thrower.commands_dir, option[:commands]))
|
46
65
|
if option[:preview]
|
data/lib/expectacle/version.rb
CHANGED
data/vendor/hosts/fw.yml
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: expectacle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- stereocat
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|