vagrant-confucius 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 02cab28e6cba35eba564bff0fdc81b3425328383
4
+ data.tar.gz: 7950a2039f2c863c5f98db4860f462a5e5de2696
5
+ SHA512:
6
+ metadata.gz: 0b5265475d2728b6488c2f37a807d7a00352c17d6148a8794b86fe5708367156ba9b0cb2abfe7006d2eacbd85fbd8760ab1d0c79ac7afacb84e6686b509474e6
7
+ data.tar.gz: 314d11ee51d4524a56c929afa6e28b5ea592f5dbdb52fddb13e008b8551215774df05d385d658e343558d70396133a033aa068529614ebb7ad473a05fb2fb2b7
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .tags*
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-confucius.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
8
+ end
9
+
10
+ group :plugins do
11
+ gem "vagrant-confucius", path: "."
12
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Kronos Technologies Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Simon Vigneux
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Vagrant::Confucius
2
+ --------------------
3
+
4
+ “To know that we know what we know, and that we do not know what we do not know, that is true knowledge."
5
+ ― [Confucius](https://www.wikipedia.org/wiki/Confucius)
6
+
7
+ Vagrant plugin to load vagrant boxes configurations from .yaml files
8
+
9
+
10
+ ## Installation
11
+
12
+ ```ruby
13
+ vagrant plugin install 'vagrant-confucius'
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```
19
+ options = Confucius::load!()
20
+ boxes = options['boxes'].sort_by { |vm, param| vm }
21
+ boxes.each do |name, box|
22
+ config.vm.define "#{name}" do |box_config|
23
+
24
+ #< use variable options to define your vms >
25
+
26
+ end
27
+ end
28
+ end
29
+ ```
30
+
31
+ > This is alpha code!
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+
40
+ To execute the plugin using your vagrant-files folder
41
+ ```ruby
42
+ bundle exec 'VAGRANT_CWD=<your vagrant folder> vagrant status'
43
+
44
+ # or
45
+ bin/test
46
+ ```
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kronostechnologies/vagrant-confucius
51
+
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+ Bundler::GemHelper.install_tasks
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vagrant/confucius"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/test ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ set -vx
4
+
5
+ bundle exec 'VAGRANT_CWD=~/kronos/vagrant-files/ vagrant status'
@@ -0,0 +1,52 @@
1
+ codebase: ~/kronos/
2
+ profile:
3
+ - dev
4
+ - www
5
+ - kt
6
+ - dsf
7
+ - ia
8
+
9
+ basebox:
10
+ jessie:
11
+ box: kronostechnologies/jessie
12
+ wheezy:
13
+ box: kronostechnologies/wheezy
14
+ trusty:
15
+ box: kronostechnologies/trusty
16
+ precise:
17
+ box: precise64-12.04.5-puppet362-1
18
+ url: http://repo.exp.prod.gest.kronos/vagrantbox/precise64-12.04.5-puppet362-1.box
19
+ centos:
20
+ box: kronostechnologies/centos6
21
+ centos7:
22
+ box: kronostechnologies/centos7
23
+ rhel7:
24
+ box: rhel-7.0-amd64-puppet362-1.box
25
+ url: http://repo.exp.prod.gest.kronos/vagrantbox/rhel-7.0-amd64-puppet362-1.box
26
+ rhel6:
27
+ box: rhel-6.6-amd64-puppet362-1.box
28
+ url: http://repo.exp.prod.gest.kronos/vagrantbox/rhel-6.6-amd64-puppet362-1.box
29
+ vyos:
30
+ box: kronostechnologies/vyos
31
+ guest: debian
32
+
33
+ params:
34
+ puppet_options: --verbose --waitforcert 30 --no-daemonize --onetime --configtimeout 600 --no-splay
35
+
36
+ boxes:
37
+ default:
38
+ order: 9999
39
+ params:
40
+ os: wheezy
41
+ providers:
42
+ gui: false
43
+ memory: 512
44
+ cpu: 2
45
+ provision:
46
+ source: remote
47
+ puppetmaster: auto.int.gest.mtl.kronos
48
+ environment: dev
49
+ network:
50
+ private:
51
+ eth1:
52
+ netmask: 255.254.0.0
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module Confucius
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,230 @@
1
+ # vim: set ai ft=ruby ts=2 sw=2 et!:
2
+ require "vagrant/confucius/version"
3
+
4
+ class ::Hash
5
+ def deep_merge(second)
6
+ merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
7
+ self.merge(second, &merger)
8
+ end
9
+
10
+ def deep_merge!(second)
11
+ second.each_pair do |k,v|
12
+ if self[k].is_a?(Hash) and second[k].is_a?(Hash)
13
+ self[k].deep_merge!(second[k])
14
+ else
15
+ self[k] = second[k]
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ # Supplement String type with sha sha256 checksum
22
+ class ::String
23
+ def sha256()
24
+ sha = Digest::SHA256.new
25
+ sha << self.to_s
26
+ return sha.hexdigest
27
+ end
28
+ end
29
+
30
+ # options (with box defaults and default profiles)
31
+ # profiles
32
+ # profiles' defaults
33
+ # user overrides
34
+ #
35
+
36
+ module Confucius
37
+
38
+ def self.load!()
39
+ global_options_file = '.confucius.yaml'
40
+ global_boxes_folder = 'boxes'
41
+ user_overrides_file = 'overrides'
42
+ profile = Profile.new(global_options_file, global_boxes_folder, user_overrides_file)
43
+ return profile.getOverridenProfiles()
44
+ end
45
+
46
+ class Profile #< Vagrant.plugin('2')
47
+ require 'yaml'
48
+ require 'digest'
49
+ require 'diskcached'
50
+ #require 'pp'
51
+
52
+ attr_reader :basedir, :config, :configFile, :overrideFile, :profiles, :boxes_folder
53
+
54
+ def checksum_dir(dir)
55
+ sha = Digest::SHA256.new
56
+ files = Dir["#{dir}/**/*"].select {|f| File.file? f }
57
+ for file in files
58
+ sha << File.mtime(file).to_s
59
+ end
60
+ return sha.hexdigest
61
+ end
62
+
63
+ def checksum_file(file)
64
+ return Digest::SHA256.file(file).hexdigest
65
+ end
66
+
67
+ def initialize(global_options_file, global_boxes_folder, user_overrides_file)
68
+ @basedir = "#{ENV['VAGRANT_CWD']}"
69
+ @configFile = File.join(basedir, global_options_file)
70
+ @boxes_folder = File.join(basedir, global_boxes_folder)
71
+ @overridesFile = File.join(basedir,user_overrides_file)
72
+
73
+ @diskcache = Diskcached.new('/tmp/cache', 86400, autogc=true)
74
+
75
+ begin
76
+ config_checksum = self.checksum_file(@configFile)
77
+ @config = @diskcache.get(config_checksum)
78
+ #puts 'config was cached'
79
+ rescue Diskcached::NotFound
80
+ #puts 'config is rebuilt'
81
+ @config = self.load_file(@configFile)
82
+ invalidate_cache = @diskcache.set(config_checksum, @config)
83
+ end
84
+
85
+ begin
86
+ overrides_checksum = self.checksum_file(@overridesFile)
87
+ @override = @diskcache.get(overrides_checksum)
88
+ #puts 'overrides was cached'
89
+ rescue Diskcached::NotFound
90
+ #puts 'overrides is rebuilt'
91
+ @override = self.load_file(@overridesFile)
92
+ invalidate_cache = @diskcache.set(overrides_checksum, @override)
93
+ end
94
+
95
+ begin
96
+ globalOverriden_checksum = "#{config_checksum}#{overrides_checksum}".sha256()
97
+ @globalOverriden = @diskcache.get(globalOverriden_checksum)
98
+ #puts 'globalOverriden was cached'
99
+ rescue Diskcached::NotFound
100
+ #puts 'globalOverriden is rebuilt'
101
+ @globalOverriden = self.conf_override(@config, @override)
102
+ invalidate_cache = @diskcache.set(globalOverriden_checksum, @globalOverriden)
103
+ end
104
+
105
+ begin
106
+ boxes_folder_checksum = self.checksum_dir(@boxes_folder)
107
+ @profiles = @diskcache.get(boxes_folder_checksum)
108
+ #puts 'boxes_folder was cached'
109
+ rescue Diskcached::NotFound
110
+ #puts 'boxes_folder is rebuilt'
111
+ @profiles = self.loadProfiles()
112
+ invalidate_cache = @diskcache.set(boxes_folder_checksum, @profiles)
113
+ end
114
+
115
+ # Let's invalidate the whole thing if not ok
116
+ if invalidate_cache
117
+ #puts 'invalidate_cache'
118
+ @diskcache.delete('overriden')
119
+ end
120
+ @overriden = @diskcache.cache('overriden') do
121
+ conf_override(@globalOverriden, @profiles)
122
+ end
123
+ end
124
+
125
+ def getOverridenProfiles()
126
+ overriden = @overriden
127
+ overriden['boxes'].tap { |box| box.delete('default') }
128
+ return overriden
129
+ end
130
+
131
+ def getProfiles()
132
+ return @profiles
133
+ end
134
+
135
+ def loadProfiles()
136
+ profiles = {}
137
+ Array(@globalOverriden['profile']).each { |profile|
138
+ file = File.join(@boxes_folder, "#{profile}.yaml")
139
+ profiles.deep_merge!(self.loadProfile(file))
140
+ }
141
+ begin
142
+
143
+ rescue
144
+ puts "Confucius ~ Profile not found: #{profile}"
145
+ exit
146
+ end
147
+ return profiles
148
+ end
149
+
150
+ # load profile and apply default box options to it
151
+ def loadProfile(file)
152
+ profile = self.load_file(file)
153
+ profile_with_defaults = applyDefaults(profile)
154
+ return config.deep_merge!(profile_with_defaults)
155
+ end
156
+
157
+ def parse_config()
158
+ # TODO: Create parser, check that config has the proper content.
159
+ end
160
+
161
+ def getOptions()
162
+ overriden = conf_override()
163
+ # Delete the 'default' box from the returned config...
164
+
165
+ return overriden
166
+ end
167
+
168
+ def load_file(file)
169
+ if File.exists?(file)
170
+ return YAML::load_file(file)
171
+ else
172
+ return {}
173
+ end
174
+ rescue
175
+ puts "Confucius ~ File not found: #{file}"
176
+ exit
177
+ end
178
+
179
+ def conf_override(conf, over)
180
+ if over == {}
181
+ return conf
182
+ else
183
+ begin
184
+ v = conf.deep_merge(over)
185
+ rescue
186
+ puts "Confucius ~ Could not merge config (#{conf}) with override (#{over}). Please make sure both files are proper yaml."
187
+ exit
188
+ end
189
+ return v
190
+ end
191
+
192
+ end
193
+
194
+ # if a default box exists, load it into profile
195
+ def applyDefaults(profile)
196
+ if @override.has_key?('boxes') and @override['boxes'].has_key?('default')
197
+ if profile.has_key?('boxes') and profile['boxes'].has_key?('default')
198
+ profile['boxes']['default'] = profile['boxes']['default'].deep_merge(@override['boxes']['default'])
199
+ else
200
+ profile['boxes']['default'] = @override['boxes']['default']
201
+ end
202
+ end
203
+
204
+ if @config.has_key?('boxes') and @config['boxes'].has_key?('default')
205
+ if profile['boxes'].has_key?('default')
206
+ default = @config['boxes']['default'].deep_merge(profile['boxes']['default'])
207
+ else
208
+ default = @config['boxes']['default']
209
+ end
210
+ else
211
+ if profile['boxes'].has_key?('default')
212
+ default = profile['boxes']['default']
213
+ else
214
+ default = { }
215
+ end
216
+ end
217
+
218
+ profile['boxes'].each do |key, box|
219
+ profile['boxes'][key] = default.deep_merge(box)
220
+ end
221
+
222
+ # cleanup default box
223
+ if profile['boxes'].has_key?('default')
224
+ profile['boxes'].tap { |box| box.delete('default') }
225
+ end
226
+ return profile
227
+ end
228
+ end
229
+
230
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant/confucius/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-confucius"
8
+ spec.version = Vagrant::Confucius::VERSION
9
+ spec.authors = ["Kronos Technologies Inc."]
10
+ spec.email = ["noreply@kronostechnologies.com"]
11
+ spec.summary = %q{Using yaml files to define vagrant boxes.}
12
+ spec.homepage = "https://github.com/kronostechnologies/vagrant-confucius/"
13
+ spec.license = "MIT"
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ #if spec.respond_to?(:metadata)
18
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
19
+ #else
20
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
21
+ #end
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.12"
29
+ spec.add_development_dependency "rake", "~> 11.0"
30
+ spec.add_dependency "diskcached"
31
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-confucius
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kronos Technologies Inc.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '11.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '11.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: diskcached
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - noreply@kronostechnologies.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - bin/test
71
+ - lib/vagrant/.options
72
+ - lib/vagrant/confucius.rb
73
+ - lib/vagrant/confucius/version.rb
74
+ - vagrant-confucius.gemspec
75
+ homepage: https://github.com/kronostechnologies/vagrant-confucius/
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Using yaml files to define vagrant boxes.
99
+ test_files: []