oxidized-script 0.0.4 → 0.0.6

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: 0c16bc591c5474eb15e40fef64bcdbc48fd7091d
4
- data.tar.gz: cd0e0ed8d118e8c1f913435b40647b2eb503d33e
3
+ metadata.gz: 1013bd79d71871bee9cd63c675ddef578746c19e
4
+ data.tar.gz: 6b3f703fcbe41564e85e1aa7f9853446a554b0c5
5
5
  SHA512:
6
- metadata.gz: a062907057e209090eff6dc322344586138bbe07e5bb9f53b22f6397f9fd0c2102049cea90ca060e06f9dc8be83d3a380cd9f7a2f80ee844f6b66c5f066fbede
7
- data.tar.gz: 983fd99551877eb0522005e35fad53721cae4f759a9f20023e75d271a691cef6ac1db89257224489819e4045deeca8306b96a17f72b65a36865b89ccbbbe5308
6
+ metadata.gz: bde082a7305a4d44be46aa36097456da566282eaa6aeaa74b57d51be825f823be5d74f288eedba3626038e8514c23733853ae4b5b50f949febfef8f4ca4c3dbf
7
+ data.tar.gz: 01de2421170611dc2cd285f46879ef244a7949044eb1aaa4c9dc09f018bd9e32ed6f3f048826b9d204d7d5ee627ccf62b5f872ba88da66f193f3899593be5c5c
data/Rakefile CHANGED
@@ -1,10 +1,9 @@
1
1
  begin
2
2
  require 'rake/testtask'
3
3
  require 'bundler'
4
- Bundler.setup
4
+ # Bundler.setup
5
5
  rescue LoadError
6
6
  warn 'bunler missing'
7
- exit 42
8
7
  end
9
8
 
10
9
  gemspec = eval(File.read(Dir['*.gemspec'].first))
@@ -33,7 +32,7 @@ end
33
32
 
34
33
  desc 'Install gem'
35
34
  task :install => :build do
36
- system "sudo -E sh -c \'umask 022; gem install gems/#{file}\'"
35
+ system "sudo -Es sh -c \'umask 022; gem install gems/#{file}\'"
37
36
  end
38
37
 
39
38
  desc 'Remove gems'
@@ -3,6 +3,7 @@ module Oxidized
3
3
  require 'slop'
4
4
  class Script
5
5
  class CLI
6
+ attr_accessor :cmd_class
6
7
  class CLIError < ScriptError; end
7
8
  class NothingToDo < ScriptError; end
8
9
 
@@ -20,11 +21,16 @@ module Oxidized
20
21
  def initialize
21
22
  @args, @opts = opts_parse load_dynamic
22
23
  CFG.debug = true if @opts[:debug]
23
- @host = @args.shift
24
- @cmd = @args.shift if @args
25
- @oxs = nil
26
- raise NothingToDo, 'no host given' if not @host
27
- raise NothingToDo, 'nothing to do, give command or -x' if not @cmd and not @opts[:commands]
24
+ if @cmd_class
25
+ @cmd_class.run :args=>@args, :opts=>@opts, :host=>@host, :cmd=>@cmd
26
+ exit 0
27
+ else
28
+ @host = @args.shift
29
+ @cmd = @args.shift if @args
30
+ @oxs = nil
31
+ raise NothingToDo, 'no host given' if not @host
32
+ raise NothingToDo, 'nothing to do, give command or -x' if not @cmd and not @opts[:commands]
33
+ end
28
34
  end
29
35
 
30
36
  def opts_parse cmds
@@ -37,11 +43,17 @@ module Oxidized
37
43
  slop.on 't=', '--timeout', 'timeout value to use'
38
44
  slop.on 'e=', '--enable', 'enable password to use'
39
45
  slop.on 'c=', '--community', 'snmp community to use for discovery'
46
+ slop.on '--protocols=','protocols to use, default "ssh, telnet"'
40
47
  slop.on 'v', '--verbose', 'verbose output, e.g. show commands sent'
41
48
  slop.on 'd', '--debug', 'turn on debugging'
49
+ slop.on :terse, 'display clean output'
42
50
  cmds.each do |cmd|
43
- slop.on cmd[:name], cmd[:description] do
44
- cmd[:class].run(:args=>@args, :opts=>@opts, :host=>@host, :cmd=>@cmd)
51
+ if cmd[:class].respond_to? :cmdline
52
+ cmd[:class].cmdline slop, self
53
+ else
54
+ slop.on cmd[:name], cmd[:description] do
55
+ @cmd_class = cmd[:class]
56
+ end
45
57
  end
46
58
  end
47
59
  slop.parse
@@ -51,7 +63,7 @@ module Oxidized
51
63
  def connect
52
64
  opts = {}
53
65
  opts[:host] = @host
54
- [:model, :username, :password, :timeout, :enable, :verbose, :community].each do |key|
66
+ [:model, :username, :password, :timeout, :enable, :verbose, :community, :protocols].each do |key|
55
67
  opts[key] = @opts[key] if @opts[key]
56
68
  end
57
69
  @oxs = Script.new opts
@@ -75,6 +87,7 @@ module Oxidized
75
87
  files = Dir.glob files
76
88
  files.each { |file| require_relative file }
