vcloud-core 0.0.13 → 0.1.0
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.
- data/CHANGELOG.md +8 -0
- data/lib/vcloud/core/config_loader.rb +13 -2
- data/lib/vcloud/core/version.rb +1 -1
- data/spec/vcloud/core/config_loader_spec.rb +43 -29
- data/spec/vcloud/core/data/working_template.yaml +22 -0
- data/spec/vcloud/core/data/working_variables.yaml +3 -0
- data/spec/vcloud/core/query_runner_spec.rb +1 -1
- data/vcloud-core.gemspec +1 -0
- metadata +23 -3
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 0.1.0 (2014-05-02)
|
2
|
+
|
3
|
+
Feature:
|
4
|
+
|
5
|
+
- Allow config files to be rendered from [Mustache](http://mustache.github.io/)
|
6
|
+
templates so that common configs can be re-used across environments with
|
7
|
+
differences represented as variables.
|
8
|
+
|
1
9
|
## 0.0.13 (2014-04-30)
|
2
10
|
|
3
11
|
Feature:
|
@@ -1,9 +1,19 @@
|
|
1
|
+
require 'mustache'
|
2
|
+
|
1
3
|
module Vcloud
|
2
4
|
module Core
|
3
5
|
class ConfigLoader
|
4
6
|
|
5
|
-
def load_config(config_file, schema = nil)
|
6
|
-
|
7
|
+
def load_config(config_file, schema = nil, vars_file = nil)
|
8
|
+
if vars_file
|
9
|
+
rendered_config = Mustache.render(
|
10
|
+
File.read(config_file),
|
11
|
+
YAML::load_file(vars_file)
|
12
|
+
)
|
13
|
+
input_config = YAML::load(rendered_config)
|
14
|
+
else
|
15
|
+
input_config = YAML::load_file(config_file)
|
16
|
+
end
|
7
17
|
|
8
18
|
# There is no way in YAML or Ruby to symbolize keys in a hash
|
9
19
|
json_string = JSON.generate(input_config)
|
@@ -18,6 +28,7 @@ module Vcloud
|
|
18
28
|
raise("Supplied configuration does not match supplied schema")
|
19
29
|
end
|
20
30
|
end
|
31
|
+
|
21
32
|
config
|
22
33
|
end
|
23
34
|
|
data/lib/vcloud/core/version.rb
CHANGED
@@ -8,41 +8,55 @@ module Vcloud
|
|
8
8
|
@data_dir = File.join(File.dirname(__FILE__), "/data")
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
describe 'basic config loading' do
|
12
|
+
it "should create a valid hash when input is JSON" do
|
13
|
+
input_file = "#{@data_dir}/working.json"
|
14
|
+
loader = ConfigLoader.new
|
15
|
+
actual_config = loader.load_config(input_file)
|
16
|
+
valid_config.should eq(actual_config)
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
it "should create a valid hash when input is YAML" do
|
20
|
+
input_file = "#{@data_dir}/working.yaml"
|
21
|
+
loader = ConfigLoader.new
|
22
|
+
actual_config = loader.load_config(input_file)
|
23
|
+
valid_config.should eq(actual_config)
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
it "should create a valid hash when input is YAML with anchor defaults" do
|
27
|
+
input_file = "#{@data_dir}/working_with_defaults.yaml"
|
28
|
+
loader = ConfigLoader.new
|
29
|
+
actual_config = loader.load_config(input_file)
|
30
|
+
valid_config['vapps'].should eq(actual_config['vapps'])
|
31
|
+
end
|
30
32
|
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
describe 'config loading with variable interpolation' do
|
35
|
+
it "should create a valid hash when input is YAML with variable file" do
|
36
|
+
input_file = "#{@data_dir}/working_template.yaml"
|
37
|
+
vars_file = "#{@data_dir}/working_variables.yaml"
|
38
|
+
loader = ConfigLoader.new
|
39
|
+
actual_config = loader.load_config(input_file, nil, vars_file)
|
40
|
+
valid_config.should eq(actual_config)
|
41
|
+
end
|
38
42
|
end
|
39
43
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
describe 'config loading with schema validation' do
|
45
|
+
it "should validate correctly against a schema" do
|
46
|
+
input_file = "#{@data_dir}/working_with_defaults.yaml"
|
47
|
+
loader = ConfigLoader.new
|
48
|
+
schema = vapp_config_schema
|
49
|
+
actual_config = loader.load_config(input_file, schema)
|
50
|
+
valid_config['vapps'].should eq(actual_config['vapps'])
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should raise an error if checked against an invalid schema" do
|
54
|
+
input_file = "#{@data_dir}/working_with_defaults.yaml"
|
55
|
+
loader = ConfigLoader.new
|
56
|
+
Vcloud::Core.logger.should_receive(:fatal).with("vapps: is not a hash")
|
57
|
+
expect { loader.load_config(input_file, invalid_schema) }.
|
58
|
+
to raise_error('Supplied configuration does not match supplied schema')
|
59
|
+
end
|
46
60
|
end
|
47
61
|
|
48
62
|
def vapp_config_schema
|
@@ -0,0 +1,22 @@
|
|
1
|
+
---
|
2
|
+
vapps:
|
3
|
+
- name: vapp-vcloud-tools-tests
|
4
|
+
vdc_name: VDC_NAME
|
5
|
+
catalog: CATALOG_NAME
|
6
|
+
catalog_item: CATALOG_ITEM
|
7
|
+
vm:
|
8
|
+
hardware_config:
|
9
|
+
memory: '4096'
|
10
|
+
cpu: '2'
|
11
|
+
extra_disks:
|
12
|
+
- size: '8192'
|
13
|
+
network_connections:
|
14
|
+
- name: Default
|
15
|
+
ip_address: {{ ip1 }}
|
16
|
+
- name: NetworkTest2
|
17
|
+
ip_address: {{ ip2 }}
|
18
|
+
bootstrap:
|
19
|
+
script_path: 'spec/data/basic_preamble_test.erb'
|
20
|
+
vars:
|
21
|
+
message: 'hello world'
|
22
|
+
metadata: {}
|
@@ -15,7 +15,7 @@ describe Vcloud::QueryRunner do
|
|
15
15
|
result.size.should == 0
|
16
16
|
end
|
17
17
|
|
18
|
-
it '
|
18
|
+
it 'returns queriable entity types provided by the API via :href link elements' do
|
19
19
|
@mock_fog_interface.stub(:get_execute_query).and_return(
|
20
20
|
{:Link => [
|
21
21
|
{:rel => 'down',
|
data/vcloud-core.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
|
25
25
|
s.add_runtime_dependency 'fog', '>= 1.22.0'
|
26
26
|
s.add_runtime_dependency 'methadone'
|
27
|
+
s.add_runtime_dependency 'mustache'
|
27
28
|
s.add_development_dependency 'aruba', '~> 0.5.3'
|
28
29
|
s.add_development_dependency 'cucumber', '~> 1.3.10'
|
29
30
|
s.add_development_dependency 'rake'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vcloud-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-05-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fog
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: mustache
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
46
62
|
- !ruby/object:Gem::Dependency
|
47
63
|
name: aruba
|
48
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -191,6 +207,8 @@ files:
|
|
191
207
|
- spec/vcloud/core/data/basic_preamble_test.erb.OUT
|
192
208
|
- spec/vcloud/core/data/working.json
|
193
209
|
- spec/vcloud/core/data/working.yaml
|
210
|
+
- spec/vcloud/core/data/working_template.yaml
|
211
|
+
- spec/vcloud/core/data/working_variables.yaml
|
194
212
|
- spec/vcloud/core/data/working_with_defaults.yaml
|
195
213
|
- spec/vcloud/core/edge_gateway_interface_spec.rb
|
196
214
|
- spec/vcloud/core/edge_gateway_spec.rb
|
@@ -227,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
245
|
version: '0'
|
228
246
|
segments:
|
229
247
|
- 0
|
230
|
-
hash:
|
248
|
+
hash: 339249452835220012
|
231
249
|
requirements: []
|
232
250
|
rubyforge_project:
|
233
251
|
rubygems_version: 1.8.23
|
@@ -248,6 +266,8 @@ test_files:
|
|
248
266
|
- spec/vcloud/core/data/basic_preamble_test.erb.OUT
|
249
267
|
- spec/vcloud/core/data/working.json
|
250
268
|
- spec/vcloud/core/data/working.yaml
|
269
|
+
- spec/vcloud/core/data/working_template.yaml
|
270
|
+
- spec/vcloud/core/data/working_variables.yaml
|
251
271
|
- spec/vcloud/core/data/working_with_defaults.yaml
|
252
272
|
- spec/vcloud/core/edge_gateway_interface_spec.rb
|
253
273
|
- spec/vcloud/core/edge_gateway_spec.rb
|