cmdb 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -0
- data/.travis.yml +5 -6
- data/Gemfile +1 -0
- data/README.md +68 -69
- data/Rakefile +4 -3
- data/lib/cmdb/commands/shell.rb +13 -9
- data/lib/cmdb/shell/dsl.rb +3 -6
- data/lib/cmdb/source/network.rb +2 -1
- data/lib/cmdb/version.rb +1 -1
- metadata +2 -4
- data/Gemfile.lock +0 -97
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ecbdd4ebf320cf1fb4dd3bc292bc70ef1a1b84e
|
4
|
+
data.tar.gz: 2e8049f2445a8fc0e5f6c9f247c3870f048f8d8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0220da2972161ea29bfc5ee28f99dc697542704dfeecf079d83803d7133a01f45cc6db8c586511a71c700808e9a4cf9bc308062990654f6da3b951947ec2f3af
|
7
|
+
data.tar.gz: 266f23c2e33c67a99bf66b2d856554e78ed9e2566c4a5d2e4cc12f4769a816bade0487f2639f83d5d041869b19c17456b896be1466dbef40868474157c8e766e
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
sudo:
|
1
|
+
sudo: required
|
2
|
+
dist: trusty
|
2
3
|
language: ruby
|
3
4
|
rvm:
|
4
5
|
- 2.1
|
5
|
-
|
6
|
+
- 2.3
|
6
7
|
before_install:
|
7
|
-
-
|
8
|
+
- sudo apt-get -y install python-pip && sudo pip install docker-compose && docker-compose -v
|
9
|
+
- gem install --no-document -v '~> 1.12' bundler
|
8
10
|
before_script:
|
9
11
|
- bundle install
|
10
|
-
script:
|
11
|
-
- bundle exec rake spec
|
12
|
-
- bundle exec rake cucumber
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# CMDB
|
2
2
|
|
3
|
-
[![TravisCI]
|
4
|
-
[travis_ci_img]: https://travis-ci.org/rightscale/cmdb.svg?branch=master
|
3
|
+
[![TravisCI](https://travis-ci.org/rightscale/cmdb.svg?branch=master)](https://travis-ci.org/rightscale/cmdb) [![Coverage](https://coveralls.io/repos/github/rightscale/cmdb/badge.svg?branch=master)](https://coveralls.io/github/rightscale/cmdb?branch=master)
|
5
4
|
|
6
5
|
CMDB is a Ruby interface for consuming data from one or more configuration management databases
|
7
6
|
(CMDBs) and making that information available to Web applications.
|
@@ -36,73 +35,6 @@ CMDB has three primary interfaces:
|
|
36
35
|
method transforms the whole configuration into an environment-friendly hash if you prefer to seed the
|
37
36
|
environment yourself, without using the shim.
|
38
37
|
|
39
|
-
# Data Model
|
40
|
-
|
41
|
-
CMDB models all data sources as trees whose nodes are named, and whose leaf
|
42
|
-
nodes can contain a piece of data: strings, numbers, booleans, or arrays.
|
43
|
-
|
44
|
-
Maps are disallowed on order to prevent ambiguity; a map always represents a
|
45
|
-
subtree of the k/v store, never a value. Mixed-type arrays are disallowed
|
46
|
-
because they can cause problems with strongly-typed languages. Nil is
|
47
|
-
disallowed as a value because writing nil means "delete the key."
|
48
|
-
|
49
|
-
Paths within a tree -- and therefore CMDB keys -- are identified using a dot
|
50
|
-
notation similar to Java properties; for instance, `production.http.listen_port`
|
51
|
-
might be an Integer-valued key that tells your microservice which HTTP port
|
52
|
-
to listen on in the production environment; `production.database.host` might be
|
53
|
-
the database host, and so forth. The names of keys are determined by the tree
|
54
|
-
structure of your k/v store, and when you set a key through CMDB, its position
|
55
|
-
in the tree is derived from its key name.
|
56
|
-
|
57
|
-
## Source Prefixes
|
58
|
-
|
59
|
-
CMDB sources have a `prefix`, meaning that _all_ keys contained in
|
60
|
-
that source begin with the same prefix. No two sources may share a prefix,
|
61
|
-
ensuring that sources don't "hide" each others' data. The prefix of a source is
|
62
|
-
usually automatically determined by the final component of its URL, e.g. the
|
63
|
-
filename in the case of `file://` sources and the final path component in the
|
64
|
-
case of `consul://` or other network sources.
|
65
|
-
|
66
|
-
## Inheritance
|
67
|
-
|
68
|
-
The uniqueness constraint on prefixes means that all sources' keys are
|
69
|
-
disjoint; there is no such thing as "inheritance" in the CMDB data model.
|
70
|
-
|
71
|
-
When keys are exported to the environment, the prefix is stripped from the
|
72
|
-
key name; however, CMDB _still_ prevents overlap in this case.
|
73
|
-
|
74
|
-
Inheritance may be supported in future as an optional behavior, but is omitted
|
75
|
-
for the time being because in practice, it causes more problems than it solves.
|
76
|
-
|
77
|
-
## Ambiguous Key Names
|
78
|
-
|
79
|
-
Consider a file that defines the following variables:
|
80
|
-
|
81
|
-
# confusing.yml
|
82
|
-
this:
|
83
|
-
is:
|
84
|
-
ambiguous
|
85
|
-
was:
|
86
|
-
very: ambiguous
|
87
|
-
extremely: confusing
|
88
|
-
|
89
|
-
At first glance, ths file defines two CMDB keys:
|
90
|
-
- `confusing.this.is` (a string)
|
91
|
-
- `confusing.this.was` (a map)
|
92
|
-
|
93
|
-
However, an equally valid interpretation would be:
|
94
|
-
- `confusing.this.is`
|
95
|
-
- `confusing.this.was.very`
|
96
|
-
- `confusing.this.was.extremely`
|
97
|
-
|
98
|
-
Because CMDB keys cannot contain maps, the first interpretation is wrong. The second
|
99
|
-
interpretation is valid according to the data model, but results in a situation where the type
|
100
|
-
of the keys could change if the structure of the YML file changes.
|
101
|
-
|
102
|
-
For this reason, any YAML file that defines an "ambiguous" key name will cause an error at
|
103
|
-
initialization time. To avoid ambiguous key names, think of your YAML file as a tree and remember
|
104
|
-
that _leaf nodes must define data_ and _internal nodes must define structure_.
|
105
|
-
|
106
38
|
# Getting Started
|
107
39
|
|
108
40
|
## Determine sources
|
@@ -247,3 +179,70 @@ located in `/var/lib/cmdb` and present it as a source whose prefix is `mykeys`.
|
|
247
179
|
JSON and YAML files are both supported. The structured data within each file
|
248
180
|
can contain arbitrarily-deep subtrees which are interpreted as subkeys,
|
249
181
|
sub-subkeys and so forth.
|
182
|
+
|
183
|
+
# Data Model
|
184
|
+
|
185
|
+
CMDB models all data sources as trees whose nodes are named, and whose leaf
|
186
|
+
nodes can contain a piece of data: strings, numbers, booleans, or arrays.
|
187
|
+
|
188
|
+
Maps are disallowed on order to prevent ambiguity; a map always represents a
|
189
|
+
subtree of the k/v store, never a value. Mixed-type arrays are disallowed
|
190
|
+
because they can cause problems with strongly-typed languages. Nil is
|
191
|
+
disallowed as a value because writing nil means "delete the key."
|
192
|
+
|
193
|
+
Paths within a tree -- and therefore CMDB keys -- are identified using a dot
|
194
|
+
notation similar to Java properties; for instance, `production.http.listen_port`
|
195
|
+
might be an Integer-valued key that tells your microservice which HTTP port
|
196
|
+
to listen on in the production environment; `production.database.host` might be
|
197
|
+
the database host, and so forth. The names of keys are determined by the tree
|
198
|
+
structure of your k/v store, and when you set a key through CMDB, its position
|
199
|
+
in the tree is derived from its key name.
|
200
|
+
|
201
|
+
## Source Prefixes
|
202
|
+
|
203
|
+
CMDB sources have a `prefix`, meaning that _all_ keys contained in
|
204
|
+
that source begin with the same prefix. No two sources may share a prefix,
|
205
|
+
ensuring that sources don't "hide" each others' data. The prefix of a source is
|
206
|
+
usually automatically determined by the final component of its URL, e.g. the
|
207
|
+
filename in the case of `file://` sources and the final path component in the
|
208
|
+
case of `consul://` or other network sources.
|
209
|
+
|
210
|
+
## Inheritance
|
211
|
+
|
212
|
+
The uniqueness constraint on prefixes means that all sources' keys are
|
213
|
+
disjoint; there is no such thing as "inheritance" in the CMDB data model.
|
214
|
+
|
215
|
+
When keys are exported to the environment, the prefix is stripped from the
|
216
|
+
key name; however, CMDB _still_ prevents overlap in this case.
|
217
|
+
|
218
|
+
Inheritance may be supported in future as an optional behavior, but is omitted
|
219
|
+
for the time being because in practice, it causes more problems than it solves.
|
220
|
+
|
221
|
+
## Ambiguous Key Names
|
222
|
+
|
223
|
+
Consider a file that defines the following variables:
|
224
|
+
|
225
|
+
# confusing.yml
|
226
|
+
this:
|
227
|
+
is:
|
228
|
+
ambiguous
|
229
|
+
was:
|
230
|
+
very: ambiguous
|
231
|
+
extremely: confusing
|
232
|
+
|
233
|
+
At first glance, ths file defines two CMDB keys:
|
234
|
+
- `confusing.this.is` (a string)
|
235
|
+
- `confusing.this.was` (a map)
|
236
|
+
|
237
|
+
However, an equally valid interpretation would be:
|
238
|
+
- `confusing.this.is`
|
239
|
+
- `confusing.this.was.very`
|
240
|
+
- `confusing.this.was.extremely`
|
241
|
+
|
242
|
+
Because CMDB keys cannot contain maps, the first interpretation is wrong. The second
|
243
|
+
interpretation is valid according to the data model, but results in a situation where the type
|
244
|
+
of the keys could change if the structure of the YML file changes.
|
245
|
+
|
246
|
+
For this reason, any YAML file that defines an "ambiguous" key name will cause an error at
|
247
|
+
initialization time. To avoid ambiguous key names, think of your YAML file as a tree and remember
|
248
|
+
that _leaf nodes must define data_ and _internal nodes must define structure_.
|
data/Rakefile
CHANGED
@@ -14,7 +14,10 @@ require 'rspec/core'
|
|
14
14
|
require 'rspec/core/rake_task'
|
15
15
|
RSpec::Core::RakeTask.new(:spec)
|
16
16
|
|
17
|
-
task
|
17
|
+
require 'coveralls/rake/task'
|
18
|
+
Coveralls::RakeTask.new
|
19
|
+
|
20
|
+
task default: [:spec, :cucumber, 'coveralls:push']
|
18
21
|
|
19
22
|
|
20
23
|
require 'docker/compose'
|
@@ -25,7 +28,5 @@ task :sandbox do
|
|
25
28
|
mapper = Docker::Compose::Mapper.new(compose)
|
26
29
|
source1 = mapper.map('consul://consul:8500/sandbox/apples')
|
27
30
|
source2 = mapper.map('consul://consul:8500/sandbox/oranges')
|
28
|
-
|
29
|
-
lib = File.expand_path('../lib', __FILE__)
|
30
31
|
exec "bin/shell --source=#{source1} --source=#{source2}"
|
31
32
|
end
|
data/lib/cmdb/commands/shell.rb
CHANGED
@@ -103,12 +103,18 @@ cmdb shell
|
|
103
103
|
words = line.split(/\s+/)
|
104
104
|
command, args = words.first.to_sym, words[1..-1]
|
105
105
|
|
106
|
-
|
107
|
-
|
106
|
+
exception = nil
|
107
|
+
begin
|
108
|
+
run_ruby(command, args)
|
109
|
+
rescue CMDB::BadCommand => e
|
110
|
+
exception = e
|
111
|
+
end
|
112
|
+
|
113
|
+
# deferred raise after trying getter and setter shortcuts
|
114
|
+
raise exception if exception && !(run_setter(line) || run_getter(line))
|
115
|
+
|
108
116
|
handle_output(self._)
|
109
|
-
rescue SystemCallError => e
|
110
|
-
handle_error(e) || raise
|
111
|
-
rescue => e
|
117
|
+
rescue StandardError, SystemCallError => e
|
112
118
|
handle_error(e) || raise
|
113
119
|
end
|
114
120
|
end
|
@@ -120,10 +126,8 @@ cmdb shell
|
|
120
126
|
def run_ruby(command, args)
|
121
127
|
self._ = @dsl.__send__(command, *args)
|
122
128
|
true
|
123
|
-
rescue
|
124
|
-
|
125
|
-
rescue ArgumentError => e
|
126
|
-
raise CMDB::BadCommand.new(e.message, command)
|
129
|
+
rescue ArgumentError, NoMethodError => e
|
130
|
+
raise CMDB::BadCommand.new(command, e.message)
|
127
131
|
end
|
128
132
|
|
129
133
|
# @return [Boolean] true if line was handled as a getter
|
data/lib/cmdb/shell/dsl.rb
CHANGED
@@ -14,10 +14,6 @@ module CMDB::Shell
|
|
14
14
|
DSL
|
15
15
|
end
|
16
16
|
|
17
|
-
def method_missing(meth, *args)
|
18
|
-
::Kernel.raise ::CMDB::BadCommand.new(meth)
|
19
|
-
end
|
20
|
-
|
21
17
|
def ls(path='')
|
22
18
|
prefix = @shell.expand_path(path)
|
23
19
|
@cmdb.search prefix
|
@@ -54,18 +50,19 @@ module CMDB::Shell
|
|
54
50
|
if @cmdb.set(key, value)
|
55
51
|
@cmdb.get(key)
|
56
52
|
else
|
57
|
-
::Kernel.raise ::CMDB::BadCommand.new('set',
|
53
|
+
::Kernel.raise ::CMDB::BadCommand.new('set', "No source accepts writes for '#{::CMDB.split(key).first}'")
|
58
54
|
end
|
59
55
|
end
|
60
56
|
|
61
57
|
def unset(key)
|
62
58
|
@cmdb.set(key, nil)
|
59
|
+
@cmdb.get(key)
|
63
60
|
end
|
64
61
|
alias rm unset
|
65
62
|
|
66
63
|
def cd(path)
|
67
64
|
pwd = @shell.expand_path(path)
|
68
|
-
@shell.pwd = CMDB.split(pwd)
|
65
|
+
@shell.pwd = ::CMDB.split(pwd)
|
69
66
|
pwd.to_sym
|
70
67
|
end
|
71
68
|
alias chdir cd
|
data/lib/cmdb/source/network.rb
CHANGED
@@ -74,10 +74,11 @@ module CMDB
|
|
74
74
|
#
|
75
75
|
# @return [Integer] HTTP status code
|
76
76
|
# @param [String] path
|
77
|
-
def http_delete(path)
|
77
|
+
def http_delete(path, query:nil)
|
78
78
|
@http ||= Net::HTTP.start(@http_url.host, @http_url.port)
|
79
79
|
url = @http_url.dup
|
80
80
|
url.path = path
|
81
|
+
url.query = query unless query.nil? || query.empty?
|
81
82
|
|
82
83
|
request = Net::HTTP::Delete.new url
|
83
84
|
response = @http.request request
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RightScale
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trollop
|
@@ -54,7 +54,6 @@ files:
|
|
54
54
|
- CHANGELOG.md
|
55
55
|
- Dockerfile
|
56
56
|
- Gemfile
|
57
|
-
- Gemfile.lock
|
58
57
|
- LICENSE
|
59
58
|
- README.md
|
60
59
|
- Rakefile
|
@@ -112,4 +111,3 @@ signing_key:
|
|
112
111
|
specification_version: 4
|
113
112
|
summary: Command-line tool for configuration manegement databases
|
114
113
|
test_files: []
|
115
|
-
has_rdoc:
|
data/Gemfile.lock
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
cmdb (3.0.0)
|
5
|
-
trollop (~> 2.0)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
addressable (2.4.0)
|
11
|
-
ast (2.2.0)
|
12
|
-
backticks (1.0.0rc1)
|
13
|
-
builder (3.2.2)
|
14
|
-
byebug (8.2.2)
|
15
|
-
coderay (1.1.1)
|
16
|
-
crack (0.4.3)
|
17
|
-
safe_yaml (~> 1.0.0)
|
18
|
-
cucumber (2.3.2)
|
19
|
-
builder (>= 2.1.2)
|
20
|
-
cucumber-core (~> 1.4.0)
|
21
|
-
cucumber-wire (~> 0.0.1)
|
22
|
-
diff-lcs (>= 1.1.3)
|
23
|
-
gherkin (~> 3.2.0)
|
24
|
-
multi_json (>= 1.7.5, < 2.0)
|
25
|
-
multi_test (>= 0.1.2)
|
26
|
-
cucumber-core (1.4.0)
|
27
|
-
gherkin (~> 3.2.0)
|
28
|
-
cucumber-wire (0.0.1)
|
29
|
-
diff-lcs (1.2.5)
|
30
|
-
docker-compose (1.0.0rc2)
|
31
|
-
backticks (>= 1.0.0rc1)
|
32
|
-
gherkin (3.2.0)
|
33
|
-
hashdiff (0.3.0)
|
34
|
-
method_source (0.8.2)
|
35
|
-
multi_json (1.11.2)
|
36
|
-
multi_test (0.1.2)
|
37
|
-
parser (2.3.0.6)
|
38
|
-
ast (~> 2.2)
|
39
|
-
powerpack (0.1.1)
|
40
|
-
pry (0.10.3)
|
41
|
-
coderay (~> 1.1.0)
|
42
|
-
method_source (~> 0.8.1)
|
43
|
-
slop (~> 3.4)
|
44
|
-
pry-byebug (3.3.0)
|
45
|
-
byebug (~> 8.0)
|
46
|
-
pry (~> 0.10)
|
47
|
-
rainbow (2.1.0)
|
48
|
-
rake (10.5.0)
|
49
|
-
rspec (3.4.0)
|
50
|
-
rspec-core (~> 3.4.0)
|
51
|
-
rspec-expectations (~> 3.4.0)
|
52
|
-
rspec-mocks (~> 3.4.0)
|
53
|
-
rspec-core (3.4.3)
|
54
|
-
rspec-support (~> 3.4.0)
|
55
|
-
rspec-expectations (3.4.0)
|
56
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
57
|
-
rspec-support (~> 3.4.0)
|
58
|
-
rspec-mocks (3.4.1)
|
59
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
60
|
-
rspec-support (~> 3.4.0)
|
61
|
-
rspec-support (3.4.1)
|
62
|
-
rubocop (0.37.2)
|
63
|
-
parser (>= 2.3.0.4, < 3.0)
|
64
|
-
powerpack (~> 0.1)
|
65
|
-
rainbow (>= 1.99.1, < 3.0)
|
66
|
-
ruby-progressbar (~> 1.7)
|
67
|
-
unicode-display_width (~> 0.3)
|
68
|
-
ruby-progressbar (1.7.5)
|
69
|
-
safe_yaml (1.0.4)
|
70
|
-
slop (3.6.0)
|
71
|
-
trollop (2.1.2)
|
72
|
-
unicode-display_width (0.3.1)
|
73
|
-
webmock (1.24.1)
|
74
|
-
addressable (>= 2.3.6)
|
75
|
-
crack (>= 0.3.2)
|
76
|
-
hashdiff
|
77
|
-
yard (0.8.7.6)
|
78
|
-
|
79
|
-
PLATFORMS
|
80
|
-
ruby
|
81
|
-
|
82
|
-
DEPENDENCIES
|
83
|
-
backticks (= 1.0.0rc1)
|
84
|
-
bundler (~> 1.10)
|
85
|
-
cmdb!
|
86
|
-
cucumber
|
87
|
-
docker-compose (= 1.0.0rc2)
|
88
|
-
pry
|
89
|
-
pry-byebug
|
90
|
-
rake
|
91
|
-
rspec
|
92
|
-
rubocop
|
93
|
-
webmock
|
94
|
-
yard
|
95
|
-
|
96
|
-
BUNDLED WITH
|
97
|
-
1.11.2
|