oxidized 0.21.0 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +5 -5
  2. data/.github/no-response.yml +13 -0
  3. data/.gitignore +3 -0
  4. data/.rubocop.yml +37 -0
  5. data/.rubocop_todo.yml +714 -0
  6. data/.travis.yml +7 -1
  7. data/CHANGELOG.md +341 -243
  8. data/Dockerfile +44 -16
  9. data/LICENSE +201 -0
  10. data/README.md +114 -82
  11. data/Rakefile +19 -0
  12. data/TODO.md +29 -23
  13. data/bin/oxidized +1 -2
  14. data/docs/Configuration.md +71 -31
  15. data/docs/Creating-Models.md +78 -0
  16. data/docs/Hooks.md +145 -41
  17. data/docs/Model-Notes/AireOS.md +12 -0
  18. data/docs/Model-Notes/ArbOS.md +12 -0
  19. data/docs/Model-Notes/Comware.md +14 -0
  20. data/docs/Model-Notes/EOS.md +9 -0
  21. data/docs/Model-Notes/JunOS.md +34 -0
  22. data/docs/Model-Notes/Netgear.md +68 -0
  23. data/docs/Model-Notes/README.md +19 -0
  24. data/docs/{VRP-Huawei.md → Model-Notes/VRP-Huawei.md} +10 -2
  25. data/docs/Model-Notes/XGS4600-Zyxel.md +39 -0
  26. data/docs/Outputs.md +27 -28
  27. data/docs/Ruby-API.md +38 -18
  28. data/docs/Sources.md +78 -16
  29. data/docs/Supported-OS-Types.md +171 -148
  30. data/extra/oxidized.logrotate +7 -0
  31. data/extra/oxidized.service +1 -1
  32. data/extra/rest_client.rb +4 -5
  33. data/extra/syslog.rb +16 -16
  34. data/lib/oxidized/cli.rb +3 -3
  35. data/lib/oxidized/config.rb +7 -4
  36. data/lib/oxidized/core.rb +3 -3
  37. data/lib/oxidized/hook.rb +64 -65
  38. data/lib/oxidized/hook/awssns.rb +2 -3
  39. data/lib/oxidized/hook/ciscosparkdiff.rb +49 -0
  40. data/lib/oxidized/hook/exec.rb +5 -5
  41. data/lib/oxidized/hook/githubrepo.rb +20 -14
  42. data/lib/oxidized/hook/slackdiff.rb +38 -19
  43. data/lib/oxidized/hook/xmppdiff.rb +58 -0
  44. data/lib/oxidized/input/cli.rb +5 -6
  45. data/lib/oxidized/input/ftp.rb +8 -7
  46. data/lib/oxidized/input/http.rb +39 -0
  47. data/lib/oxidized/input/ssh.rb +24 -22
  48. data/lib/oxidized/input/telnet.rb +38 -32
  49. data/lib/oxidized/jobs.rb +3 -4
  50. data/lib/oxidized/manager.rb +9 -4
  51. data/lib/oxidized/model/acos.rb +15 -16
  52. data/lib/oxidized/model/acsw.rb +3 -8
  53. data/lib/oxidized/model/aen.rb +1 -2
  54. data/lib/oxidized/model/aireos.rb +3 -5
  55. data/lib/oxidized/model/alteonos.rb +16 -18
  56. data/lib/oxidized/model/alvarion.rb +0 -4
  57. data/lib/oxidized/model/aos.rb +2 -4
  58. data/lib/oxidized/model/aos7.rb +2 -3
  59. data/lib/oxidized/model/aosw.rb +13 -15
  60. data/lib/oxidized/model/apc_aos.rb +0 -3
  61. data/lib/oxidized/model/arbos.rb +26 -0
  62. data/lib/oxidized/model/aricentiss.rb +51 -0
  63. data/lib/oxidized/model/asa.rb +33 -35
  64. data/lib/oxidized/model/asyncos.rb +41 -44
  65. data/lib/oxidized/model/audiocodes.rb +4 -8
  66. data/lib/oxidized/model/awplus.rb +84 -0
  67. data/lib/oxidized/model/boss.rb +6 -5
  68. data/lib/oxidized/model/br6910.rb +43 -45
  69. data/lib/oxidized/model/c4cmts.rb +3 -5
  70. data/lib/oxidized/model/cambium.rb +22 -0
  71. data/lib/oxidized/model/catos.rb +0 -2
  72. data/lib/oxidized/model/cisconga.rb +1 -3
  73. data/lib/oxidized/model/ciscosma.rb +37 -40
  74. data/lib/oxidized/model/ciscosmb.rb +7 -4
  75. data/lib/oxidized/model/comnetms.rb +43 -0
  76. data/lib/oxidized/model/comware.rb +9 -9
  77. data/lib/oxidized/model/coriant8600.rb +3 -5
  78. data/lib/oxidized/model/coriantgroove.rb +3 -5
  79. data/lib/oxidized/model/corianttmos.rb +1 -3
  80. data/lib/oxidized/model/cumulus.rb +26 -32
  81. data/lib/oxidized/model/datacom.rb +0 -2
  82. data/lib/oxidized/model/dcnos.rb +46 -0
  83. data/lib/oxidized/model/dlink.rb +1 -1
  84. data/lib/oxidized/model/dnos.rb +9 -5
  85. data/lib/oxidized/model/edgecos.rb +45 -0
  86. data/lib/oxidized/model/edgeos.rb +5 -3
  87. data/lib/oxidized/model/edgeswitch.rb +1 -3
  88. data/lib/oxidized/model/enterasys.rb +1 -3
  89. data/lib/oxidized/model/eos.rb +6 -8
  90. data/lib/oxidized/model/fabricos.rb +3 -5
  91. data/lib/oxidized/model/firewareos.rb +2 -5
  92. data/lib/oxidized/model/fortios.rb +21 -17
  93. data/lib/oxidized/model/ftos.rb +2 -4
  94. data/lib/oxidized/model/fujitsupy.rb +2 -4
  95. data/lib/oxidized/model/gaiaos.rb +6 -10
  96. data/lib/oxidized/model/gcombnps.rb +82 -0
  97. data/lib/oxidized/model/hatteras.rb +8 -5
  98. data/lib/oxidized/model/hirschmann.rb +8 -10
  99. data/lib/oxidized/model/hpebladesystem.rb +19 -17
  100. data/lib/oxidized/model/hpemsa.rb +0 -3
  101. data/lib/oxidized/model/ios.rb +54 -55
  102. data/lib/oxidized/model/iosxe.rb +5 -0
  103. data/lib/oxidized/model/iosxr.rb +1 -3
  104. data/lib/oxidized/model/ipos.rb +1 -3
  105. data/lib/oxidized/model/ironware.rb +12 -15
  106. data/lib/oxidized/model/isam.rb +4 -5
  107. data/lib/oxidized/model/junos.rb +8 -7
  108. data/lib/oxidized/model/masteros.rb +1 -3
  109. data/lib/oxidized/model/mlnxos.rb +3 -4
  110. data/lib/oxidized/model/model.rb +15 -7
  111. data/lib/oxidized/model/mtrlrfs.rb +1 -4
  112. data/lib/oxidized/model/ndms.rb +24 -0
  113. data/lib/oxidized/model/netgear.rb +3 -4
  114. data/lib/oxidized/model/netscaler.rb +0 -2
  115. data/lib/oxidized/model/nos.rb +1 -3
  116. data/lib/oxidized/model/nxos.rb +13 -3
  117. data/lib/oxidized/model/oneos.rb +6 -8
  118. data/lib/oxidized/model/openbsd.rb +76 -0
  119. data/lib/oxidized/model/opengear.rb +3 -5
  120. data/lib/oxidized/model/openwrt.rb +77 -0
  121. data/lib/oxidized/model/opnsense.rb +19 -0
  122. data/lib/oxidized/model/outputs.rb +1 -3
  123. data/lib/oxidized/model/panos.rb +1 -2
  124. data/lib/oxidized/model/pfsense.rb +9 -5
  125. data/lib/oxidized/model/planet.rb +8 -12
  126. data/lib/oxidized/model/powerconnect.rb +6 -9
  127. data/lib/oxidized/model/procurve.rb +18 -4
  128. data/lib/oxidized/model/quantaos.rb +3 -5
  129. data/lib/oxidized/model/routeros.rb +3 -2
  130. data/lib/oxidized/model/saos.rb +0 -1
  131. data/lib/oxidized/model/screenos.rb +3 -5
  132. data/lib/oxidized/model/sgos.rb +2 -3
  133. data/lib/oxidized/model/siklu.rb +0 -2
  134. data/lib/oxidized/model/slxos.rb +59 -0
  135. data/lib/oxidized/model/sros.rb +117 -0
  136. data/lib/oxidized/model/stoneos.rb +32 -0
  137. data/lib/oxidized/model/supermicro.rb +6 -41
  138. data/lib/oxidized/model/timos.rb +6 -114
  139. data/lib/oxidized/model/tmos.rb +1 -3
  140. data/lib/oxidized/model/tplink.rb +7 -11
  141. data/lib/oxidized/model/trango.rb +6 -7
  142. data/lib/oxidized/model/ucs.rb +0 -1
  143. data/lib/oxidized/model/voltaire.rb +3 -6
  144. data/lib/oxidized/model/voss.rb +1 -2
  145. data/lib/oxidized/model/vrp.rb +4 -5
  146. data/lib/oxidized/model/vyatta.rb +6 -4
  147. data/lib/oxidized/model/weos.rb +1 -3
  148. data/lib/oxidized/model/xos.rb +6 -5
  149. data/lib/oxidized/model/zhoneolt.rb +2 -2
  150. data/lib/oxidized/model/zynos.rb +1 -3
  151. data/lib/oxidized/model/zynoscli.rb +36 -0
  152. data/lib/oxidized/node.rb +11 -11
  153. data/lib/oxidized/node/stats.rb +15 -2
  154. data/lib/oxidized/nodes.rb +8 -8
  155. data/lib/oxidized/output/file.rb +41 -42
  156. data/lib/oxidized/output/git.rb +113 -115
  157. data/lib/oxidized/output/gitcrypt.rb +241 -242
  158. data/lib/oxidized/output/http.rb +23 -27
  159. data/lib/oxidized/output/output.rb +1 -2
  160. data/lib/oxidized/source/csv.rb +44 -45
  161. data/lib/oxidized/source/http.rb +52 -49
  162. data/lib/oxidized/source/source.rb +6 -7
  163. data/lib/oxidized/source/sql.rb +55 -51
  164. data/lib/oxidized/string.rb +3 -4
  165. data/lib/oxidized/version.rb +17 -1
  166. data/lib/oxidized/worker.rb +12 -3
  167. data/oxidized.gemspec +19 -13
  168. metadata +139 -51
  169. data/.ruby-version +0 -1
  170. data/Gemfile.lock +0 -44
