batali-wedge 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef69a6b06a756322f8df232ffc6a9c81333e1b09
4
- data.tar.gz: 8303ac1dd941339ae34de7211a73e81cf4ba1f92
3
+ metadata.gz: 64024acd8e0fb94d33b225a9cc7f94d72370aae6
4
+ data.tar.gz: 2f1d3e2e0769fd0e417b6e67928d1c52dd5498e3
5
5
  SHA512:
6
- metadata.gz: 6398b9b1a45bf3f9973dc210d22a66452fafc89157b9363e7d3aed6d187bdd395da49f4e2e96baa6d1c813af02c1a464248082e7b5fa63e87858d66f45e179b3
7
- data.tar.gz: f096fde169e4dec00a989c1ee39f9d6e1fa970472117de11d64b4edb57de8bc6cbba54c7aeb20629738afac7f74afb2bed9c3db7ab814f55c52a9fac3d35ad38
6
+ metadata.gz: 5653e53bda177ade9995fc2348eb85d6a8f9d1ece305d30d29077b5381d24e42ea42215c72499152f6f4766b92d333c24f7f73dd9e05d5db6faa1fcc8a98f6c1
7
+ data.tar.gz: ad7a959f9a0aa95598d0d273ed6981eddaaba5e0bdae9479b3fae92dc0a42c294f9e37c5332032beaa639165330bfe55b6c6562081aba4a7382a95c409935ebe
@@ -1,97 +1,93 @@
1
1
  require 'batali-wedge'
2
2
 
3
- module BataliWedge
4
- module Sync
3
+ class Chef::PolicyBuilder::ExpandNodeObject
5
4
 
6
- # Provide override to force Batali resolution
7
- def sync_cookbooks
8
- Chef::Log.debug("Synchronizing cookbooks")
5
+ # Provide override to force Batali resolution
6
+ def sync_cookbooks
7
+ Chef::Log.debug("Synchronizing cookbooks")
9
8
 
10
- begin
11
- events.cookbook_resolution_start(@expanded_run_list_with_versions)
12
- cookbook_hash = batali_cookbook_hash
9
+ begin
10
+ events.cookbook_resolution_start(@expanded_run_list_with_versions)
11
+ cookbook_hash = batali_cookbook_hash
13
12
 
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
13
+ rescue Exception => e
14
+ # TODO: wrap/munge exception to provide helpful error output
15
+ events.cookbook_resolution_failed(@expanded_run_list_with_versions, e)
16
+ raise
17
+ else
18
+ events.cookbook_resolution_complete(cookbook_hash)
19
+ end
21
20
 
22
- synchronizer = Chef::CookbookSynchronizer.new(cookbook_hash, events)
23
- if temporary_policy?
24
- synchronizer.remove_obsoleted_files = false
25
- end
26
- synchronizer.sync_cookbooks
21
+ synchronizer = Chef::CookbookSynchronizer.new(cookbook_hash, events)
22
+ if temporary_policy?
23
+ synchronizer.remove_obsoleted_files = false
24
+ end
25
+ synchronizer.sync_cookbooks
27
26
 
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")
27
+ # register the file cache path in the cookbook path so that CookbookLoader actually picks up the synced cookbooks
28
+ Chef::Config[:cookbook_path] = File.join(Chef::Config[:file_cache_path], "cookbooks")
30
29
 
31
- cookbook_hash
30
+ cookbook_hash
32
31
 
33
- end
32
+ end
34
33
 
