2013-04-08 20:05:53 +00:00
|
|
|
require "vagrant"
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module CFEngine
|
|
|
|
class Config < Vagrant.plugin("2", :config)
|
2013-04-08 21:24:46 +00:00
|
|
|
attr_accessor :classes
|
2013-04-08 20:05:53 +00:00
|
|
|
attr_accessor :deb_repo_file
|
|
|
|
attr_accessor :deb_repo_line
|
2013-04-08 20:28:54 +00:00
|
|
|
attr_accessor :force_bootstrap
|
|
|
|
attr_accessor :install
|
|
|
|
attr_accessor :mode
|
2013-04-08 20:46:03 +00:00
|
|
|
attr_accessor :policy_server_address
|
2013-04-08 20:05:53 +00:00
|
|
|
attr_accessor :repo_gpg_key_url
|
2013-04-08 21:21:10 +00:00
|
|
|
attr_accessor :run_file
|
|
|
|
attr_accessor :upload_path
|
2013-04-08 20:09:52 +00:00
|
|
|
attr_accessor :yum_repo_file
|
|
|
|
attr_accessor :yum_repo_url
|
2013-04-08 20:05:53 +00:00
|
|
|
|
|
|
|
def initialize
|
2013-04-08 21:24:46 +00:00
|
|
|
@classes = UNSET_VALUE
|
2013-04-08 20:09:52 +00:00
|
|
|
@deb_repo_file = UNSET_VALUE
|
|
|
|
@deb_repo_line = UNSET_VALUE
|
2013-04-08 20:28:54 +00:00
|
|
|
@force_bootstrap = UNSET_VALUE
|
2013-04-08 20:09:52 +00:00
|
|
|
@install = UNSET_VALUE
|
2013-04-08 20:28:54 +00:00
|
|
|
@mode = UNSET_VALUE
|
2013-04-08 20:46:03 +00:00
|
|
|
@policy_server_address = UNSET_VALUE
|
2013-04-08 20:05:53 +00:00
|
|
|
@repo_gpg_key_url = UNSET_VALUE
|
2013-04-08 21:21:10 +00:00
|
|
|
@run_file = UNSET_VALUE
|
|
|
|
@upload_path = UNSET_VALUE
|
2013-04-08 20:09:52 +00:00
|
|
|
@yum_repo_file = UNSET_VALUE
|
|
|
|
@yum_repo_url = UNSET_VALUE
|
2013-04-08 20:05:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def finalize!
|
2013-04-08 21:24:46 +00:00
|
|
|
@classes = nil if @classes == UNSET_VALUE
|
|
|
|
|
2013-04-08 20:05:53 +00:00
|
|
|
if @deb_repo_file == UNSET_VALUE
|
|
|
|
@deb_repo_file = "/etc/apt/sources.list.d/cfengine-community.list"
|
|
|
|
end
|
|
|
|
|
|
|
|
if @deb_repo_line == UNSET_VALUE
|
|
|
|
@deb_repo_line = "deb http://cfengine.com/pub/apt $(lsb_release -cs) main"
|
|
|
|
end
|
|
|
|
|
2013-04-08 20:28:54 +00:00
|
|
|
@force_bootstrap = false if @force_bootstrap == UNSET_VALUE
|
|
|
|
|
2013-04-08 20:05:53 +00:00
|
|
|
@install = true if @install == UNSET_VALUE
|
|
|
|
@install = @install.to_sym if @install.respond_to?(:to_sym)
|
|
|
|
|
2013-04-08 20:28:54 +00:00
|
|
|
@mode = :bootstrap if @mode == UNSET_VALUE
|
|
|
|
@mode = @mode.to_sym
|
|
|
|
|
2013-04-08 21:21:10 +00:00
|
|
|
@run_file = nil if @run_file == UNSET_VALUE
|
|
|
|
|
2013-04-08 20:46:03 +00:00
|
|
|
@policy_server_address = nil if @policy_server_address == UNSET_VALUE
|
|
|
|
|
2013-04-08 20:05:53 +00:00
|
|
|
if @repo_gpg_key_url == UNSET_VALUE
|
|
|
|
@repo_gpg_key_url = "http://cfengine.com/pub/gpg.key"
|
|
|
|
end
|
2013-04-08 20:09:52 +00:00
|
|
|
|
2013-04-08 21:21:10 +00:00
|
|
|
@upload_path = "/tmp/vagrant-cfengine-file" if @upload_path == UNSET_VALUE
|
|
|
|
|
2013-04-08 20:09:52 +00:00
|
|
|
if @yum_repo_file == UNSET_VALUE
|
|
|
|
@yum_repo_file = "/etc/yum.repos.d/cfengine-community.repo"
|
|
|
|
end
|
|
|
|
|
|
|
|
if @yum_repo_url == UNSET_VALUE
|
|
|
|
@yum_repo_url = "http://cfengine.com/pub/yum/"
|
|
|
|
end
|
2013-04-08 20:05:53 +00:00
|
|
|
end
|
2013-04-08 20:51:40 +00:00
|
|
|
|
|
|
|
def validate(machine)
|
|
|
|
errors = []
|
|
|
|
|
2013-04-08 21:21:10 +00:00
|
|
|
valid_modes = [:bootstrap, :single_run]
|
2013-04-08 20:51:40 +00:00
|
|
|
errors << I18n.t("vagrant.cfengine_config.invalid_mode") if !valid_modes.include?(@mode)
|
|
|
|
|
|
|
|
if @mode == :bootstrap
|
|
|
|
errors << I18n.t("vagrant.cfengine_config.policy_server_address") if !@policy_server_address
|
|
|
|
end
|
|
|
|
|
2013-04-08 21:24:46 +00:00
|
|
|
if @classes && !@classes.is_a?(Array)
|
|
|
|
errors << I18n.t("vagrant.cfengine_config.classes_array")
|
|
|
|
end
|
|
|
|
|
2013-04-08 20:51:40 +00:00
|
|
|
{ "CFEngine" => errors }
|
|
|
|
end
|
2013-04-08 20:05:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|