oxidized-script 0.3.0 → 0.3.1
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/CHANGELOG.md +4 -0
- data/README.md +2 -1
- data/Rakefile +15 -19
- data/lib/oxidized/script/cli.rb +34 -32
- data/oxidized-script.gemspec +1 -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: f33b06421d3e4c2ab37dd2532a68215b98991d34
|
4
|
+
data.tar.gz: e9349537593bfbc2b4194827381ce8f3f400ab8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09dbc25da8a981abcadd591ffe630a037c4068c248ef7d5117c60d4272d40be424c5b4efc5e86df5a180541233ac1142237c57a8751ed95561a54b01e4a555b1
|
7
|
+
data.tar.gz: 39895ff7b8f342f1e7ff3470ee010b1ea0e9ada7200bee3ce2556ada7d743cc978672b894a652faeb762b3a8b383f929768689208fb814e1568c8eb9a9d8f7a1
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# 0.3.1
|
2
|
+
- FEATURE on --dryrun to get a list of nodes without running a command (by @nertwork)
|
3
|
+
- BUGFIX: errors with large config files running in ruby threads - forking instead (by @nertwork)
|
4
|
+
|
1
5
|
# 0.3.0
|
2
6
|
- FEATURE on --regex to run commands on hosts matching a regex (by @nertwork)
|
3
7
|
- FEATURE on -g to run commands on entire group (by @nertwork)
|
data/README.md
CHANGED
@@ -46,7 +46,8 @@ Usage: oxs [options] hostname [command]
|
|
46
46
|
-c, --community snmp community to use for discovery
|
47
47
|
-g, --group group to run commands on (ios, junos, etc), specified in oxidized db
|
48
48
|
-r, --threads specify ammount of threads to use for running group (default: 1)
|
49
|
-
--regex
|
49
|
+
--regex run on all hosts that match the regexp
|
50
|
+
--dryrun do a dry run on either groups or regexp to find matching hosts
|
50
51
|
--protocols protocols to use, default "ssh, telnet"
|
51
52
|
-v, --verbose verbose output, e.g. show commands sent
|
52
53
|
-d, --debug turn on debugging
|
data/Rakefile
CHANGED
@@ -1,10 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'bundler'
|
4
|
-
# Bundler.setup
|
5
|
-
rescue LoadError
|
6
|
-
warn 'bunler missing'
|
7
|
-
end
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
8
3
|
|
9
4
|
gemspec = eval(File.read(Dir['*.gemspec'].first))
|
10
5
|
file = [gemspec.name, gemspec.version].join('-') + '.gem'
|
@@ -17,19 +12,13 @@ end
|
|
17
12
|
desc 'Run minitest'
|
18
13
|
task :test do
|
19
14
|
Rake::TestTask.new do |t|
|
20
|
-
t.libs
|
21
|
-
t.test_files = FileList['spec
|
15
|
+
t.libs << 'spec'
|
16
|
+
t.test_files = FileList['spec/**/*_spec.rb']
|
17
|
+
t.warning = true
|
22
18
|
t.verbose = true
|
23
19
|
end
|
24
20
|
end
|
25
21
|
|
26
|
-
desc 'Build gem'
|
27
|
-
task :build do
|
28
|
-
system "gem build #{gemspec.name}.gemspec"
|
29
|
-
FileUtils.mkdir_p 'gems'
|
30
|
-
FileUtils.mv file, 'gems'
|
31
|
-
end
|
32
|
-
|
33
22
|
desc 'Install gem'
|
34
23
|
task :install => :build do
|
35
24
|
system "sudo -Es sh -c \'umask 022; gem install gems/#{file}\'"
|
@@ -37,10 +26,17 @@ end
|
|
37
26
|
|
38
27
|
desc 'Remove gems'
|
39
28
|
task :clean do
|
40
|
-
FileUtils.rm_rf '
|
29
|
+
FileUtils.rm_rf 'pkg'
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'Tag the release'
|
33
|
+
task :tag do
|
34
|
+
system "git tag #{gemspec.version}"
|
41
35
|
end
|
42
36
|
|
43
37
|
desc 'Push to rubygems'
|
44
|
-
task :push do
|
45
|
-
system "gem push
|
38
|
+
task :push => :tag do
|
39
|
+
system "gem push pkg/#{file}"
|
46
40
|
end
|
41
|
+
|
42
|
+
task default: :test
|
data/lib/oxidized/script/cli.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Oxidized
|
2
2
|
require_relative 'script'
|
3
3
|
require 'slop'
|
4
|
-
require 'thread'
|
5
4
|
|
6
5
|
class Script
|
7
6
|
class CLI
|
@@ -12,29 +11,26 @@ module Oxidized
|
|
12
11
|
def run
|
13
12
|
if @group or @regex
|
14
13
|
nodes = get_hosts
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
counter = @threads.to_i
|
15
|
+
Signal.trap("CLD") { counter += 1 }
|
16
|
+
nodes.each do |node|
|
17
|
+
Process.wait if counter <= 0
|
18
|
+
puts "Forking " + node if @verbose
|
19
|
+
counter -= 1
|
20
|
+
fork {
|
19
21
|
begin
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
elsif @cmd
|
27
|
-
puts @oxs.cmd @cmd
|
28
|
-
end
|
29
|
-
rescue
|
30
|
-
puts "Couldn't connect to: " + node
|
31
|
-
end
|
22
|
+
@host = node
|
23
|
+
connect
|
24
|
+
if @opts[:commands]
|
25
|
+
puts "Running commands on #{node}:\n#{run_file @opts[:commands]}"
|
26
|
+
elsif @cmd
|
27
|
+
puts "Running commands on #{node}:\n#{@oxs.cmd @cmd}"
|
32
28
|
end
|
33
|
-
rescue
|
29
|
+
rescue => error
|
30
|
+
puts "We had the following error on node #{node}:\n#{error}"
|
34
31
|
end
|
35
|
-
|
32
|
+
}
|
36
33
|
end
|
37
|
-
workers.map(&:join)
|
38
34
|
else
|
39
35
|
connect
|
40
36
|
if @opts[:commands]
|
@@ -69,6 +65,10 @@ module Oxidized
|
|
69
65
|
end
|
70
66
|
@oxs = nil
|
71
67
|
raise NothingToDo, 'no host given' if not @host and not @group and not @regex
|
68
|
+
if @dryrun
|
69
|
+
puts get_hosts
|
70
|
+
exit
|
71
|
+
end
|
72
72
|
raise NothingToDo, 'nothing to do, give command or -x' if not @cmd and not @opts[:commands]
|
73
73
|
end
|
74
74
|
end
|
@@ -86,6 +86,7 @@ module Oxidized
|
|
86
86
|
slop.on 'g=', '--group', 'group to run commands on (ios, junos, etc), specified in oxidized db'
|
87
87
|
slop.on 'r=', '--threads', 'specify ammount of threads to use for running group', default: '1'
|
88
88
|
slop.on '--regex=', 'run on all hosts that match the regexp'
|
89
|
+
slop.on '--dryrun', 'do a dry run on either groups or regexp to find matching hosts'
|
89
90
|
slop.on '--protocols=','protocols to use, default "ssh, telnet"'
|
90
91
|
slop.on 'v', '--verbose', 'verbose output, e.g. show commands sent'
|
91
92
|
slop.on 'd', '--debug', 'turn on debugging'
|
@@ -103,6 +104,7 @@ module Oxidized
|
|
103
104
|
@group = slop[:group]
|
104
105
|
@threads = slop[:threads]
|
105
106
|
@verbose = slop[:verbose]
|
107
|
+
@dryrun= slop[:dryrun]
|
106
108
|
@regex = slop[:regex]
|
107
109
|
[slop.parse!, slop]
|
108
110
|
end
|
@@ -144,18 +146,18 @@ module Oxidized
|
|
144
146
|
end
|
145
147
|
|
146
148
|
def get_hosts
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
149
|
+
if @group and @regex
|
150
|
+
puts "running list for hosts in group: #{@group} and matching: #{@regex}" if @verbose
|
151
|
+
nodes_group = run_group @group
|
152
|
+
nodes_regex = run_regex @regex
|
153
|
+
return nodes_group & nodes_regex
|
154
|
+
elsif @regex
|
155
|
+
puts 'running list for hosts matching: ' + @regex if @verbose
|
156
|
+
return run_regex @regex
|
157
|
+
else
|
158
|
+
puts 'running list for hosts in group: ' + @group if @verbose
|
159
|
+
return run_group @group
|
160
|
+
end
|
159
161
|
end
|
160
162
|
|
161
163
|
def run_group group
|
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.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Saku Ytti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oxidized
|