77
89
  Script::Command.constants.each do |cmd|
90
+ next if cmd == :Base
78
91
  cmd = Script::Command.const_get cmd
79
92
  name = cmd.const_get :Name
80
93
  desc = cmd.const_get :Description
@@ -0,0 +1,8 @@
1
+ module Oxidized
2
+ class Script
3
+ module Command
4
+ class Base
5
+ end
6
+ end
7
+ end
8
+ end
@@ -1,13 +1,12 @@
1
1
  module Oxidized
2
2
  class Script
3
3
  module Command
4
- class ListModels
4
+ class ListModels < Base
5
5
  Name = 'list-models'
6
6
  Description = 'list supported models'
7
7
 
8
8
  def self.run opts={}
9
9
  puts new(opts).models
10
- exit
11
10
  end
12
11
 
13
12
  def models
@@ -1,13 +1,26 @@
1
1
  module Oxidized
2
2
  class Script
3
3
  module Command
4
- class ListNodes
4
+ class ListNodes < Base
5
5
  Name = 'list-nodes'
6
6
  Description = 'list nodes in oxidized source'
7
7
 
8
+ # this is not needed this this command, just shown how todo more
9
+ # complex commands, this could use slop sub-commands etc. As long as it
10
+ # sets cli.cmd_class when you want to run it, it gets ran after parsing
11
+ # commandline
12
+ def self.cmdline slop, cli
13
+ slop.on "--#{Name}", Description do
14
+ cli.cmd_class = self
15
+ end
16
+ end
17
+
8
18
  def self.run opts={}
9
- puts new(opts).nodes
10
- exit
19
+ if opts[:opts][:terse] # find if 'terse' global option is set
20
+ puts new(opts).nodes_terse
21
+ else
22
+ puts new(opts).nodes
23
+ end
11
24
  end
12
25
 
13
26
  def nodes
@@ -25,6 +38,15 @@ module Oxidized
25
38
  out
26
39
  end
27
40
 
41
+ def nodes_terse
42
+ out = ''
43
+ i = 0
44
+ Nodes.new.each do |node|
45
+ out += "#{i += 1} - #{node.name}\n"
46
+ end
47
+ out
48
+ end
49
+
28
50
  private
29
51
 
30
52
  def initialize opts={}
@@ -2,11 +2,15 @@
2
2
 
3
3
  module Oxidized
4
4
  require 'oxidized'
5
+ require_relative 'command'
5
6
  class Script
6
7
  class ScriptError < OxidizedError; end
7
- class NoConnection < ScriptError; end
8
8
  class NoNode < ScriptError; end
9
9
  class InvalidOption < ScriptError; end
10
+ class NoConnection < ScriptError
11
+ attr_accessor :node_error
12
+ end
13
+
10
14
 
11
15
  # @param [String] command command to be sent
12
16
  # @return [String] output for command
@@ -34,6 +38,7 @@ module Oxidized
34
38
  # @option opts [String] :passsword password for login
35
39
  # @option opts [String] :enable enable password to use
36
40
  # @option opts [String] :community community to use for discovery
41
+ # @option opts [String] :protocols protocols to use to connect, default "ssh ,telnet"
37
42
  # @option opts [boolean] :verbose extra output, e.g. show command given in output
38
43
  # @yieldreturn [self] if called in block, returns self and disconnnects session after exiting block
39
44
  # @return [void]
@@ -46,6 +51,7 @@ module Oxidized
46
51
  enable = opts.delete :enable
47
52
  community = opts.delete :community
48
53
  @verbose = opts.delete :verbose
54
+ CFG.input.default = opts.delete :protocols if opts[:protocols]
49
55
  raise InvalidOption, "#{opts} not recognized" unless opts.empty?
50
56
  Oxidized.mgr = Manager.new
51
57
  @node = if model
@@ -78,16 +84,20 @@ module Oxidized
78
84
  end
79
85
 
80
86
  def connect
87
+ node_error = {}
81
88
  @node.input.each do |input|
82
89
  begin
83
90
  @node.model.input = input.new
84
91
  @node.model.input.connect @node
85
92
  break
86
- rescue
93
+ rescue => error
94
+ node_error[input] = error
87
95
  end
88
96
  end
89
97
  @input = @node.model.input
90
- raise NoConnection, 'unable to connect' unless @input.connected?
98
+ err = NoConnection.new
99
+ err.node_error = node_error
100
+ raise err, 'unable to connect' unless @input.connected?
91
101
  @input.connect_cli
92
102
  end
93
103
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'oxidized-script'
3
- s.version = '0.0.4'
3
+ s.version = '0.0.6'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = [ 'Saku Ytti' ]
6
6
  s.email = %w( saku@ytti.fi )
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oxidized-script
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saku Ytti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-16 00:00:00.000000000 Z
11
+ date: 2014-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oxidized
@@ -54,6 +54,7 @@ files:
54
54
  - bin/oxs
55
55
  - lib/oxidized/script.rb
56
56
  - lib/oxidized/script/cli.rb
57
+ - lib/oxidized/script/command.rb
57
58
  - lib/oxidized/script/commands/list-models.rb
58
59
  - lib/oxidized/script/commands/list-nodes.rb
59
60
  - lib/oxidized/script/script.rb