@@ -7,9 +7,9 @@ module Oxidized
7
7
 
8
8
  def setup
9
9
  if @cfg.empty?
10
- CFGS.user.output.http.user = 'Oxidized'
10
+ CFGS.user.output.http.user = 'Oxidized'
11
11
  CFGS.user.output.http.pasword = 'secret'
12
- CFGS.user.output.http.url = 'http://localhost/web-api/oxidized'
12
+ CFGS.user.output.http.url = 'http://localhost/web-api/oxidized'
13
13
  CFGS.save :user
14
14
  raise NoConfig, 'no output http config, edit ~/.config/oxidized/config'
15
15
  end
@@ -17,42 +17,38 @@ module Oxidized
17
17
  require "net/http"
18
18
  require "uri"
19
19
  require "json"
20
- def store node, outputs, opt={}
20
+ def store node, outputs, opt = {}
21
21
  @commitref = nil
22
22
  json = JSON.pretty_generate(
23
- {
24
- 'msg' => opt[:msg],
25
- 'user' => opt[:user],
26
- 'email' => opt[:email],
27
- 'group' => opt[:group],
28
- 'node' => node,
29
- 'config' => outputs.to_cfg,
30
- # actually we need to also iterate outputs, for other types like in gitlab. But most people don't use 'type' functionality.
31
- }
23
+ {
24
+ 'msg' => opt[:msg],
25
+ 'user' => opt[:user],
26
+ 'email' => opt[:email],
27
+ 'group' => opt[:group],
28
+ 'node' => node,
29
+ 'config' => outputs.to_cfg,
30
+ # actually we need to also iterate outputs, for other types like in gitlab. But most people don't use 'type' functionality.
31
+ }
32
32
  )
33
33
  uri = URI.parse @cfg.url
34
34
  http = Net::HTTP.new uri.host, uri.port
35
- #http.use_ssl = true if uri.scheme = 'https'
36
- req = Net::HTTP::Post.new(uri.request_uri, initheader = { 'Content-Type' => 'application/json'})
35
+ # http.use_ssl = true if uri.scheme = 'https'
36
+ req = Net::HTTP::Post.new(uri.request_uri, initheader = { 'Content-Type' => 'application/json' })
37
37
  req.basic_auth @cfg.user, @cfg.password
38
38
  req.body = json
39
39
  response = http.request req
40
40
 
41
41
  case response.code.to_i
42
- when 200 || 201
43
- Oxidized.logger.info "Configuration http backup complete for #{node}"
44
- p [:success]
45
- when (400..499)
46
- Oxidized.logger.info "Configuration http backup for #{node} failed status: #{response.body}"
47
- p [:bad_request]
48
- when (500..599)
49
- p [:server_problems]
50
- Oxidized.logger.info "Configuration http backup for #{node} failed status: #{response.body}"
42
+ when 200 || 201
43
+ Oxidized.logger.info "Configuration http backup complete for #{node}"
44
+ p [:success]
45
+ when (400..499)
46
+ Oxidized.logger.info "Configuration http backup for #{node} failed status: #{response.body}"
47
+ p [:bad_request]
48
+ when (500..599)
49
+ p [:server_problems]
50
+ Oxidized.logger.info "Configuration http backup for #{node} failed status: #{response.body}"
51
51
  end
52
-
53
52
  end
54
-
55
53
  end
56
54
  end
57
-
58
-
@@ -3,8 +3,7 @@ module Oxidized
3
3
  class NoConfig < OxidizedError; end
4
4
 
5
5
  def cfg_to_str cfg
6
- cfg.select{ |h| h[:type]=='cfg' }.map{ |h| h[:data] }.join
6
+ cfg.select { |h| h[:type] == 'cfg' }.map { |h| h[:data] }.join
7
7
  end
8
-
9
8
  end
10
9
  end
@@ -1,54 +1,53 @@
1
1
  module Oxidized
2
- class CSV < Source
3
- def initialize
4
- @cfg = Oxidized.config.source.csv
5
- super
6
- end
7
-
8
- def setup
9
- if @cfg.empty?
10
- Oxidized.asetus.user.source.csv.file = File.join(Config::Root, 'router.db')
11
- Oxidized.asetus.user.source.csv.delimiter = /:/
12
- Oxidized.asetus.user.source.csv.map.name = 0
13
- Oxidized.asetus.user.source.csv.map.model = 1
14
- Oxidized.asetus.user.source.csv.gpg = false
15
- Oxidized.asetus.save :user
16
- raise NoConfig, 'no source csv config, edit ~/.config/oxidized/config'
2
+ class CSV < Source
3
+ def initialize
4
+ @cfg = Oxidized.config.source.csv
5
+ super
17
6
  end
18
- require 'gpgme' if @cfg.gpg?
19
- end
20
7
 
21
- def load
22
- nodes = []
23
- file = File.expand_path(@cfg.file)
24
- file = if @cfg.gpg?
25
- crypto = GPGME::Crypto.new password: @cfg.gpg_password
26
- crypto.decrypt(file).to_s
27
- else
28
- open(file)
29
- end
30
- file.each_line do |line|
31
- next if line.match(/^\s*#/)
32
- data = line.chomp.split(@cfg.delimiter, -1)
33
- next if data.empty?
34
- # map node parameters
35
- keys = {}
36
- @cfg.map.each do |key, position|
37
- keys[key.to_sym] = node_var_interpolate data[position]
8
+ def setup
9
+ if @cfg.empty?
10
+ Oxidized.asetus.user.source.csv.file = File.join(Config::Root, 'router.db')
11
+ Oxidized.asetus.user.source.csv.delimiter = /:/
12
+ Oxidized.asetus.user.source.csv.map.name = 0
13
+ Oxidized.asetus.user.source.csv.map.model = 1
14
+ Oxidized.asetus.user.source.csv.gpg = false
15
+ Oxidized.asetus.save :user
16
+ raise NoConfig, 'no source csv config, edit ~/.config/oxidized/config'
38
17
  end
39
- keys[:model] = map_model keys[:model] if keys.key? :model
18
+ require 'gpgme' if @cfg.gpg?
19
+ end
40
20
 
41
- # map node specific vars
42
- vars = {}
43
- @cfg.vars_map.each do |key, position|
44
- vars[key.to_sym] = node_var_interpolate data[position]
45
- end
46
- keys[:vars] = vars unless vars.empty?
21
+ def load _node_want = nil
22
+ nodes = []
23
+ file = File.expand_path(@cfg.file)
24
+ file = if @cfg.gpg?
25
+ crypto = GPGME::Crypto.new password: @cfg.gpg_password
26
+ file = crypto.decrypt(File.open(file)).to_s
27
+ else
28
+ open(file)
29
+ end
30
+ file.each_line do |line|
31
+ next if line.match(/^\s*#/)
32
+ data = line.chomp.split(@cfg.delimiter, -1)
33
+ next if data.empty?
34
+ # map node parameters
35
+ keys = {}
36
+ @cfg.map.each do |key, position|
37
+ keys[key.to_sym] = node_var_interpolate data[position]
38
+ end
39
+ keys[:model] = map_model keys[:model] if keys.has_key? :model
47
40
 
48
- nodes << keys
41
+ # map node specific vars
42
+ vars = {}
43
+ @cfg.vars_map.each do |key, position|
44
+ vars[key.to_sym] = node_var_interpolate data[position]
45
+ end
46
+ keys[:vars] = vars unless vars.empty?
47
+
48
+ nodes << keys
49
+ end
50
+ nodes
49
51
  end
50
- nodes
51
52
  end
52
-
53
- end
54
53
  end
@@ -1,64 +1,67 @@
1
1
  module Oxidized
2
- class HTTP < Source
3
- def initialize
4
- @cfg = Oxidized.config.source.http
5
- super
6
- end
7
-
8
- def setup
9
- if @cfg.url.empty?
10
- raise NoConfig, 'no source http url config, edit ~/.config/oxidized/config'
2
+ class HTTP < Source
3
+ def initialize
4
+ @cfg = Oxidized.config.source.http
5
+ super
11
6
  end
12
- end
13
-
14
- require "net/http"
15
- require "uri"
16
- require "json"
17
7
 
18
- def load
19
- nodes = []
20
- uri = URI.parse(@cfg.url)
21
- http = Net::HTTP.new(uri.host, uri.port)
22
- http.use_ssl = true if uri.scheme == 'https'
23
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless @cfg.secure
24
-
25
- # map headers
26
- headers = {}
27
- @cfg.headers.each do |header, value|
28
- headers[header] = value
8
+ def setup
9
+ if @cfg.url.empty?
10
+ raise NoConfig, 'no source http url config, edit ~/.config/oxidized/config'
11
+ end
29
12
  end
30
13
 
31
- request = Net::HTTP::Get.new(uri.request_uri, headers)
32
- if (@cfg.user? && @cfg.pass?)
33
- request.basic_auth(@cfg.user,@cfg.pass)
34
- end
14
+ require "net/http"
15
+ require "uri"
16
+ require "json"
35
17
 
36
- response = http.request(request)
37
- data = JSON.parse(response.body)
38
- data.each do |node|
39
- next if node.empty?
40
- # map node parameters
41
- keys = {}
42
- @cfg.map.each do |key, want_position|
43
- want_positions = want_position.split('.')
44
- keys[key.to_sym] = node_var_interpolate node.dig(*want_positions)
18
+ def load node_want = nil
19
+ nodes = []
20
+ uri = URI.parse(@cfg.url)
21
+ http = Net::HTTP.new(uri.host, uri.port)
22
+ http.use_ssl = true if uri.scheme == 'https'
23
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless @cfg.secure
24
+
25
+ # map headers
26
+ headers = {}
27
+ @cfg.headers.each do |header, value|
28
+ headers[header] = value
45
29
  end
46
- keys[:model] = map_model keys[:model] if keys.key? :model
47
30
 
48
- # map node specific vars
49
- vars = {}
50
- @cfg.vars_map.each do |key, want_position|
51
- want_positions = want_position.split('.')
52
- vars[key.to_sym] = node_var_interpolate node.dig(*want_positions)
31
+ req_uri = uri.request_uri
32
+ if node_want
33
+ req_uri = "#{req_uri}/#{node_want}"
34
+ end
35
+ request = Net::HTTP::Get.new(req_uri, headers)
36
+ if (@cfg.user? && @cfg.pass?)
37
+ request.basic_auth(@cfg.user, @cfg.pass)
53
38
  end
54
- keys[:vars] = vars unless vars.empty?
55
39
 
56
- nodes << keys
40
+ response = http.request(request)
41
+ data = JSON.parse(response.body)
42
+ data.each do |node|
43
+ next if node.empty?
44
+ # map node parameters
45
+ keys = {}
46
+ @cfg.map.each do |key, want_position|
47
+ want_positions = want_position.split('.')
48
+ keys[key.to_sym] = node_var_interpolate node.dig(*want_positions)
49
+ end
50
+ keys[:model] = map_model keys[:model] if keys.has_key? :model
51
+
52
+ # map node specific vars
53
+ vars = {}
54
+ @cfg.vars_map.each do |key, want_position|
55
+ want_positions = want_position.split('.')
56
+ vars[key.to_sym] = node_var_interpolate node.dig(*want_positions)
57
+ end
58
+ keys[:vars] = vars unless vars.empty?
59
+
60
+ nodes << keys
61
+ end
62
+ nodes
57
63
  end
58
- nodes
59
64
  end
60
-
61
- end
62
65
  end
63
66
 
64
67
  if RUBY_VERSION < '2.3'
@@ -11,13 +11,12 @@ module Oxidized
11
11
  end
12
12
 
13
13
  def node_var_interpolate var
14
- case var
15
- when "nil" then nil
16
- when "false" then false
17
- when "true" then true
18
- else var
19
- end
14
+ case var
15
+ when "nil" then nil
16
+ when "false" then false
17
+ when "true" then true
18
+ else var
19
+ end
20
20
  end
21
-
22
21
  end
23
22
  end
@@ -1,63 +1,67 @@
1
1
  module Oxidized
2
- class SQL < Source
3
- begin
4
- require 'sequel'
5
- rescue LoadError
6
- raise OxidizedError, 'sequel not found: sudo gem install sequel'
7
- end
2
+ class SQL < Source
3
+ begin
4
+ require 'sequel'
5
+ rescue LoadError
6
+ raise OxidizedError, 'sequel not found: sudo gem install sequel'
7
+ end
8
8
 
9
- def setup
10
- if @cfg.empty?
11
- Oxidized.asetus.user.source.sql.adapter = 'sqlite'
12
- Oxidized.asetus.user.source.sql.database = File.join(Config::Root, 'sqlite.db')
13
- Oxidized.asetus.user.source.sql.table = 'devices'
14
- Oxidized.asetus.user.source.sql.map.name = 'name'
15
- Oxidized.asetus.user.source.sql.map.model = 'rancid'
16
- Oxidized.asetus.save :user
17
- raise NoConfig, 'no source sql config, edit ~/.config/oxidized/config'
9
+ def setup
10
+ if @cfg.empty?
11
+ Oxidized.asetus.user.source.sql.adapter = 'sqlite'
12
+ Oxidized.asetus.user.source.sql.database = File.join(Config::Root, 'sqlite.db')
13
+ Oxidized.asetus.user.source.sql.table = 'devices'
14
+ Oxidized.asetus.user.source.sql.map.name = 'name'
15
+ Oxidized.asetus.user.source.sql.map.model = 'rancid'
16
+ Oxidized.asetus.save :user
17
+ raise NoConfig, 'no source sql config, edit ~/.config/oxidized/config'
18
+ end
18
19
  end
19
- end
20
20
 
21
- def load
22
- nodes = []
23
- db = connect
24
- query = db[@cfg.table.to_sym]
25
- query = query.with_sql(@cfg.query) if @cfg.query?
26
- query.each do |node|
27
- # map node parameters
28
- keys = {}
29
- @cfg.map.each { |key, sql_column| keys[key.to_sym] = node_var_interpolate node[sql_column.to_sym] }
30
- keys[:model] = map_model keys[:model] if keys.key? :model
31
-
32
- # map node specific vars
33
- vars = {}
34
- @cfg.vars_map.each do |key, sql_column|
35
- vars[key.to_sym] = node_var_interpolate node[sql_column.to_sym]
21
+ def load node_want = nil
22
+ nodes = []
23
+ db = connect
24
+ query = db[@cfg.table.to_sym]
25
+ query = query.with_sql(@cfg.query) if @cfg.query?
26
+
27
+ if node_want
28
+ query = query.where(@cfg.map.name.to_sym => node_want)
36
29
  end
37
- keys[:vars] = vars unless vars.empty?
38
30
 
39
- nodes << keys
31
+ query.each do |node|
32
+ # map node parameters
33
+ keys = {}
34
+ @cfg.map.each { |key, sql_column| keys[key.to_sym] = node_var_interpolate node[sql_column.to_sym] }
35
+ keys[:model] = map_model keys[:model] if keys.has_key? :model
36
+
37
+ # map node specific vars
38
+ vars = {}
39
+ @cfg.vars_map.each do |key, sql_column|
40
+ vars[key.to_sym] = node_var_interpolate node[sql_column.to_sym]
41
+ end
42
+ keys[:vars] = vars unless vars.empty?
43
+
44
+ nodes << keys
45
+ end
46
+ db.disconnect
47
+ nodes
40
48
  end
41
- db.disconnect
42
- nodes
43
- end
44
49
 
45
- private
50
+ private
46
51
 
47
- def initialize
48
- super
49
- @cfg = Oxidized.config.source.sql
50
- end
52
+ def initialize
53
+ super
54
+ @cfg = Oxidized.config.source.sql
55
+ end
51
56
 
52
- def connect
53
- Sequel.connect(:adapter => @cfg.adapter,
54
- :host => @cfg.host?,
55
- :user => @cfg.user?,
56
- :password => @cfg.password?,
57
- :database => @cfg.database)
58
- rescue Sequel::AdapterNotFound => error
59
- raise OxidizedError, "SQL adapter gem not installed: " + error.message
57
+ def connect
58
+ Sequel.connect(:adapter => @cfg.adapter,
59
+ :host => @cfg.host?,
60
+ :user => @cfg.user?,
61
+ :password => @cfg.password?,
62
+ :database => @cfg.database)
63
+ rescue Sequel::AdapterNotFound => error
64
+ raise OxidizedError, "SQL adapter gem not installed: " + error.message
65
+ end
60
66
  end
61
-
62
- end
63
67
  end
@@ -15,11 +15,11 @@ module Oxidized
15
15
 
16
16
  # sets @cmd and @name unless @name is already set
17
17
  def set_cmd command
18
- @cmd = command
19
- @name ||= @cmd.strip.gsub(/\s+/, '_')
18
+ @cmd = command
19
+ @name ||= @cmd.to_s.strip.gsub(/\s+/, '_') # what to do when command is proc? #to_s seems ghetto
20
20
  end
21
21
 
22
- def initialize str=''
22
+ def initialize str = ''
23
23
  super
24
24
  if str.class == Oxidized::String
25
25
  @cmd = str.cmd
@@ -27,6 +27,5 @@ module Oxidized
27
27
  @type = str.type
28
28
  end
29
29
  end
30
-
31
30
  end
32
31
  end