2013-06-08 02:37:02 +00:00
|
|
|
module VagrantPlugins
|
2013-05-22 22:38:26 +00:00
|
|
|
module Cachier
|
|
|
|
class Config < Vagrant.plugin(2, :config)
|
2014-02-01 02:04:51 +00:00
|
|
|
attr_accessor :scope, :auto_detect, :synced_folder_opts
|
2013-05-22 22:38:26 +00:00
|
|
|
attr_reader :buckets
|
|
|
|
|
2013-08-03 17:51:31 +00:00
|
|
|
ALLOWED_SCOPES = %w( box machine )
|
|
|
|
|
2013-05-22 22:38:26 +00:00
|
|
|
def initialize
|
2014-02-01 02:03:20 +00:00
|
|
|
@scope = UNSET_VALUE
|
2013-05-22 22:38:26 +00:00
|
|
|
@auto_detect = UNSET_VALUE
|
2014-02-01 02:03:20 +00:00
|
|
|
@synced_folder_opts = UNSET_VALUE
|
2014-02-01 04:57:51 +00:00
|
|
|
@ui = Vagrant::UI::Colored.new
|
2013-05-22 22:38:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def enable(bucket, opts = {})
|
|
|
|
(@buckets ||= {})[bucket] = opts
|
|
|
|
end
|
|
|
|
|
2014-02-01 02:04:51 +00:00
|
|
|
def enable_nfs=(value)
|
2014-02-01 04:57:51 +00:00
|
|
|
@ui.warn "The `enable_nfs` config for vagrant-cachier has been deprecated " \
|
|
|
|
"and will be removed on 0.7.0, please use " \
|
2014-02-01 06:36:00 +00:00
|
|
|
"`synced_folder_opts = { type: :nfs }` instead.\n"
|
2014-02-01 04:57:51 +00:00
|
|
|
|
2014-02-01 06:36:00 +00:00
|
|
|
@synced_folder_opts = { type: :nfs } if value
|
2014-02-01 02:04:51 +00:00
|
|
|
end
|
|
|
|
|
2013-08-03 17:51:31 +00:00
|
|
|
def validate(machine)
|
|
|
|
errors = _detected_errors
|
|
|
|
|
2014-02-01 22:24:14 +00:00
|
|
|
if enabled? && backed_by_cloud_provider?(machine)
|
|
|
|
machine.ui.warn(I18n.t('vagrant_cachier.backed_by_cloud_provider',
|
|
|
|
provider: machine.provider_name))
|
|
|
|
disable!
|
|
|
|
end
|
|
|
|
|
2013-08-03 17:51:31 +00:00
|
|
|
if enabled? && ! ALLOWED_SCOPES.include?(@scope.to_s)
|
|
|
|
errors << I18n.t('vagrant_cachier.unknown_cache_scope',
|
|
|
|
allowed: ALLOWED_SCOPES.inspect,
|
|
|
|
cache_scope: @scope)
|
|
|
|
end
|
|
|
|
|
|
|
|
{ "vagrant cachier" => errors }
|
|
|
|
end
|
|
|
|
|
2014-02-01 20:38:35 +00:00
|
|
|
def enabled?
|
|
|
|
return @enabled unless @enabled.nil?
|
|
|
|
|
2014-02-12 01:24:48 +00:00
|
|
|
@enabled = @scope != UNSET_VALUE
|
2014-02-01 20:38:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def disable!
|
|
|
|
@enabled = false
|
|
|
|
end
|
|
|
|
|
2013-05-22 22:38:26 +00:00
|
|
|
def finalize!
|
|
|
|
return unless enabled?
|
|
|
|
|
2014-02-12 01:24:48 +00:00
|
|
|
@auto_detect = true if @auto_detect == UNSET_VALUE
|
2014-02-01 02:03:20 +00:00
|
|
|
@synced_folder_opts = nil if @synced_folder_opts == UNSET_VALUE
|
|
|
|
@buckets = @buckets ? @buckets.dup : {}
|
2013-05-22 22:38:26 +00:00
|
|
|
end
|
2014-02-01 22:24:14 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def backed_by_cloud_provider?(machine)
|
|
|
|
CLOUD_PROVIDERS.include?(machine.provider_name.to_s)
|
|
|
|
end
|
2013-05-22 22:38:26 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|