apt-cacher bucket + capability

This commit is contained in:
Roman Heinrich 2013-07-17 11:38:02 +02:00
parent ce6e08fd0d
commit b0110897a7
4 changed files with 55 additions and 0 deletions

View file

@ -38,3 +38,4 @@ require_relative "bucket/gem"
require_relative "bucket/pacman"
require_relative "bucket/yum"
require_relative "bucket/rvm"
require_relative "bucket/apt_cacher"

View file

@ -0,0 +1,35 @@
# Apt-Cacher NG is a caching proxy for software packages which are downloaded by Unix/Linux system distribution mechanisms from mirror servers accessible via HTTP.
module VagrantPlugins
module Cachier
class Bucket
class AptCacher < Bucket
def self.capability
:apt_cacher_dir
end
def install
machine = @env[:machine]
guest = machine.guest
if guest.capability?(:apt_cacher_dir)
guest_path = guest.capability(:apt_cacher_dir)
@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 an APT-CACHER cache for a guest machine that does not support it!"
end
end
end
end
end
end

View file

@ -0,0 +1,14 @@
module VagrantPlugins
module Cachier
module Cap
module Debian
module AptCacherDir
def self.apt_cacher_dir(machine)
# cat /etc/apt-cacher-ng/acng.conf |grep CacheDir
'/var/cache/apt-cacher-ng'
end
end
end
end
end
end

View file

@ -23,6 +23,11 @@ module VagrantPlugins
Cap::Debian::AptCacheDir
end
guest_capability 'debian', 'apt_cacher_dir' do
require_relative 'cap/debian/apt_cacher_dir'
Cap::Debian::AptCacherDir
end
guest_capability 'redhat', 'yum_cache_dir' do
require_relative 'cap/redhat/yum_cache_dir'
Cap::RedHat::YumCacheDir