oxidized-script 0.0.2 → 0.0.3

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: ea9be3c8d9c8f52605aa70e968d1402b067bd9c5
4
- data.tar.gz: 92dd4aeba5806eda79f706be7b77813f9a05cf6f
3
+ metadata.gz: 68cefc95e5aa80208cafc27a688c8be059491610
4
+ data.tar.gz: b494915c82884731ed23e7e0b840769f131e239d
5
5
  SHA512:
6
- metadata.gz: bd23cfcd6376dd20c7676ecf183a635b3e3953ecf9a1dc61f1c3760b2821518bb6e0ee10a4bc86bcb54a3d47581d1184b0f091ff96d44d0d14146f6504fb59bf
7
- data.tar.gz: 0a8d27f8bec9dbda18078b914088285f65df78dc780d965f19ed9e98492328aebac13012b4370b8679e2e8073502694f1a03dd30a2db35160dccb7f448c8cf0c
6
+ metadata.gz: b14fb72028484d26c864247868803ab5d559b868adbbebc1f5dff19be3efefea04df5ec7bf6cb493ad111d45b72fe2177ada490a75d1f457148e45a98ae7f4ca
7
+ data.tar.gz: 652cfd656ae8f34d6e867f8d7f4790955da500f02d9980a1a02d2b174640a35d2867125fbefc5f58b14191f89bb4771e08a49d3cca2887d72efbb020941fe936
@@ -18,27 +18,32 @@ module Oxidized
18
18
  private
19
19
 
20
20
  def initialize
21
- args, @opts = opts_parse
21
+ @args, @opts = opts_parse load_dynamic
22
22
  CFG.debug = true if @opts[:debug]
23
- @host = args.shift
24
- @cmd = args.shift if args
23
+ @host = @args.shift
24
+ @cmd = @args.shift if @args
25
25
  @oxs = nil
26
26
  raise NothingToDo, 'no host given' if not @host
27
27
  raise NothingToDo, 'nothing to do, give command or -x' if not @cmd and not @opts[:commands]
28
28
  end
29
29
 
30
- def opts_parse
31
- slop = Slop.parse(:help=>true) do
32
- banner 'Usage: oxs [options] hostname [command]'
33
- on 'm=', '--model', 'host model (ios, junos, etc), otherwise discovered from Oxidized source'
34
- on 'x=', '--commands', 'commands file to be sent'
35
- on 'u=', '--username', 'username to use'
36
- on 'p=', '--password', 'password to use'
37
- on 't=', '--timeout', 'timeout value to use'
38
- on 'e=', '--enable', 'enable password to use'
39
- on 'v', '--verbose', 'verbose output, e.g. show commands sent'
40
- on 'd', '--debug', 'turn on debugging'
30
+ def opts_parse cmds
31
+ slop = Slop.new(:help=>true)
32
+ slop.banner 'Usage: oxs [options] hostname [command]'
33
+ slop.on 'm=', '--model', 'host model (ios, junos, etc), otherwise discovered from Oxidized source'
34
+ slop.on 'x=', '--commands', 'commands file to be sent'
35
+ slop.on 'u=', '--username', 'username to use'
36
+ slop.on 'p=', '--password', 'password to use'
37
+ slop.on 't=', '--timeout', 'timeout value to use'
38
+ slop.on 'e=', '--enable', 'enable password to use'
39
+ slop.on 'v', '--verbose', 'verbose output, e.g. show commands sent'
40
+ slop.on 'd', '--debug', 'turn on debugging'
41
+ cmds.each do |cmd|
42
+ slop.on cmd[:name], cmd[:description] do
43
+ cmd[:class].run(:args=>@args, :opts=>@opts, :host=>@host, :cmd=>@cmd)
44
+ end
41
45
  end
46
+ slop.parse
42
47
  [slop.parse!, slop]
43
48
  end
44
49
 
@@ -61,6 +66,21 @@ module Oxidized
61
66
  out
62
67
  end
63
68
 
69
+ def load_dynamic
70
+ cmds = []
71
+ files = File.dirname __FILE__
72
+ files = File.join files, 'commands', '*.rb'
73
+ files = Dir.glob files
74
+ files.each { |file| require_relative file }
75
+ Script::Command.constants.each do |cmd|
76
+ cmd = Script::Command.const_get cmd
77
+ name = cmd.const_get :Name
78
+ desc = cmd.const_get :Description
79
+ cmds << {:class=>cmd, :name=>name, :description=>desc}
80
+ end
81
+ cmds
82
+ end
83
+
64
84
  end
65
85
  end
66
86
  end
@@ -0,0 +1,30 @@
1
+ module Oxidized
2
+ class Script
3
+ module Command
4
+ class ListModels
5
+ Name = 'list-models'
6
+ Description = 'list supported models'
7
+
8
+ def self.run opts={}
9
+ puts new(opts).models
10
+ exit
11
+ end
12
+
13
+ def models
14
+ out = ''
15
+ models = Dir.glob File.join Config::ModelDir, '*.rb'
16
+ models.each do |model|
17
+ out += "%15s - %s\n" % [File.basename(model, '.rb'), model]
18
+ end
19
+ out
20
+ end
21
+
22
+ private
23
+
24
+ def initialize opts={}
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,37 @@
1
+ module Oxidized
2
+ class Script
3
+ module Command
4
+ class ListNodes
5
+ Name = 'list-nodes'
6
+ Description = 'list nodes in oxidized source'
7
+
8
+ def self.run opts={}
9
+ puts new(opts).nodes
10
+ exit
11
+ end
12
+
13
+ def nodes
14
+ out = ''
15
+ Nodes.new.each do |node|
16
+ out += "#{node.name}:\n"
17
+ node.instance_variables.each do |var|
18
+ name = var.to_s[1..-1]
19
+ next if name == 'name'
20
+ value = node.instance_variable_get var
21
+ value = value.class if name == 'model'
22
+ out += " %10s => %s\n" % [name, value.to_s]
23
+ end
24
+ end
25
+ out
26
+ end
27
+
28
+ private
29
+
30
+ def initialize opts={}
31
+ Oxidized.mgr = Manager.new
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'oxidized-script'
3
- s.version = '0.0.2'
3
+ s.version = '0.0.3'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = [ 'Saku Ytti' ]
6
6
  s.email = %w( saku@ytti.fi )
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oxidized-script
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saku Ytti
@@ -54,6 +54,8 @@ files:
54
54
  - bin/oxs
55
55
  - lib/oxidized/script.rb
56
56
  - lib/oxidized/script/cli.rb
57
+ - lib/oxidized/script/commands/list-models.rb
58
+ - lib/oxidized/script/commands/list-nodes.rb
57
59
  - lib/oxidized/script/script.rb
58
60
  - oxidized-script.gemspec
59
61
  homepage: http://github.com/ytti/oxidized-script