bosher 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +1 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/bin/bosher +16 -0
- data/bosher.gemspec +25 -0
- data/lib/bosher/bosher.rb +61 -0
- data/lib/bosher/version.rb +3 -0
- data/lib/bosher.rb +1 -0
- data/sandbox/Gemfile +5 -0
- data/spec/bosher_spec.rb +47 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d420c3c7a89275b18c496bb1cda9865af86c68d1
|
4
|
+
data.tar.gz: 0f2ce3282c3101d80eba4144c2ebd0265b491fa7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dd08a9cac8c655c1d9b39e9fa30463cf7ebc2734b541a75da50aa541275977b2b01511b933188fc8c7121f479f2a8eb0a50287ceb88052011062e9ce1ab129d7
|
7
|
+
data.tar.gz: 3aa4a71b948987fe288a9115178e8bc9731a6f5c496668b32ac97fe07246050057109793baa1632f4d28aa6c86b5ddc39ad44ea225354b2757e5600394fc6cc5
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Luan Santos and Serguei Filimonov
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Bosher
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'bosher'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install bosher
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/bosher/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/bosher
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'bosher'
|
5
|
+
|
6
|
+
unless ARGV.any?
|
7
|
+
puts "Usage: bosher manifest, spec, template, job_name"
|
8
|
+
exit 0
|
9
|
+
end
|
10
|
+
|
11
|
+
puts Bosher::Bosher.new.bosh(
|
12
|
+
YAML.load_file(ARGV[0]),
|
13
|
+
YAML.load_file(ARGV[1]),
|
14
|
+
IO.read(ARGV[2]),
|
15
|
+
ARGV[3]
|
16
|
+
)
|
data/bosher.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bosher/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bosher"
|
8
|
+
spec.version = Bosher::VERSION
|
9
|
+
spec.authors = ["Luan Santos and Serguei Filimonov"]
|
10
|
+
spec.email = ["pair+luan+sfilimonov@pivotallabs.com"]
|
11
|
+
spec.summary = %q{bosh simulator}
|
12
|
+
spec.description = %q{simulates bosh template writing}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activesupport"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'yaml'
|
4
|
+
require 'active_support/core_ext'
|
5
|
+
|
6
|
+
module Bosher
|
7
|
+
class Bosher
|
8
|
+
class ErbalT < OpenStruct
|
9
|
+
def render(template)
|
10
|
+
ERB.new(template).result(binding)
|
11
|
+
end
|
12
|
+
|
13
|
+
def p(key)
|
14
|
+
key.split('.').reduce(self) do |memo, k|
|
15
|
+
memo[k]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def spec
|
20
|
+
OpenStruct.new(networks: OpenStruct.new({
|
21
|
+
default: OpenStruct.new(
|
22
|
+
ip: "13.17.19.23",
|
23
|
+
dns: ["13.17.19.29", "13.17.19.31"],
|
24
|
+
)
|
25
|
+
}))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def bosh(manifest, spec, template, job_name)
|
30
|
+
spec_defaults = spec_defaults(spec)
|
31
|
+
defaults = nestify(spec_defaults)
|
32
|
+
ErbalT.new(defaults.deep_merge(properties(manifest, job_name))).render(template)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def nestify(hsh)
|
38
|
+
if hsh.keys.size == 1 && hsh.keys.first.empty?
|
39
|
+
return hsh.values.first
|
40
|
+
end
|
41
|
+
hsh.reduce({}) do |memo, kv|
|
42
|
+
parts = kv[0].split('.')
|
43
|
+
key = parts[0]
|
44
|
+
value = kv[1]
|
45
|
+
memo.deep_merge({key => nestify(parts.drop(1).join('.') => value)})
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def spec_defaults(spec)
|
50
|
+
spec['properties'].reduce({}) do |memo, kv|
|
51
|
+
memo.merge({kv[0] => kv[1]['default']})
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def properties(manifest, job_name)
|
56
|
+
manifest['jobs'].detect do |job|
|
57
|
+
job['name'] == job_name
|
58
|
+
end['properties']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/bosher.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.dirname(__FILE__) + "/**/*.rb"].each(&method(:require))
|
data/sandbox/Gemfile
ADDED
data/spec/bosher_spec.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'yaml'
|
3
|
+
require_relative '../lib/bosher/bosher'
|
4
|
+
|
5
|
+
describe 'bosher' do
|
6
|
+
it 'works with manifest, spec, template' do
|
7
|
+
manifest = YAML.load(<<MANIFEST)
|
8
|
+
---
|
9
|
+
jobs:
|
10
|
+
- name: the-job
|
11
|
+
properties:
|
12
|
+
property1: 7
|
13
|
+
bosh:
|
14
|
+
dns: [8.8.8.8]
|
15
|
+
MANIFEST
|
16
|
+
spec = YAML.load(<<SPEC)
|
17
|
+
---
|
18
|
+
properties:
|
19
|
+
property1:
|
20
|
+
description: whatever
|
21
|
+
property2:
|
22
|
+
default: three
|
23
|
+
bosh.dns:
|
24
|
+
default: [7.7.7.7]
|
25
|
+
bosh.fns:
|
26
|
+
default: [6.6.6.6]
|
27
|
+
SPEC
|
28
|
+
template = <<TEMPLATE
|
29
|
+
<%= p('property1') %>
|
30
|
+
<%= p('property2') %>
|
31
|
+
<%= spec.networks.default.ip %>
|
32
|
+
<%= spec.networks.default.dns %>
|
33
|
+
<%= p('bosh.dns') %>
|
34
|
+
<%= p('bosh.fns') %>
|
35
|
+
TEMPLATE
|
36
|
+
|
37
|
+
asset = Bosher::Bosher.new.bosh manifest, spec, template, 'the-job'
|
38
|
+
asset.should == <<ASSET
|
39
|
+
7
|
40
|
+
three
|
41
|
+
13.17.19.23
|
42
|
+
["13.17.19.29", "13.17.19.31"]
|
43
|
+
["8.8.8.8"]
|
44
|
+
["6.6.6.6"]
|
45
|
+
ASSET
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bosher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Luan Santos and Serguei Filimonov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: simulates bosh template writing
|
70
|
+
email:
|
71
|
+
- pair+luan+sfilimonov@pivotallabs.com
|
72
|
+
executables:
|
73
|
+
- bosher
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/bosher
|
84
|
+
- bosher.gemspec
|
85
|
+
- lib/bosher.rb
|
86
|
+
- lib/bosher/bosher.rb
|
87
|
+
- lib/bosher/version.rb
|
88
|
+
- sandbox/Gemfile
|
89
|
+
- spec/bosher_spec.rb
|
90
|
+
homepage: ''
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.2.2
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: bosh simulator
|
114
|
+
test_files:
|
115
|
+
- spec/bosher_spec.rb
|
116
|
+
has_rdoc:
|