batali-wedge 0.0.1

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: 46ed9b345a1867c08fdc12e4cdd669c8d34bfbfa
4
+ data.tar.gz: db30d18b5ec9ca2baad55d4a19846165ed2cc535
5
+ SHA512:
6
+ metadata.gz: c836e221969b0014ecf1df910dc6517cbfca54598125ed9797c931113060a29bed3dfa45387153f46ad899ffd45071bca8d76900785a515a7629cae6fc0fe7ba
7
+ data.tar.gz: 4088261f00526d61d37760e2eb9063f3e45c1beb99121270630cb60662a6071df7e595800de646246489a6a1099c18d14f4b3d8233e7d78b818017642c62842e
data/CHANGELOG.md ADDED
File without changes
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2015 Chris Roberts
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
File without changes
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + '/lib/'
2
+ require 'batali-wedge/version'
3
+ Gem::Specification.new do |s|
4
+ s.name = 'batali-wedge'
5
+ s.version = BataliWedge::VERSION.version
6
+ s.summary = 'Magic wedger'
7
+ s.author = 'Chris Roberts'
8
+ s.email = 'code@chrisroberts.org'
9
+ s.homepage = 'https://github.com/hw-labs/batali-wedge'
10
+ s.description = 'Wedge magic into Chef'
11
+ s.require_path = 'lib'
12
+ s.license = 'Apache 2.0'
13
+ s.add_runtime_dependency 'batali'
14
+ s.files = Dir['{lib}/**/**/*'] + %w(batali-wedge.gemspec README.md CHANGELOG.md LICENSE)
15
+ end
@@ -0,0 +1,92 @@
1
+ require 'batali-wedge'
2
+
3
+ module BataliWedge
4
+ module Sync
5
+
6
+ # Provide override to force Batali resolution
7
+ def sync_cookbooks
8
+ Chef::Log.debug("Synchronizing cookbooks")
9
+
10
+ begin
11
+ events.cookbook_resolution_start(@expanded_run_list_with_versions)
12
+ cookbook_hash = batali_cookbook_hash
13
+
14
+ rescue Exception => e
15
+ # TODO: wrap/munge exception to provide helpful error output
16
+ events.cookbook_resolution_failed(@expanded_run_list_with_versions, e)
17
+ raise
18
+ else
19
+ events.cookbook_resolution_complete(cookbook_hash)
20
+ end
21
+
22
+ synchronizer = Chef::CookbookSynchronizer.new(cookbook_hash, events)
23
+ if temporary_policy?
24
+ synchronizer.remove_obsoleted_files = false
25
+ end
26
+ synchronizer.sync_cookbooks
27
+
28
+ # register the file cache path in the cookbook path so that CookbookLoader actually picks up the synced cookbooks
29
+ Chef::Config[:cookbook_path] = File.join(Chef::Config[:file_cache_path], "cookbooks")
30
+
31
+ cookbook_hash
32
+
33
+ end
34
+
35
+ # Generate expected cookbook version hash
36
+ #
37
+ # @return [Hash]
38
+ def batali_cookbook_hash
39
+ Chef::Log.info 'Resolving cookbooks via Batali!'
40
+ system = batali_build_system
41
+ constraints = Smash[
42
+ api_service.get_rest("environments/#{node.chef_environment}").cookbook_versions.to_a
43
+ ]
44
+ @expanded_run_list_with_versions.each do |item|
45
+ c_name, c_version = item.split('@')
46
+ if(c_version)
47
+ constraints[c_name] = c_version
48
+ end
49
+ end
50
+ requirements = Grimoire::RequirementList.new(
51
+ :name => :batali_resolv,
52
+ :requirements => constraints.to_a
53
+ )
54
+ solver = Grimoire::Solver.new(
55
+ :requirements => requirements,
56
+ :system => system
57
+ )
58
+ results = solver.generate!
59
+ solution = results.pop
60
+ solution_output = solution.sort_by(&:name).map{|u| "#{u.name}<#{u.version}>"}.join(', ')
61
+ Chef::Log.info "Batali cookbook resolution: #{solution_output}"
62
+ Hash[
63
+ solution.units.map do |unit|
64
+ [unit.name, api_service.get_rest("cookbooks/#{unit.name}/#{unit.version}")]
65
+ end
66
+ ]
67
+ end
68
+
69
+ # Build the base system for generating solution
70
+ #
71
+ # @return [Grimoire::System]
72
+ def batali_build_system
73
+ system = Grimoire::System.new
74
+ units = api_service.get_rest('cookbooks').map do |c_name, meta|
75
+ meta['versions'].map do |info|
76
+ "#{c_name}/#{info['version']}"
77
+ end
78
+ end.map do |ckbk|
79
+ Smash.new(
80
+ :name => ckbk.split('/').first,
81
+ :version => ckbk.split('/').last,
82
+ :dependencies => api_service.get_rest("cookbooks/#{ckbk}").metadata.dependencies.to_a
83
+ )
84
+ end
85
+ system.add_units(units)
86
+ system
87
+ end
88
+
89
+ end
90
+ end
91
+
92
+ Chef::PolicyBuilder::ExpandNodeObject.send(:include, BataliWedge::Sync)
@@ -0,0 +1,3 @@
1
+ module BataliWedge
2
+ VERSION = Gem::Version.new('0.0.1')
3
+ end
@@ -0,0 +1,2 @@
1
+ require 'batali'
2
+ require 'batali-wedge/version'
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: batali-wedge
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Roberts
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: batali
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
+ description: Wedge magic into Chef
28
+ email: code@chrisroberts.org
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - CHANGELOG.md
34
+ - LICENSE
35
+ - README.md
36
+ - batali-wedge.gemspec
37
+ - lib/batali-wedge.rb
38
+ - lib/batali-wedge/sync.rb
39
+ - lib/batali-wedge/version.rb
40
+ homepage: https://github.com/hw-labs/batali-wedge
41
+ licenses:
42
+ - Apache 2.0
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.2.2
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Magic wedger
64
+ test_files: []
65
+ has_rdoc: