expectacle 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2548d2071903bbd5b0f1c0ed3f0e46a928feb9d6
4
- data.tar.gz: 0fd63708608402d9de553df1b36403dc9499cbb2
3
+ metadata.gz: '029ac71fb1381c439677ac4c36009c7056be529b'
4
+ data.tar.gz: 23298b873bd9b727806fe09e3dcd8b20d598b5e8
5
5
  SHA512:
6
- metadata.gz: 00791cb556c54d6b6d27081f1a9887ccc80469e1d4bcfa7a24d0df55de2d29e51af56a1956e512849470ab6c32f97b174922ad049acd9156ada255dae682bd95
7
- data.tar.gz: 4c9679ba35e87619793823285ebf4c3d11eea1419122c595bbd107062601992ec487eb9581e0e433231d65c5a5fde136c502b06ff1eaca37244a07e72200310e
6
+ metadata.gz: 11536ed5527986defcccf7b3017f4683ecde6a04c09271676403788a37226090c295d07576f3ed656f7e39a3965575b270dddf3d0a5b871ccd50e54120b70578
7
+ data.tar.gz: 4202028b4045286aa6a97521d8939adf8eb6c470178af86fc6b5b38908b8517bff1a3286846eb9fbb60b7f5bd19cfb426c88c5a598c07a204412c4d474acb01f
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
+ *~
2
+ \#*
1
3
  /.bundle/
2
4
  /.yardoc
3
5
  /Gemfile.lock
data/README.md CHANGED
@@ -99,13 +99,19 @@ stereocat@tftpserver:~/expectacle$ bundle exec run_command -p -h l2switch.yml -c
99
99
  ```
100
100
  **Notice** : Passwords were masked above example, but actually, raw password strings are printed out.
101
101
 
102
- ### Use Syslog
102
+ ### Change place of log message
103
+
104
+ With `-l`/`--logfile`, [run_command](./exe/run_command) changes logging IO to file instead of standard-out (default).
105
+
106
+ $ bundle exec run_command -r -l foo.log -h l2switch.yml -c cisco_show_arp.yml
103
107
 
104
108
  With `-s`/`--syslog`, [run_command](./exe/run_command) changes logging instance to `syslog/logger`.
105
109
  So, log messages are printed out to syslog on localhost.
106
110
 
107
111
  $ bundle exec run_command -rs -h l2switch.yml -c cisco_show_arp.yml
108
112
 
113
+ **Notice** : When specified `--logfile` and `--syslog` at the same time, `--syslog` is used to logging.
114
+
109
115
  ### Quiet mode
110
116
 
111
117
  With `-q`/`--quiet`, [run_command](./exe/run_command) stop printing out results
@@ -205,6 +211,23 @@ For example, if you want to save configuration of a Cisco device to tftp server:
205
211
  - "copy run tftp://<%= @host_param[:tftp_server] %>/<%= @host_param[:hostname] %>.confg"
206
212
  ```
207
213
 
214
+ ## SSH Options
215
+
216
+ When use `ssh` (OpenSSH) command to spawn device, the user can set options for the command via `#{base_dir}/ssh_opts.yml`.
217
+ With options as list in [ssh_opts.yml](./vendor/ssh_opts.yml),
218
+ ```
219
+ - '-o StrictHostKeyChecking=no'
220
+ - '-o KexAlgorithms=+diffie-hellman-group1-sha1'
221
+ - '-o Ciphers=+aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc'
222
+ ```
223
+ it works same as `~/.ssh/config` below.
224
+ ```
225
+ Host *
226
+ StrictHostKeyChecking no
227
+ KexAlgorithms +diffie-hellman-group1-sha1
228
+ Ciphers +aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc
229
+ ```
230
+
208
231
  ## TODO
209
232
 
210
233
  ### Sub prompt operation (interactive command)
data/exe/run_command CHANGED
@@ -4,7 +4,6 @@
4
4
  require 'expectacle'
