Adds basic chef file_cache_path support.
This commit is contained in:
parent
57528f5420
commit
3eede6caf9
4 changed files with 71 additions and 0 deletions
|
@ -34,6 +34,7 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
require_relative "bucket/apt"
|
require_relative "bucket/apt"
|
||||||
|
require_relative "bucket/chef"
|
||||||
require_relative "bucket/gem"
|
require_relative "bucket/gem"
|
||||||
require_relative "bucket/pacman"
|
require_relative "bucket/pacman"
|
||||||
require_relative "bucket/yum"
|
require_relative "bucket/yum"
|
||||||
|
|
34
lib/vagrant-cachier/bucket/chef.rb
Normal file
34
lib/vagrant-cachier/bucket/chef.rb
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
module VagrantPlugins
|
||||||
|
module Cachier
|
||||||
|
class Bucket
|
||||||
|
class Chef < Bucket
|
||||||
|
def self.capability
|
||||||
|
:chef_file_cache_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def install
|
||||||
|
machine = @env[:machine]
|
||||||
|
guest = machine.guest
|
||||||
|
|
||||||
|
if guest.capability?(:chef_file_cache_path)
|
||||||
|
guest_path = guest.capability(:chef_file_cache_path)
|
||||||
|
|
||||||
|
@env[:cache_dirs] << guest_path
|
||||||
|
|
||||||
|
machine.communicate.tap do |comm|
|
||||||
|
comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}")
|
||||||
|
unless comm.test("test -L #{guest_path}")
|
||||||
|
comm.sudo("rm -rf #{guest_path}")
|
||||||
|
comm.sudo("mkdir -p `dirname #{guest_path}`")
|
||||||
|
comm.sudo("ln -s /tmp/vagrant-cache/#{@name} #{guest_path}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# TODO: Raise a better error
|
||||||
|
raise "You've configured a Chef cache for a guest machine that does not support it!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
31
lib/vagrant-cachier/cap/linux/chef_file_cache_path.rb
Normal file
31
lib/vagrant-cachier/cap/linux/chef_file_cache_path.rb
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
module VagrantPlugins
|
||||||
|
module Cachier
|
||||||
|
module Cap
|
||||||
|
module Linux
|
||||||
|
module ChefFileCachePath
|
||||||
|
def self.chef_provisioner?(machine)
|
||||||
|
provisioners = machine.config.vm.provisioners
|
||||||
|
chef_provisioners = [:chef_solo, :chef_client]
|
||||||
|
compat_provisioners = provisioners.keep_if { |p| chef_provisioners.include? p.name }
|
||||||
|
|
||||||
|
if compat_provisioners.size > 1
|
||||||
|
raise "One machine is using multiple chef provisioners, which is unsupported."
|
||||||
|
end
|
||||||
|
|
||||||
|
using_chef = compat_provisioners.empty? ? false : true
|
||||||
|
|
||||||
|
using_chef
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.chef_file_cache_path(machine)
|
||||||
|
chef_file_cache_path = nil
|
||||||
|
# TODO: Determine paths rather than using default.
|
||||||
|
chef_file_cache_path = '/var/chef/cache' if chef_provisioner?(machine)
|
||||||
|
|
||||||
|
return chef_file_cache_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -18,6 +18,11 @@ module VagrantPlugins
|
||||||
Cap::Linux::RvmPath
|
Cap::Linux::RvmPath
|
||||||
end
|
end
|
||||||
|
|
||||||
|
guest_capability 'linux', 'chef_file_cache_path' do
|
||||||
|
require_relative 'cap/linux/chef_file_cache_path'
|
||||||
|
Cap::Linux::ChefFileCachePath
|
||||||
|
end
|
||||||
|
|
||||||
guest_capability 'debian', 'apt_cache_dir' do
|
guest_capability 'debian', 'apt_cache_dir' do
|
||||||
require_relative 'cap/debian/apt_cache_dir'
|
require_relative 'cap/debian/apt_cache_dir'
|
||||||
Cap::Debian::AptCacheDir
|
Cap::Debian::AptCacheDir
|
||||||
|
|
Loading…
Reference in a new issue