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 +4 -4
- data/Rakefile +2 -3
- data/lib/oxidized/script/cli.rb +21 -8
- data/lib/oxidized/script/command.rb +8 -0
- data/lib/oxidized/script/commands/list-models.rb +1 -2
- data/lib/oxidized/script/commands/list-nodes.rb +25 -3
- data/lib/oxidized/script/script.rb +13 -3
- data/oxidized-script.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1013bd79d71871bee9cd63c675ddef578746c19e
|
4
|
+
data.tar.gz: 6b3f703fcbe41564e85e1aa7f9853446a554b0c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 -
|
35
|
+
system "sudo -Es sh -c \'umask 022; gem install gems/#{file}\'"
|
37
36
|
end
|
38
37
|
|
39
38
|
desc 'Remove gems'
|
data/lib/oxidized/script/cli.rb
CHANGED
@@ -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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
44
|
-
cmd[:class].
|
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
|
@@ -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
|
-
|
10
|
-
|
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
|
-
|
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
|
data/oxidized-script.gemspec
CHANGED
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
|
+
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-
|
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
|