5
5
  require 'optparse'
6
6
  require 'yaml'
7
- require 'syslog/logger'
8
7
 
9
8
  option = {}
10
9
  opt = OptionParser.new
@@ -26,6 +25,9 @@ end
26
25
  opt.on('-s', '--syslog', 'Set syslog logger (localhost syslog)') do |value|
27
26
  option[:syslog] = value
28
27
  end
28
+ opt.on('-l', '--logfile=FILE', 'Set file to save log message') do |value|
29
+ option[:logfile] = value
30
+ end
29
31
  opt.on('-t', '--timeout=SEC', 'Set seconds to timeout') do |value|
30
32
  option[:timeout] = value
31
33
  end
@@ -40,6 +42,13 @@ opt.parse!(ARGV)
40
42
  # basic setting
41
43
  verbose = option.key?(:quiet) ? false : true
42
44
  timeout = option.key?(:timeout) ? option[:timeout] : 60
45
+ logger = if option.key?(:syslog)
46
+ :syslog
47
+ elsif option.key?(:logfile)
48
+ option[:logfile]
49
+ else
50
+ $stdout
51
+ end
43
52
  base_dir = if option.key?(:base_dir)
44
53
  option[:base_dir]
45
54
  else
@@ -50,13 +59,9 @@ base_dir = if option.key?(:base_dir)
50
59
  # create thrower
51
60
  thrower = Expectacle::Thrower.new(base_dir: base_dir,
52
61
  verbose: verbose,
53
- timeout: timeout)
54
-
55
- # setup logger options
56
- if option[:syslog]
57
- thrower.logger = Syslog::Logger.new 'Expectacle'
58
- thrower.setup_logger
59
- end
62
+ timeout: timeout,
63
+ logger: logger)
64
+ # setup logging level
60
65
  thrower.logger.level = Logger::DEBUG if option.key?(:debug) && option[:debug]
61
66
 
62
67
  # run or preview
@@ -5,6 +5,7 @@ require 'expect'
5
5
  require 'yaml'
6
6
  require 'erb'
7
7
  require 'logger'
8
+ require 'syslog/logger'
8
9
 
9
10
  module Expectacle
10
11
  # Basic state setup/management
@@ -20,7 +21,8 @@ module Expectacle
20
21
  # (default: `true`)
21
22
  # @param base_dir [String] Base directory to find files.
22
23
  # (default: `Dir.pwd`)
23
- # @param logger [IO] IO Object to logging. (default `$stdout`)
24
+ # @param logger [IO,String,Symbol] IO Object (default `$stdout`),
25
+ # File name, or :syslog to logging.
24
26
  # @return [Expectacle::ThrowerBase]
25
27
  def initialize(timeout: 60, verbose: true,
26
28
  base_dir: Dir.pwd, logger: $stdout)
@@ -35,8 +37,7 @@ module Expectacle
35
37
  # base dir
36
38
  @base_dir = File.expand_path(base_dir)
37
39
  # logger
38
- @logger = Logger.new(logger)
39
- setup_default_logger
40
+ setup_default_logger(logger)
40
41
  end
41
42
 
42
43
  # Path to prompt file directory.
@@ -57,20 +58,26 @@ module Expectacle
57
58
  File.join @base_dir, 'commands'
58
59
  end
59
60
 
60
- # Setup common settings of logger instance.
61
- def setup_logger
62
- @logger.level = Logger::INFO
63
- @logger.formatter = proc do |severity, datetime, progname, msg|
64
- "#{datetime} #{progname} [#{severity}] #{msg}\n"
65
- end
66
- end
67
-
68
61
  private
69
62
 
