refactor, code cleanup, remove println debugging
This commit is contained in:
parent
9e18803b95
commit
f5966d5166
1 changed files with 25 additions and 25 deletions
|
@ -14,45 +14,33 @@ module VagrantPlugins
|
||||||
|
|
||||||
if !env[:cache_buckets_folder_configured] && env[:machine].config.cache.enabled?
|
if !env[:cache_buckets_folder_configured] && env[:machine].config.cache.enabled?
|
||||||
setup_buckets_folder
|
setup_buckets_folder
|
||||||
env[:cache_buckets_folder_configured] = true
|
|
||||||
if cache_vagrant_omnibus?
|
|
||||||
setup_omnibus_cache_folder
|
setup_omnibus_cache_folder
|
||||||
end
|
env[:cache_buckets_folder_configured] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
@app.call env
|
@app.call env
|
||||||
end
|
end
|
||||||
|
|
||||||
def cache_vagrant_omnibus?
|
|
||||||
plugin_defined = defined?(VagrantPlugins::Omnibus::Plugin)
|
|
||||||
puts "xxx - cap: vagrant-omnibus defined? #{plugin_defined}"
|
|
||||||
return false unless plugin_defined
|
|
||||||
|
|
||||||
chef_version = @env[:machine].config.omnibus.chef_version
|
|
||||||
puts "xxx - cap: chef_version? #{chef_version}"
|
|
||||||
return chef_version != nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def setup_omnibus_cache_folder
|
|
||||||
# since it's not configurable via the vagrant-omnibus plugin (yet)
|
|
||||||
# we specify the directory where to download the omnibus package here
|
|
||||||
omnibus_cache_dir = File.join(cache_root.to_s, 'omnibus')
|
|
||||||
FileUtils.mkdir_p(omnibus_cache_dir) unless File.exist? omnibus_cache_dir
|
|
||||||
ENV['OMNIBUS_DOWNLOAD_DIR'] = "/tmp/vagrant-cache/omnibus"
|
|
||||||
end
|
|
||||||
|
|
||||||
def setup_buckets_folder
|
def setup_buckets_folder
|
||||||
FileUtils.mkdir_p(cache_root.to_s) unless cache_root.exist?
|
FileUtils.mkdir_p(host_cache_root.to_s) unless host_cache_root.exist?
|
||||||
|
|
||||||
synced_folder_opts = {id: "vagrant-cache"}
|
synced_folder_opts = {id: "vagrant-cache"}
|
||||||
synced_folder_opts.merge!(@env[:machine].config.cache.synced_folder_opts || {})
|
synced_folder_opts.merge!(@env[:machine].config.cache.synced_folder_opts || {})
|
||||||
|
|
||||||
@env[:machine].config.vm.synced_folder cache_root, '/tmp/vagrant-cache', synced_folder_opts
|
@env[:machine].config.vm.synced_folder host_cache_root, guest_cache_root, synced_folder_opts
|
||||||
@env[:cache_dirs] = []
|
@env[:cache_dirs] = []
|
||||||
end
|
end
|
||||||
|
|
||||||
def cache_root
|
def setup_omnibus_cache_folder
|
||||||
@cache_root ||= case @env[:machine].config.cache.scope.to_sym
|
# unfortunately vagrant-omnibus hooks in before our buckets are installed, yet
|
||||||
|
# this is early enough to tell it to download to the vagrant-omnibus pseudo bucket
|
||||||
|
if omnibus_plugin_detected? && omnibus_plugin_enabled?
|
||||||
|
ENV['OMNIBUS_DOWNLOAD_DIR'] ||= "#{guest_cache_root}/vagrant-omnibus"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def host_cache_root
|
||||||
|
@host_cache_root ||= case @env[:machine].config.cache.scope.to_sym
|
||||||
when :box
|
when :box
|
||||||
@env[:home_path].join('cache', @env[:machine].box.name)
|
@env[:home_path].join('cache', @env[:machine].box.name)
|
||||||
when :machine
|
when :machine
|
||||||
|
@ -61,6 +49,18 @@ module VagrantPlugins
|
||||||
raise "Unknown cache scope: '#{@env[:machine].config.cache.scope}'"
|
raise "Unknown cache scope: '#{@env[:machine].config.cache.scope}'"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def guest_cache_root
|
||||||
|
'/tmp/vagrant-cache'
|
||||||
|
end
|
||||||
|
|
||||||
|
def omnibus_plugin_detected?
|
||||||
|
defined?(VagrantPlugins::Omnibus::Plugin)
|
||||||
|
end
|
||||||
|
|
||||||
|
def omnibus_plugin_enabled?
|
||||||
|
@env[:machine].config.omnibus.chef_version != nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue