From 0106155a0fda613336a3fc114e7c5c1c62a89bc9 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 20:24:14 -0200 Subject: [PATCH] Disable the plugin on machines backed by cloud providers (fix GH-45) --- lib/vagrant-cachier/config.rb | 12 ++++++++++++ lib/vagrant-cachier/plugin.rb | 6 +++++- locales/en.yml | 3 +++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/vagrant-cachier/config.rb b/lib/vagrant-cachier/config.rb index ac857a7..fb43280 100644 --- a/lib/vagrant-cachier/config.rb +++ b/lib/vagrant-cachier/config.rb @@ -28,6 +28,12 @@ module VagrantPlugins def validate(machine) errors = _detected_errors + if enabled? && backed_by_cloud_provider?(machine) + machine.ui.warn(I18n.t('vagrant_cachier.backed_by_cloud_provider', + provider: machine.provider_name)) + disable! + end + if enabled? && ! ALLOWED_SCOPES.include?(@scope.to_s) errors << I18n.t('vagrant_cachier.unknown_cache_scope', allowed: ALLOWED_SCOPES.inspect, @@ -55,6 +61,12 @@ module VagrantPlugins @synced_folder_opts = nil if @synced_folder_opts == UNSET_VALUE @buckets = @buckets ? @buckets.dup : {} end + + private + + def backed_by_cloud_provider?(machine) + CLOUD_PROVIDERS.include?(machine.provider_name.to_s) + end end end end diff --git a/lib/vagrant-cachier/plugin.rb b/lib/vagrant-cachier/plugin.rb index 93a9b27..e9523dc 100644 --- a/lib/vagrant-cachier/plugin.rb +++ b/lib/vagrant-cachier/plugin.rb @@ -11,12 +11,16 @@ module VagrantPlugins module Cachier class Plugin < Vagrant.plugin('2') name 'vagrant-cachier' - config 'cache' do require_relative "config" Config end end + + # Keep an eye on https://github.com/mitchellh/vagrant/wiki/Available-Vagrant-Plugins#wiki-providers + # for more. + CLOUD_PROVIDERS = %w( aws cloudstack digitalocean hp joyent openstack rackspace + softlayer proxmox managed virtualbox ) end end diff --git a/locales/en.yml b/locales/en.yml index a8eaefd..c67c616 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -16,3 +16,6 @@ en: scoped cache dirs starting with the 0.3.0 version of the plugin. unable_to_ssh: |- vagrant-cachier was unable to SSH into the VM to remove symlinks! + backed_by_cloud_provider: |- + The machine is backed by a cloud provider (%{provider}), caching + will be disabled.