cmdb 3.0.0rc3 → 3.0.0rc4
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/Gemfile.lock +1 -1
- data/Rakefile +3 -2
- data/lib/cmdb.rb +18 -0
- data/lib/cmdb/commands/shell.rb +5 -3
- data/lib/cmdb/interface.rb +13 -9
- data/lib/cmdb/shell/dsl.rb +1 -1
- data/lib/cmdb/source/consul.rb +26 -3
- data/lib/cmdb/source/file.rb +1 -1
- data/lib/cmdb/source/network.rb +6 -11
- data/lib/cmdb/version.rb +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: c88c245ee9bc31f0fe4f261b3d688402b0f06be1
|
4
|
+
data.tar.gz: 0e6b981474487959202b1bc16a85e5411754c818
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a613be0d9de98744ba0b86d799d6f3685e46632a8d8373cb6ba1b1b473b326a26ce6b95912be9b60f31f5090ca2a883784fdf89d0e3362a9a5acbc6d15953887
|
7
|
+
data.tar.gz: 337b285e2ed120e8b543fe4cc0e1c9e0e1af759589aee4072c022bc76a793272b934185c12db54b2bd9860fe2a325c5c879423f4b38b45423f08ebde01d29b16
|
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -23,8 +23,9 @@ task :sandbox do
|
|
23
23
|
compose = Docker::Compose::Session.new
|
24
24
|
compose.up 'consul', detached:true
|
25
25
|
mapper = Docker::Compose::Mapper.new(compose)
|
26
|
-
|
26
|
+
source1 = mapper.map('consul://consul:8500/sandbox/apples')
|
27
|
+
source2 = mapper.map('consul://consul:8500/sandbox/oranges')
|
27
28
|
|
28
29
|
lib = File.expand_path('../lib', __FILE__)
|
29
|
-
exec "bin/shell --source=#{
|
30
|
+
exec "bin/shell --source=#{source1} --source=#{source2}"
|
30
31
|
end
|
data/lib/cmdb.rb
CHANGED
@@ -127,6 +127,24 @@ module CMDB
|
|
127
127
|
|
128
128
|
module_function
|
129
129
|
|
130
|
+
# Split a dotted-notation CMDB key into its constituent parts and return an
|
131
|
+
# Array. Optionally limit the amount of splitting done by passing parts > 0.
|
132
|
+
#
|
133
|
+
# @return [Array]
|
134
|
+
# @param [String] key dotted-notation key
|
135
|
+
# @param [Integer] parts number of total parts to return
|
136
|
+
def split(key, parts=0)
|
137
|
+
key.split(SEPARATOR, parts)
|
138
|
+
end
|
139
|
+
|
140
|
+
# Transform a list of key components into a dotted-notation key.
|
141
|
+
#
|
142
|
+
# @return [String]
|
143
|
+
def join(*pieces)
|
144
|
+
pieces.flatten!
|
145
|
+
pieces.join(SEPARATOR)
|
146
|
+
end
|
147
|
+
|
130
148
|
def log
|
131
149
|
unless @log
|
132
150
|
@log = Logger.new($stderr)
|
data/lib/cmdb/commands/shell.rb
CHANGED
@@ -72,6 +72,7 @@ cmdb shell
|
|
72
72
|
if subpath.include?(ALT_SEPARATOR) || subpath =~ NAVIGATION
|
73
73
|
# filesystem-like subpath
|
74
74
|
# apply Unix-style directory navigation shortcuts
|
75
|
+
# ge rid of successive //// and other oddities
|
75
76
|
pieces = subpath.split(ALT_SEPARATOR).select { |p| !p.nil? && !p.empty? }
|
76
77
|
pieces.each do |piece|
|
77
78
|
case piece
|
@@ -81,14 +82,15 @@ cmdb shell
|
|
81
82
|
end
|
82
83
|
end
|
83
84
|
|
84
|
-
|
85
|
+
CMDB.join(result)
|
85
86
|
else
|
86
|
-
pieces = subpath.split(CMDB::SEPARATOR).select { |p| !p.nil? && !p.empty? }
|
87
87
|
# standard dotted notation
|
88
|
+
# get rid of successive .... and other oddities
|
89
|
+
pieces = CMDB.split(subpath).select { |p| !p.nil? && !p.empty? }
|
88
90
|
result += pieces
|
89
91
|
end
|
90
92
|
|
91
|
-
|
93
|
+
CMDB.join(result)
|
92
94
|
end
|
93
95
|
|
94
96
|
private
|
data/lib/cmdb/interface.rb
CHANGED
@@ -48,19 +48,21 @@ module CMDB
|
|
48
48
|
|
49
49
|
# Set the value of a CMDB key.
|
50
50
|
#
|
51
|
-
# @return [Source,
|
51
|
+
# @return [Source,nil] the source that accepted the write, if any
|
52
52
|
# @raise [BadKey] if the key name is malformed
|
53
53
|
def set(key, value)
|
54
54
|
raise BadKey.new(key) unless key =~ VALID_KEY
|
55
55
|
|
56
|
-
|
56
|
+
wrote = nil
|
57
|
+
@sources.each do |s|
|
57
58
|
if s.respond_to?(:set)
|
58
|
-
s.set(key, value)
|
59
|
-
|
59
|
+
if s.set(key, value)
|
60
|
+
wrote = s
|
61
|
+
break
|
62
|
+
end
|
60
63
|
end
|
61
64
|
end
|
62
|
-
|
63
|
-
nil
|
65
|
+
wrote
|
64
66
|
end
|
65
67
|
|
66
68
|
# Enumerate all of the keys in the CMDB.
|
@@ -77,13 +79,15 @@ module CMDB
|
|
77
79
|
self
|
78
80
|
end
|
79
81
|
|
80
|
-
|
81
|
-
|
82
|
+
# @return [Hash] all keys/values that match query
|
83
|
+
# @param [String,Regexp] query key name prefix or pattern to search for
|
84
|
+
def search(query)
|
85
|
+
query = Regexp.new('^' + Regexp.escape(query)) unless query.is_a?(Regexp)
|
82
86
|
result = {}
|
83
87
|
|
84
88
|
@sources.each do |s|
|
85
89
|
s.each_pair do |k, v|
|
86
|
-
result[k] = v if k =~
|
90
|
+
result[k] = v if k =~ query
|
87
91
|
end
|
88
92
|
end
|
89
93
|
|
data/lib/cmdb/shell/dsl.rb
CHANGED
data/lib/cmdb/source/consul.rb
CHANGED
@@ -10,6 +10,9 @@ module CMDB
|
|
10
10
|
|
11
11
|
def initialize(uri, prefix)
|
12
12
|
super(uri, 8500, prefix)
|
13
|
+
useless = uri.path.split('/')
|
14
|
+
useless.shift ; useless.pop # del initial "" and final word (aka prefix)
|
15
|
+
@useless = CMDB.join(useless)
|
13
16
|
end
|
14
17
|
|
15
18
|
# Get a single key from consul. If the key is not found, return nil.
|
@@ -33,16 +36,26 @@ module CMDB
|
|
33
36
|
end
|
34
37
|
|
35
38
|
# Set a single key in consul. If value is nil, then delete the key
|
36
|
-
# entirely from consul.
|
39
|
+
# entirely from consul. If this source cannot accept the write due to
|
40
|
+
# key name limitations, return nil.
|
37
41
|
#
|
42
|
+
# @return [true,nil]
|
38
43
|
# @param [String] key dot-notation key
|
39
44
|
# @param [Object] value new value of key
|
45
|
+
# @raise [CMDB:Error] if the write fails atthe consul server
|
40
46
|
def set(key, value)
|
47
|
+
return nil unless prefixed?(key)
|
41
48
|
key = dot_to_slash(key)
|
42
49
|
if value.nil?
|
43
|
-
http_delete path_to(key)
|
50
|
+
status = http_delete path_to(key)
|
51
|
+
else
|
52
|
+
status = http_put path_to(key), value
|
53
|
+
end
|
54
|
+
|
55
|
+
if status >= 200 && status < 300
|
56
|
+
true
|
44
57
|
else
|
45
|
-
|
58
|
+
raise CMDB::Error.new("Consul put/delete failed with status #{status}")
|
46
59
|
end
|
47
60
|
end
|
48
61
|
|
@@ -64,6 +77,7 @@ module CMDB
|
|
64
77
|
|
65
78
|
result.each do |item|
|
66
79
|
key = slash_to_dot(item['Key'])
|
80
|
+
key.sub(@useless,'')
|
67
81
|
next unless item['Value']
|
68
82
|
value = json_parse(Base64.decode64(item['Value']))
|
69
83
|
yield(key, value)
|
@@ -89,5 +103,14 @@ module CMDB
|
|
89
103
|
def path_to(subpath)
|
90
104
|
::File.join('/v1/kv/', @uri.path, subpath)
|
91
105
|
end
|
106
|
+
|
107
|
+
# Transform a subpath into a key name. Account for base-path prefix if
|
108
|
+
# necessary.
|
109
|
+
def slash_to_dot(path)
|
110
|
+
dot = super
|
111
|
+
dot.sub!(@useless,'')
|
112
|
+
dot=dot[1..-1] if dot[0] == '.'
|
113
|
+
dot
|
114
|
+
end
|
92
115
|
end
|
93
116
|
end
|
data/lib/cmdb/source/file.rb
CHANGED
data/lib/cmdb/source/network.rb
CHANGED
@@ -99,24 +99,19 @@ module CMDB
|
|
99
99
|
end
|
100
100
|
|
101
101
|
# Convert dotted notation to slash-separated notation without an initial
|
102
|
-
# slash. Remove prefix if
|
103
|
-
# does not begin with this source's prefix.
|
102
|
+
# slash. Remove prefix if it is present in the dotted-notation key.
|
104
103
|
def dot_to_slash(key)
|
105
|
-
|
106
|
-
|
107
|
-
end
|
108
|
-
pieces = key.split(CMDB::SEPARATOR)
|
109
|
-
pieces.shift
|
104
|
+
pieces = CMDB.split(key)
|
105
|
+
pieces.shift if pieces[0] == @prefix
|
110
106
|
pieces.join('/')
|
111
107
|
end
|
112
108
|
|
113
|
-
# Convert a slash-separated URI path or subpath to dotted notation
|
114
|
-
#
|
109
|
+
# Convert a slash-separated URI path or subpath to dotted notation,
|
110
|
+
# discarding initial slash. Does not account for prefix in any way!
|
115
111
|
def slash_to_dot(path)
|
116
112
|
pieces = path.split('/')
|
117
113
|
pieces.shift if pieces[0].empty?
|
118
|
-
|
119
|
-
pieces.join(CMDB::SEPARATOR)
|
114
|
+
CMDB.join(pieces)
|
120
115
|
end
|
121
116
|
end
|
122
117
|
end
|
data/lib/cmdb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cmdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.0rc4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RightScale
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trollop
|