35
- # Generate expected cookbook version hash
36
- #
37
- # @return [Hash]
38
- def batali_cookbook_hash
39
- Chef::Log.warn '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
- c_name = c_name.split('::').first
47
- if(c_version)
48
- constraints[c_name] = c_version
49
- elsif(constraints[c_name].nil?)
50
- constraints[c_name] = '> 0'
51
- end
34
+ # Generate expected cookbook version hash
35
+ #
36
+ # @return [Hash]
37
+ def batali_cookbook_hash
38
+ Chef::Log.warn 'Resolving cookbooks via Batali!'
39
+ system = batali_build_system
40
+ constraints = Smash[
41
+ api_service.get_rest("environments/#{node.chef_environment}").cookbook_versions.to_a
42
+ ]
43
+ @expanded_run_list_with_versions.each do |item|
44
+ c_name, c_version = item.split('@')
45
+ c_name = c_name.split('::').first
46
+ if(c_version)
47
+ constraints[c_name] = c_version
48
+ elsif(constraints[c_name].nil?)
49
+ constraints[c_name] = '> 0'
52
50
  end
53
- requirements = Grimoire::RequirementList.new(
54
- :name => :batali_resolv,
55
- :requirements => constraints.to_a
56
- )
57
- solver = Grimoire::Solver.new(
58
- :requirements => requirements,
59
- :system => system
60
- )
61
- results = solver.generate!
62
- solution = results.pop
63
- solution_output = solution.units.sort_by(&:name).map{|u| "#{u.name}<#{u.version}>"}.join(', ')
64
- Chef::Log.warn "Batali cookbook resolution: #{solution_output}"
65
- Hash[
66
- solution.units.map do |unit|
67
- [unit.name, api_service.get_rest("cookbooks/#{unit.name}/#{unit.version}")]
68
- end
69
- ]
70
51
  end
52
+ requirements = Grimoire::RequirementList.new(
53
+ :name => :batali_resolv,
54
+ :requirements => constraints.to_a
55
+ )
56
+ solver = Grimoire::Solver.new(
57
+ :requirements => requirements,
58
+ :system => system
59
+ )
60
+ results = solver.generate!
61
+ solution = results.pop
62
+ solution_output = solution.units.sort_by(&:name).map{|u| "#{u.name}<#{u.version}>"}.join(', ')
63
+ Chef::Log.warn "Batali cookbook resolution: #{solution_output}"
64
+ Hash[
65
+ solution.units.map do |unit|
66
+ [unit.name, api_service.get_rest("cookbooks/#{unit.name}/#{unit.version}")]
67
+ end
68
+ ]
69
+ end
71
70
 
72
- # Build the base system for generating solution
73
- #
74
- # @return [Grimoire::System]
75
- def batali_build_system
76
- system = Grimoire::System.new
77
- units = api_service.get_rest('cookbooks').map do |c_name, meta|
78
- meta['versions'].map do |info|
79
- "#{c_name}/#{info['version']}"
80
- end
81
- end.flatten.map do |ckbk|
82
- Batali::Unit.new(
83
- Smash.new(
84
- :name => ckbk.split('/').first,
85
- :version => ckbk.split('/').last,
86
- :dependencies => api_service.get_rest("cookbooks/#{ckbk}").metadata.dependencies.to_a
87
- )
88
- )
71
+ # Build the base system for generating solution
72
+ #
73
+ # @return [Grimoire::System]
74
+ def batali_build_system
75
+ system = Grimoire::System.new
76
+ units = api_service.get_rest('cookbooks').map do |c_name, meta|
77
+ meta['versions'].map do |info|
78
+ "#{c_name}/#{info['version']}"
89
79
  end
90
- system.add_unit(*units)
91
- system
80
+ end.flatten.map do |ckbk|
81
+ Batali::Unit.new(
82
+ Smash.new(
83
+ :name => ckbk.split('/').first,
84
+ :version => ckbk.split('/').last,
85
+ :dependencies => api_service.get_rest("cookbooks/#{ckbk}").metadata.dependencies.to_a
86
+ )
87
+ )
92
88
  end
93
-
89
+ system.add_unit(*units)
90
+ system
94
91
  end
95
- end
96
92
 
97
- Chef::PolicyBuilder::ExpandNodeObject.send(:include, BataliWedge::Sync)
93
+ end
@@ -1,3 +1,3 @@
1
1
  module BataliWedge
2
- VERSION = Gem::Version.new('0.0.2')
2
+ VERSION = Gem::Version.new('0.0.3')
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: batali-wedge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts