oxidized-fetch 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +35 -0
- data/Gemfile +3 -0
- data/README.md +1 -0
- data/Rakefile +46 -0
- data/bin/oxf +9 -0
- data/lib/oxidized/fetch/cli.rb +50 -0
- data/lib/oxidized/fetch/fetch.rb +85 -0
- data/lib/oxidized/fetch.rb +1 -0
- data/oxidized-fetch.gemspec +18 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d0c4b2b86e5ad256c3ef70ec1282bb8becbb743d
|
4
|
+
data.tar.gz: 14e2787491aadda46d897fca3dd8e6dacac29c7b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 98c8073936a2ce62ce747a3ccb0dc44cd690351160b2ddbfb2791ee217bfdb042dacbc9f00def9ee9686ee0031871776c2b2aeeb00d9837b82a45ee026a67c1b
|
7
|
+
data.tar.gz: a7fec564b70acf8ee646c5c04b0c56eec499d95bb52006695590a3a92195f8b9b5d025ea5956f4c2d42a4d453fd571d9c27e0676445388c03291ad762db4fc89
|
data/.gitignore
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
# Gemfile.lock
|
31
|
+
# .ruby-version
|
32
|
+
# .ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# oxidized-fetch
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
begin
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'bundler'
|
4
|
+
# Bundler.setup
|
5
|
+
rescue LoadError
|
6
|
+
warn 'bunler missing'
|
7
|
+
end
|
8
|
+
|
9
|
+
gemspec = eval(File.read(Dir['*.gemspec'].first))
|
10
|
+
file = [gemspec.name, gemspec.version].join('-') + '.gem'
|
11
|
+
|
12
|
+
desc 'Validate gemspec'
|
13
|
+
task :gemspec do
|
14
|
+
gemspec.validate
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Run minitest'
|
18
|
+
task :test do
|
19
|
+
Rake::TestTask.new do |t|
|
20
|
+
t.libs.push "lib"
|
21
|
+
t.test_files = FileList['spec/*_spec.rb']
|
22
|
+
t.verbose = true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
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
|
+
desc 'Install gem'
|
34
|
+
task :install => :build do
|
35
|
+
system "sudo -Es sh -c \'umask 022; gem install gems/#{file}\'"
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'Remove gems'
|
39
|
+
task :clean do
|
40
|
+
FileUtils.rm_rf 'gems'
|
41
|
+
end
|
42
|
+
|
43
|
+
desc 'Push to rubygems'
|
44
|
+
task :push do
|
45
|
+
system "gem push gems/#{file}"
|
46
|
+
end
|
data/bin/oxf
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module Oxidized
|
2
|
+
require_relative 'fetch'
|
3
|
+
require 'slop'
|
4
|
+
class Fetch
|
5
|
+
class CLI
|
6
|
+
class CLIError < ScriptError; end
|
7
|
+
class NothingToDo < ScriptError; end
|
8
|
+
|
9
|
+
def run
|
10
|
+
connect
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@args, @opts = opts_parse
|
17
|
+
CFG.debug = true if @opts[:debug]
|
18
|
+
@host = @args.shift
|
19
|
+
@oxf = nil
|
20
|
+
raise NothingToDo, 'no host given' if not @host
|
21
|
+
end
|
22
|
+
|
23
|
+
def opts_parse
|
24
|
+
slop = Slop.new(:help=>true)
|
25
|
+
slop.banner 'Usage: oxf [options] hostname'
|
26
|
+
slop.on 'm=', '--model', 'host model (ios, junos, etc), otherwise discovered from Oxidized source'
|
27
|
+
slop.on 'u=', '--username', 'username to use'
|
28
|
+
slop.on 'p=', '--password', 'password to use'
|
29
|
+
slop.on 't=', '--timeout', 'timeout value to use'
|
30
|
+
slop.on 'e=', '--enable', 'enable password to use'
|
31
|
+
slop.on 'c=', '--community', 'snmp community to use for discovery'
|
32
|
+
slop.on '--protocols=','protocols to use, default "ssh, telnet"'
|
33
|
+
slop.on 'v', '--verbose', 'verbose output, e.g. show commands sent'
|
34
|
+
slop.on 'd', '--debug', 'turn on debugging'
|
35
|
+
slop.on :terse, 'display clean output'
|
36
|
+
slop.parse
|
37
|
+
[slop.parse!, slop]
|
38
|
+
end
|
39
|
+
|
40
|
+
def connect
|
41
|
+
opts = {}
|
42
|
+
opts[:host] = @host
|
43
|
+
[:model, :username, :password, :timeout, :enable, :verbose, :community, :protocols].each do |key|
|
44
|
+
opts[key] = @opts[key] if @opts[key]
|
45
|
+
end
|
46
|
+
@oxf = Fetch.new opts
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
module Oxidized
|
4
|
+
require 'oxidized'
|
5
|
+
class Fetch
|
6
|
+
attr_reader :model
|
7
|
+
|
8
|
+
class ScriptError < OxidizedError; end
|
9
|
+
class NoNode < ScriptError; end
|
10
|
+
class InvalidOption < ScriptError; end
|
11
|
+
class NoConnection < ScriptError
|
12
|
+
attr_accessor :node_error
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
# @param [Hash] opts options for Oxidized::Fetch
|
18
|
+
# @option opts [String] :host hostname or ip address for Oxidized::Node
|
19
|
+
# @option opts [String] :model node model (ios, junos etc) if defined, nodes are not loaded from source
|
20
|
+
# @option opts [Fixnum] :timeout oxidized timeout
|
21
|
+
# @option opts [String] :username username for login
|
22
|
+
# @option opts [String] :passsword password for login
|
23
|
+
# @option opts [String] :enable enable password to use
|
24
|
+
# @option opts [String] :community community to use for discovery
|
25
|
+
# @option opts [String] :protocols protocols to use to connect, default "ssh ,telnet"
|
26
|
+
# @option opts [boolean] :verbose extra output, e.g. show command given in output
|
27
|
+
# @yieldreturn [self] if called in block, returns self and disconnnects session after exiting block
|
28
|
+
# @return [void]
|
29
|
+
def initialize opts, &block
|
30
|
+
host = opts.delete :host
|
31
|
+
model = opts.delete :model
|
32
|
+
timeout = opts.delete :timeout
|
33
|
+
username = opts.delete :username
|
34
|
+
password = opts.delete :password
|
35
|
+
enable = opts.delete :enable
|
36
|
+
community = opts.delete :community
|
37
|
+
@verbose = opts.delete :verbose
|
38
|
+
CFG.input.default = opts.delete :protocols if opts[:protocols]
|
39
|
+
raise InvalidOption, "#{opts} not recognized" unless opts.empty?
|
40
|
+
|
41
|
+
@@oxi ||= false
|
42
|
+
if not @@oxi
|
43
|
+
Oxidized.mgr = Manager.new
|
44
|
+
@@oxi = true
|
45
|
+
end
|
46
|
+
|
47
|
+
@node = if model
|
48
|
+
Node.new(:name=>host, :model=>model)
|
49
|
+
else
|
50
|
+
Nodes.new(:node=>host).first
|
51
|
+
end
|
52
|
+
if not @node
|
53
|
+
begin
|
54
|
+
require 'corona'
|
55
|
+
community ||= Corona::CFG.community
|
56
|
+
rescue LoadError
|
57
|
+
raise NoNode, 'node not found'
|
58
|
+
end
|
59
|
+
node = Corona.poll :host=>host, :community=>community
|
60
|
+
raise NoNode, 'node not found' unless node
|
61
|
+
@node = Node.new :name=>host, :model=>node[:model]
|
62
|
+
end
|
63
|
+
@node.auth[:username] = username if username
|
64
|
+
@node.auth[:password] = password if password
|
65
|
+
CFG.vars.enable = enable if enable
|
66
|
+
CFG.timeout = timeout if timeout
|
67
|
+
|
68
|
+
status, config = @node.run
|
69
|
+
if status == :success
|
70
|
+
msg = "update #{@node.name}"
|
71
|
+
msg += " from #{@node.from}" if @node.from
|
72
|
+
msg += " with message '#{@node.msg}'" if @node.msg
|
73
|
+
if @node.output.new.store @node.name, config, :msg => msg, :user => @node.user, :group => @node.group
|
74
|
+
STDERR.write "Configuration updated for #{@node.group}/#{@node.name}\n" if @verbose
|
75
|
+
exit 1
|
76
|
+
end
|
77
|
+
STDERR.write "Configuration NOT updated for #{@node.group}/#{@node.name}\n" if @verbose
|
78
|
+
exit 0
|
79
|
+
else
|
80
|
+
STDERR.write "An unexpected error occurred\n" if @verbose
|
81
|
+
exit -1
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'fetch/fetch'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'oxidized-fetch'
|
3
|
+
s.version = '0.1.0'
|
4
|
+
s.licenses = %w( Apache-2.0 )
|
5
|
+
s.platform = Gem::Platform::RUBY
|
6
|
+
s.authors = [ 'Giovanni Lovato', 'Alex Tomasello' ]
|
7
|
+
s.email = %w( heruan@aldu.net )
|
8
|
+
s.homepage = 'http://github.com/heruan/oxidized-fetch'
|
9
|
+
s.summary = 'cli + library for scripting network devices'
|
10
|
+
s.description = 'rancid clogin-like script to push configs to devices + library interface to do same'
|
11
|
+
s.rubyforge_project = s.name
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.executables = %w( oxf )
|
14
|
+
s.require_path = 'lib'
|
15
|
+
|
16
|
+
s.add_runtime_dependency 'oxidized', '~> 0.2'
|
17
|
+
s.add_runtime_dependency 'slop', '~> 3.5'
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oxidized-fetch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Giovanni Lovato
|
8
|
+
- Alex Tomasello
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-09-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: oxidized
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0.2'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0.2'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: slop
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3.5'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '3.5'
|
42
|
+
description: rancid clogin-like script to push configs to devices + library interface
|
43
|
+
to do same
|
44
|
+
email:
|
45
|
+
- heruan@aldu.net
|
46
|
+
executables:
|
47
|
+
- oxf
|
48
|
+
extensions: []
|
49
|
+
extra_rdoc_files: []
|
50
|
+
files:
|
51
|
+
- ".gitignore"
|
52
|
+
- Gemfile
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/oxf
|
56
|
+
- lib/oxidized/fetch.rb
|
57
|
+
- lib/oxidized/fetch/cli.rb
|
58
|
+
- lib/oxidized/fetch/fetch.rb
|
59
|
+
- oxidized-fetch.gemspec
|
60
|
+
homepage: http://github.com/heruan/oxidized-fetch
|
61
|
+
licenses:
|
62
|
+
- Apache-2.0
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project: oxidized-fetch
|
80
|
+
rubygems_version: 2.0.14
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: cli + library for scripting network devices
|
84
|
+
test_files: []
|