70
- def setup_default_logger
71
- @logger.progname = 'Expectacle'
72
- @logger.datetime_format = '%Y-%m-%d %H:%M:%D %Z'
73
- setup_logger
63
+ def default_io_logger(logger_io, progname)
64
+ logger = Logger.new(logger_io)
65
+ logger.progname = progname
66
+ logger.datetime_format = '%Y-%m-%d %H:%M:%D %Z'
67
+ logger
68
+ end
69
+
70
+ def setup_default_logger(logger)
71
+ progname = 'Expectacle'
72
+ @logger = if logger == :syslog
73
+ Syslog::Logger.new(progname)
74
+ else
75
+ default_io_logger(logger, progname)
76
+ end
77
+ @logger.level = Logger::INFO
78
+ @logger.formatter = proc do |severity, datetime, pname, msg|
79
+ "#{datetime} #{pname} [#{severity}] #{msg}\n"
80
+ end
74
81
  end
75
82
 
76
83
  def ready_to_open_host_session
@@ -108,17 +115,14 @@ module Expectacle
108
115
  end
109
116
 
110
117
  def ssh_command
111
- ['ssh',
112
- '-o StrictHostKeyChecking=no',
113
- '-o KexAlgorithms=+diffie-hellman-group1-sha1', # for old cisco device
114
- "-l #{embed_user_name}",
115
- @host_param[:ipaddr]].join(' ')
118
+ opts = load_ssh_opts_file
119
+ ['ssh', opts, "-l #{embed_user_name}", embed_ipaddr].join(' ')
116
120
  end
117
121
 
118
122
  def make_spawn_command
119
123
  case @host_param[:protocol]
120
124
  when /^telnet$/i
121
- ['telnet', @host_param[:ipaddr]].join(' ')
125
+ ['telnet', embed_ipaddr].join(' ')
122
126
  when /^ssh$/i
123
127
  ssh_command
124
128
  else
@@ -139,6 +143,11 @@ module Expectacle
139
143
  @prompt = load_yaml_file('prompt file', prompt_file)
140
144
  end
141
145
 
146
+ def load_ssh_opts_file
147
+ ssh_opts_file = "#{@base_dir}/ssh_opts.yml"
148
+ @ssh_opts = load_yaml_file('ssh opts file', ssh_opts_file)
149
+ end
150
+
142
151
  def expect_regexp
143
152
  /
144
153
  ( #{@prompt[:password]} | #{@prompt[:enable_password]}
@@ -184,5 +193,11 @@ module Expectacle
184
193
  uname_erb = ERB.new(@host_param[:username])
185
194
  uname_erb.result(binding)
186
195
  end
196
+
197
+ def embed_ipaddr
198
+ check_embed_envvar(@host_param[:ipaddr])
199
+ ipaddr_erb = ERB.new(@host_param[:ipaddr])
200
+ ipaddr_erb.result(binding)
201
+ end
187
202
  end
188
203
  end
@@ -1,4 +1,4 @@
1
1
  module Expectacle
2
2
  # Gem version
3
- VERSION = '0.0.3'.freeze
3
+ VERSION = '0.0.4'.freeze
4
4
  end
@@ -0,0 +1,3 @@
1
+ - '-o StrictHostKeyChecking=no'
2
+ - '-o KexAlgorithms=+diffie-hellman-group1-sha1'
3
+ - '-o Ciphers=+aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc'
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.3
4
+ version: 0.0.4
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-03 00:00:00.000000000 Z
11
+ date: 2018-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -61,6 +61,7 @@ files:
61
61
  - vendor/prompts/c3750g_prompt.yml
62
62
  - vendor/prompts/pica8_prompt.yml
63
63
  - vendor/prompts/ssg_prompt.yml
64
+ - vendor/ssh_opts.yml
64
65
  homepage: https://github.com/stereocat/expectacle
65
66
  licenses:
66
67
  - MIT
@@ -81,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
82
  version: '0'
82
83
  requirements: []
83
84
  rubyforge_project:
84
- rubygems_version: 2.5.1
85
+ rubygems_version: 2.5.2.1
85
86
  signing_key:
86
87
  specification_version: 4
87
88
  summary: Simple expect wrapper to send commands to a devices.