Support config.classes for extra classes in CFEngine

This commit is contained in:
Mitchell Hashimoto 2013-04-08 14:24:46 -07:00
parent c25ce9f732
commit 292bada134
3 changed files with 20 additions and 1 deletions

View File

@ -3,6 +3,7 @@ require "vagrant"
module VagrantPlugins
module CFEngine
class Config < Vagrant.plugin("2", :config)
attr_accessor :classes
attr_accessor :deb_repo_file
attr_accessor :deb_repo_line
attr_accessor :force_bootstrap
@ -16,6 +17,7 @@ module VagrantPlugins
attr_accessor :yum_repo_url
def initialize
@classes = UNSET_VALUE
@deb_repo_file = UNSET_VALUE
@deb_repo_line = UNSET_VALUE
@force_bootstrap = UNSET_VALUE
@ -30,6 +32,8 @@ module VagrantPlugins
end
def finalize!
@classes = nil if @classes == UNSET_VALUE
if @deb_repo_file == UNSET_VALUE
@deb_repo_file = "/etc/apt/sources.list.d/cfengine-community.list"
end
@ -75,6 +79,10 @@ module VagrantPlugins
errors << I18n.t("vagrant.cfengine_config.policy_server_address") if !@policy_server_address
end
if @classes && !@classes.is_a?(Array)
errors << I18n.t("vagrant.cfengine_config.classes_array")
end
{ "CFEngine" => errors }
end
end

View File

@ -21,7 +21,7 @@ module VagrantPlugins
@machine.ui.info(I18n.t("vagrant.cfengine_single_run_execute"))
path = Pathname.new(@config.run_file).expand_path(@machine.env.root_path)
machine.communicate.upload(path.to_s, @config.upload_path)
cfagent("-KI -f #{@config.upload_path}")
cfagent("-KI -f #{@config.upload_path}#{cfagent_classes_args}")
end
end
@ -44,6 +44,15 @@ module VagrantPlugins
end
end
# Returns the arguments for the classes configuration if they are
# set.
def cfagent_classes_args
return "" if !@config.classes
args = @config.classes.map { |c| "-D#{c}" }.join(" ")
return " #{args}"
end
# This handles checking if the CFEngine installation needs to
# be bootstrapped, and bootstraps if it does.
def handle_cfengine_bootstrap

View File

@ -16,6 +16,8 @@ en:
Executing run file for CFEngine...
cfengine_config:
classes_array: |-
The 'classes' configuration must be an array.
invalid_mode: |-
The mode must be 'bootstrap' or 'single_run'
policy_server_address: |-