Class: Vagabond::InternalConfiguration
- Inherits:
-
Object
- Object
- Vagabond::InternalConfiguration
- Includes:
- Helpers
- Defined in:
- lib/vagabond/internal_configuration.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#ui ⇒ Object
readonly
Returns the value of attribute ui.
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
- #cache_path ⇒ Object
- #cookbook_path ⇒ Object
- #create_store ⇒ Object
- #dna_path ⇒ Object
- #get_checksum(path) ⇒ Object
-
#initialize(v_config, ui) ⇒ InternalConfiguration
constructor
A new instance of InternalConfiguration.
- #load_existing ⇒ Object
- #run_solo ⇒ Object
- #save ⇒ Object
- #solo_needed? ⇒ Boolean
- #solo_path ⇒ Object
- #store_checksums ⇒ Object
- #store_path ⇒ Object
- #write_dna_json ⇒ Object
- #write_solo_rb ⇒ Object
Constructor Details
#initialize(v_config, ui) ⇒ InternalConfiguration
Returns a new instance of InternalConfiguration.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/vagabond/internal_configuration.rb', line 12 def initialize(v_config, ui) @v_config = v_config @config = Mash.new(:mappings => Mash.new) @checksums = Mash.new @ui = ui create_store load_existing store_checksums write_dna_json write_solo_rb run_solo if solo_needed? end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/vagabond/internal_configuration.rb', line 9 def config @config end |
#ui ⇒ Object (readonly)
Returns the value of attribute ui.
10 11 12 |
# File 'lib/vagabond/internal_configuration.rb', line 10 def ui @ui end |
Instance Method Details
#[](k) ⇒ Object
25 26 27 |
# File 'lib/vagabond/internal_configuration.rb', line 25 def [](k) @config[k] end |
#[]=(k, v) ⇒ Object
29 30 31 |
# File 'lib/vagabond/internal_configuration.rb', line 29 def []=(k,v) @config[k] = v end |
#cache_path ⇒ Object
120 121 122 123 124 125 |
# File 'lib/vagabond/internal_configuration.rb', line 120 def cache_path unless(@cache_path) FileUtils.mkdir_p(@cache_path = File.join(store_path, 'chef_cache')) end @cache_path end |
#cookbook_path ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/vagabond/internal_configuration.rb', line 127 def cookbook_path File.( File.join( File.dirname(__FILE__), 'cookbooks' ) ) end |
#create_store ⇒ Object
33 34 35 |
# File 'lib/vagabond/internal_configuration.rb', line 33 def create_store FileUtils.mkdir_p(store_path) end |
#dna_path ⇒ Object
55 56 57 |
# File 'lib/vagabond/internal_configuration.rb', line 55 def dna_path File.join(store_path, 'dna.json') end |
#get_checksum(path) ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/vagabond/internal_configuration.rb', line 98 def get_checksum(path) if(File.exists?(path)) s = Digest::SHA256.new s << File.read(path) s.hexdigest else '' end end |
#load_existing ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/vagabond/internal_configuration.rb', line 37 def load_existing if(File.exists?(path = File.join(store_path, 'vagabond.json'))) @config = Mash.new( JSON.load( File.read(path) ) ) end end |
#run_solo ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/vagabond/internal_configuration.rb', line 135 def run_solo ui.info ui.color('Ensuring expected system state (creating required template containers)', :yellow) ui.info ui.color(' - This can take a while...', :yellow) com = "#{Config[:sudo]}chef-solo -j #{File.join(store_path, 'dna.json')} -c #{File.join(store_path, 'solo.rb')}" debug(com) cmd = Mixlib::ShellOut.new(com, :timeout => 1200, :live_stream => Config[:debug]) cmd.run_command cmd.error! end |
#save ⇒ Object
145 146 147 148 149 |
# File 'lib/vagabond/internal_configuration.rb', line 145 def save File.open(File.join(store_path, 'vagabond.json'), 'w') do |file| file.write(JSON.dump(@config)) end end |
#solo_needed? ⇒ Boolean
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/vagabond/internal_configuration.rb', line 108 def solo_needed? if(Config[:force_solo]) true elsif(Config[:disable_solo]) false else [dna_path, solo_path].detect do |path| @checksums[path] != get_checksum(path) end end end |
#solo_path ⇒ Object
59 60 61 |
# File 'lib/vagabond/internal_configuration.rb', line 59 def solo_path File.join(store_path, 'solo.rb') end |
#store_checksums ⇒ Object
92 93 94 95 96 |
# File 'lib/vagabond/internal_configuration.rb', line 92 def store_checksums [dna_path, solo_path].each do |path| @checksums[path] = get_checksum(path) end end |
#store_path ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/vagabond/internal_configuration.rb', line 47 def store_path FileUtils.mkdir_p( File.join( File.dirname(@v_config.path), '.vagabond' ) ) end |
#write_dna_json ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/vagabond/internal_configuration.rb', line 63 def write_dna_json conf = Mash.new @v_config.config[:boxes].map(&:last).map{|i| i[:template]}.compact.uniq.each do |t| conf[t] = Mash.new(:enabled => true) end if(@v_config.config[:templates]) @v_config.config[:templates].each do |t| conf[t] ||= Mash.new conf[t].merge!(@v_config[:templates][t]) end end File.open(dna_path, 'w') do |file| file.write( JSON.dump( :vagabond => { :bases => conf }, :run_list => %w(recipe[vagabond]) ) ) end end |
#write_solo_rb ⇒ Object
86 87 88 89 90 |
# File 'lib/vagabond/internal_configuration.rb', line 86 def write_solo_rb File.open(solo_path, 'w') do |file| file.write("\nfile_cache_path \"#{cache_path}\"\ncookbook_path \"#{cookbook_path}\"\n") end end |