oxidized 0.21.0 → 0.22.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/no-response.yml +13 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +37 -0
- data/.rubocop_todo.yml +714 -0
- data/.travis.yml +7 -1
- data/CHANGELOG.md +341 -243
- data/Dockerfile +44 -16
- data/LICENSE +201 -0
- data/README.md +114 -82
- data/Rakefile +19 -0
- data/TODO.md +29 -23
- data/bin/oxidized +1 -2
- data/docs/Configuration.md +71 -31
- data/docs/Creating-Models.md +78 -0
- data/docs/Hooks.md +145 -41
- data/docs/Model-Notes/AireOS.md +12 -0
- data/docs/Model-Notes/ArbOS.md +12 -0
- data/docs/Model-Notes/Comware.md +14 -0
- data/docs/Model-Notes/EOS.md +9 -0
- data/docs/Model-Notes/JunOS.md +34 -0
- data/docs/Model-Notes/Netgear.md +68 -0
- data/docs/Model-Notes/README.md +19 -0
- data/docs/{VRP-Huawei.md → Model-Notes/VRP-Huawei.md} +10 -2
- data/docs/Model-Notes/XGS4600-Zyxel.md +39 -0
- data/docs/Outputs.md +27 -28
- data/docs/Ruby-API.md +38 -18
- data/docs/Sources.md +78 -16
- data/docs/Supported-OS-Types.md +171 -148
- data/extra/oxidized.logrotate +7 -0
- data/extra/oxidized.service +1 -1
- data/extra/rest_client.rb +4 -5
- data/extra/syslog.rb +16 -16
- data/lib/oxidized/cli.rb +3 -3
- data/lib/oxidized/config.rb +7 -4
- data/lib/oxidized/core.rb +3 -3
- data/lib/oxidized/hook.rb +64 -65
- data/lib/oxidized/hook/awssns.rb +2 -3
- data/lib/oxidized/hook/ciscosparkdiff.rb +49 -0
- data/lib/oxidized/hook/exec.rb +5 -5
- data/lib/oxidized/hook/githubrepo.rb +20 -14
- data/lib/oxidized/hook/slackdiff.rb +38 -19
- data/lib/oxidized/hook/xmppdiff.rb +58 -0
- data/lib/oxidized/input/cli.rb +5 -6
- data/lib/oxidized/input/ftp.rb +8 -7
- data/lib/oxidized/input/http.rb +39 -0
- data/lib/oxidized/input/ssh.rb +24 -22
- data/lib/oxidized/input/telnet.rb +38 -32
- data/lib/oxidized/jobs.rb +3 -4
- data/lib/oxidized/manager.rb +9 -4
- data/lib/oxidized/model/acos.rb +15 -16
- data/lib/oxidized/model/acsw.rb +3 -8
- data/lib/oxidized/model/aen.rb +1 -2
- data/lib/oxidized/model/aireos.rb +3 -5
- data/lib/oxidized/model/alteonos.rb +16 -18
- data/lib/oxidized/model/alvarion.rb +0 -4
- data/lib/oxidized/model/aos.rb +2 -4
- data/lib/oxidized/model/aos7.rb +2 -3
- data/lib/oxidized/model/aosw.rb +13 -15
- data/lib/oxidized/model/apc_aos.rb +0 -3
- data/lib/oxidized/model/arbos.rb +26 -0
- data/lib/oxidized/model/aricentiss.rb +51 -0
- data/lib/oxidized/model/asa.rb +33 -35
- data/lib/oxidized/model/asyncos.rb +41 -44
- data/lib/oxidized/model/audiocodes.rb +4 -8
- data/lib/oxidized/model/awplus.rb +84 -0
- data/lib/oxidized/model/boss.rb +6 -5
- data/lib/oxidized/model/br6910.rb +43 -45
- data/lib/oxidized/model/c4cmts.rb +3 -5
- data/lib/oxidized/model/cambium.rb +22 -0
- data/lib/oxidized/model/catos.rb +0 -2
- data/lib/oxidized/model/cisconga.rb +1 -3
- data/lib/oxidized/model/ciscosma.rb +37 -40
- data/lib/oxidized/model/ciscosmb.rb +7 -4
- data/lib/oxidized/model/comnetms.rb +43 -0
- data/lib/oxidized/model/comware.rb +9 -9
- data/lib/oxidized/model/coriant8600.rb +3 -5
- data/lib/oxidized/model/coriantgroove.rb +3 -5
- data/lib/oxidized/model/corianttmos.rb +1 -3
- data/lib/oxidized/model/cumulus.rb +26 -32
- data/lib/oxidized/model/datacom.rb +0 -2
- data/lib/oxidized/model/dcnos.rb +46 -0
- data/lib/oxidized/model/dlink.rb +1 -1
- data/lib/oxidized/model/dnos.rb +9 -5
- data/lib/oxidized/model/edgecos.rb +45 -0
- data/lib/oxidized/model/edgeos.rb +5 -3
- data/lib/oxidized/model/edgeswitch.rb +1 -3
- data/lib/oxidized/model/enterasys.rb +1 -3
- data/lib/oxidized/model/eos.rb +6 -8
- data/lib/oxidized/model/fabricos.rb +3 -5
- data/lib/oxidized/model/firewareos.rb +2 -5
- data/lib/oxidized/model/fortios.rb +21 -17
- data/lib/oxidized/model/ftos.rb +2 -4
- data/lib/oxidized/model/fujitsupy.rb +2 -4
- data/lib/oxidized/model/gaiaos.rb +6 -10
- data/lib/oxidized/model/gcombnps.rb +82 -0
- data/lib/oxidized/model/hatteras.rb +8 -5
- data/lib/oxidized/model/hirschmann.rb +8 -10
- data/lib/oxidized/model/hpebladesystem.rb +19 -17
- data/lib/oxidized/model/hpemsa.rb +0 -3
- data/lib/oxidized/model/ios.rb +54 -55
- data/lib/oxidized/model/iosxe.rb +5 -0
- data/lib/oxidized/model/iosxr.rb +1 -3
- data/lib/oxidized/model/ipos.rb +1 -3
- data/lib/oxidized/model/ironware.rb +12 -15
- data/lib/oxidized/model/isam.rb +4 -5
- data/lib/oxidized/model/junos.rb +8 -7
- data/lib/oxidized/model/masteros.rb +1 -3
- data/lib/oxidized/model/mlnxos.rb +3 -4
- data/lib/oxidized/model/model.rb +15 -7
- data/lib/oxidized/model/mtrlrfs.rb +1 -4
- data/lib/oxidized/model/ndms.rb +24 -0
- data/lib/oxidized/model/netgear.rb +3 -4
- data/lib/oxidized/model/netscaler.rb +0 -2
- data/lib/oxidized/model/nos.rb +1 -3
- data/lib/oxidized/model/nxos.rb +13 -3
- data/lib/oxidized/model/oneos.rb +6 -8
- data/lib/oxidized/model/openbsd.rb +76 -0
- data/lib/oxidized/model/opengear.rb +3 -5
- data/lib/oxidized/model/openwrt.rb +77 -0
- data/lib/oxidized/model/opnsense.rb +19 -0
- data/lib/oxidized/model/outputs.rb +1 -3
- data/lib/oxidized/model/panos.rb +1 -2
- data/lib/oxidized/model/pfsense.rb +9 -5
- data/lib/oxidized/model/planet.rb +8 -12
- data/lib/oxidized/model/powerconnect.rb +6 -9
- data/lib/oxidized/model/procurve.rb +18 -4
- data/lib/oxidized/model/quantaos.rb +3 -5
- data/lib/oxidized/model/routeros.rb +3 -2
- data/lib/oxidized/model/saos.rb +0 -1
- data/lib/oxidized/model/screenos.rb +3 -5
- data/lib/oxidized/model/sgos.rb +2 -3
- data/lib/oxidized/model/siklu.rb +0 -2
- data/lib/oxidized/model/slxos.rb +59 -0
- data/lib/oxidized/model/sros.rb +117 -0
- data/lib/oxidized/model/stoneos.rb +32 -0
- data/lib/oxidized/model/supermicro.rb +6 -41
- data/lib/oxidized/model/timos.rb +6 -114
- data/lib/oxidized/model/tmos.rb +1 -3
- data/lib/oxidized/model/tplink.rb +7 -11
- data/lib/oxidized/model/trango.rb +6 -7
- data/lib/oxidized/model/ucs.rb +0 -1
- data/lib/oxidized/model/voltaire.rb +3 -6
- data/lib/oxidized/model/voss.rb +1 -2
- data/lib/oxidized/model/vrp.rb +4 -5
- data/lib/oxidized/model/vyatta.rb +6 -4
- data/lib/oxidized/model/weos.rb +1 -3
- data/lib/oxidized/model/xos.rb +6 -5
- data/lib/oxidized/model/zhoneolt.rb +2 -2
- data/lib/oxidized/model/zynos.rb +1 -3
- data/lib/oxidized/model/zynoscli.rb +36 -0
- data/lib/oxidized/node.rb +11 -11
- data/lib/oxidized/node/stats.rb +15 -2
- data/lib/oxidized/nodes.rb +8 -8
- data/lib/oxidized/output/file.rb +41 -42
- data/lib/oxidized/output/git.rb +113 -115
- data/lib/oxidized/output/gitcrypt.rb +241 -242
- data/lib/oxidized/output/http.rb +23 -27
- data/lib/oxidized/output/output.rb +1 -2
- data/lib/oxidized/source/csv.rb +44 -45
- data/lib/oxidized/source/http.rb +52 -49
- data/lib/oxidized/source/source.rb +6 -7
- data/lib/oxidized/source/sql.rb +55 -51
- data/lib/oxidized/string.rb +3 -4
- data/lib/oxidized/version.rb +17 -1
- data/lib/oxidized/worker.rb +12 -3
- data/oxidized.gemspec +19 -13
- metadata +139 -51
- data/.ruby-version +0 -1
- data/Gemfile.lock +0 -44
data/lib/oxidized/output/http.rb
CHANGED
@@ -7,9 +7,9 @@ module Oxidized
|
|
7
7
|
|
8
8
|
def setup
|
9
9
|
if @cfg.empty?
|
10
|
-
CFGS.user.output.http.user
|
10
|
+
CFGS.user.output.http.user = 'Oxidized'
|
11
11
|
CFGS.user.output.http.pasword = 'secret'
|
12
|
-
CFGS.user.output.http.url
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
data/lib/oxidized/source/csv.rb
CHANGED
@@ -1,54 +1,53 @@
|
|
1
1
|
module Oxidized
|
2
|
-
class CSV < Source
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
18
|
+
require 'gpgme' if @cfg.gpg?
|
19
|
+
end
|
40
20
|
|
41
|
-
|
42
|
-
|
43
|
-
@cfg.
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
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
|
data/lib/oxidized/source/http.rb
CHANGED
@@ -1,64 +1,67 @@
|
|
1
1
|
module Oxidized
|
2
|
-
class HTTP < Source
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
14
|
+
require "net/http"
|
15
|
+
require "uri"
|
16
|
+
require "json"
|
35
17
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
data/lib/oxidized/source/sql.rb
CHANGED
@@ -1,63 +1,67 @@
|
|
1
1
|
module Oxidized
|
2
|
-
class SQL < Source
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
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
|
-
|
50
|
+
private
|
46
51
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
52
|
+
def initialize
|
53
|
+
super
|
54
|
+
@cfg = Oxidized.config.source.sql
|
55
|
+
end
|
51
56
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
data/lib/oxidized/string.rb
CHANGED
@@ -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
|
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
|