diff options
author | Adam Edwards <adamed@opscode.com> | 2014-08-19 06:52:36 -0700 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2014-09-03 13:57:37 -0400 |
commit | a6cf4da154c03caa8df32bb869e6c2869703ba0a (patch) | |
tree | af274eca47e897660b02b6e84f7abb203438c626 /lib | |
parent | 5f269afd5ac11f799503aeea0b608271ad23289e (diff) | |
download | chef-a6cf4da154c03caa8df32bb869e6c2869703ba0a.tar.gz |
Add configurationdata attribute support
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/provider/dsc_script.rb | 28 | ||||
-rw-r--r-- | lib/chef/resource/dsc_script.rb | 30 | ||||
-rw-r--r-- | lib/chef/util/dsc/configuration_generator.rb | 2 |
3 files changed, 53 insertions, 7 deletions
diff --git a/lib/chef/provider/dsc_script.rb b/lib/chef/provider/dsc_script.rb index 2adb32937f..122b7e6198 100644 --- a/lib/chef/provider/dsc_script.rb +++ b/lib/chef/provider/dsc_script.rb @@ -59,12 +59,14 @@ class Chef protected def run_configuration(operation) - config_directory = ::Dir.mktmpdir("dsc-script") + config_directory = ::Dir.mktmpdir("chef-dsc-script") + configuration_data_path = get_configuration_data_path(config_directory) + configuration_flags = get_augmented_configuration_flags(configuration_data_path) config_manager = Chef::Util::DSC::LocalConfigurationManager.new(@run_context.node, config_directory) begin - configuration_document = generate_configuration_document(config_directory, @dsc_resource.flags) + configuration_document = generate_configuration_document(config_directory, configuration_flags) @operations[operation].call(config_manager, configuration_document) rescue Exception => e Chef::Log.error("DSC operation failed: #{e.message.to_s}") @@ -74,6 +76,16 @@ class Chef end end + def get_augmented_configuration_flags(configuration_data_path) + updated_flags = nil + if configuration_data_path + updated_flags = @dsc_resource.flags.nil? ? {} : @dsc_resource.flags.dup + Chef::Util::PathHelper.validate_path(configuration_data_path) + updated_flags[:configurationdata] = configuration_data_path + end + updated_flags + end + def generate_configuration_document(config_directory, configuration_flags) shellout_flags = { :cwd => @dsc_resource.cwd, @@ -90,6 +102,18 @@ class Chef end end + def get_configuration_data_path(config_directory) + if @dsc_resource.configuration_data_script + @dsc_resource.configuration_data_script + elsif @dsc_resource.configuration_data + configuration_data_path = "#{config_directory}/chef_dsc_config_data.psd1" + ::File.open(configuration_data_path, 'wt') do | script | + script.write(@dsc_resource.configuration_data) + end + configuration_data_path + end + end + def configuration_name @dsc_resource.configuration_name || @dsc_resource.name end diff --git a/lib/chef/resource/dsc_script.rb b/lib/chef/resource/dsc_script.rb index 10d90bd065..37546c3b6a 100644 --- a/lib/chef/resource/dsc_script.rb +++ b/lib/chef/resource/dsc_script.rb @@ -25,16 +25,16 @@ class Chef def initialize(name, run_context=nil) super @allowed_actions.push(:run) - @action = 'run' + @action = :run provider(Chef::Provider::DscScript) end def code(arg=nil) if arg && command - raise ArgumentError, "Only one of 'code' and 'command' properties may be specified" + raise ArgumentError, "Only one of 'code' and 'command' attributes may be specified" end if arg && configuration_name - raise ArgumentError, "Attribute `code` may not be set if `configuration_name` is set" + raise ArgumentError, "The 'code' and 'command' attributes may not be used together" end set_or_return( :code, @@ -56,7 +56,7 @@ class Chef def command(arg=nil) if arg && code - raise ArgumentError, "Only one of 'code' and 'command' properties may be specified" + raise ArgumentError, "The 'code' and 'command' attributes may not be used together" end set_or_return( :command, @@ -65,6 +65,28 @@ class Chef ) end + def configuration_data(arg=nil) + if arg && configuration_data_script + raise ArgumentError, "The 'configuration_data' and 'configuration_data_script' attributes may not be used together" + end + set_or_return( + :configuration_data, + arg, + :kind_of => [ String ] + ) + end + + def configuration_data_script(arg=nil) + if arg && configuration_data + raise ArgumentError, "The 'configuration_data' and 'configuration_data_script' attributes may not be used together" + end + set_or_return( + :configuration_data_script, + arg, + :kind_of => [ String ] + ) + end + def flags(arg=nil) set_or_return( :flags, diff --git a/lib/chef/util/dsc/configuration_generator.rb b/lib/chef/util/dsc/configuration_generator.rb index ea949bb9c4..0385bad0c4 100644 --- a/lib/chef/util/dsc/configuration_generator.rb +++ b/lib/chef/util/dsc/configuration_generator.rb @@ -81,7 +81,7 @@ class Chef::Util::DSC end def configuration_code(code, configuration_name) - "$ProgressPreference = 'SilentlyContinue';Configuration '#{configuration_name}'\n{\n\t#{code}\n}\n" + "$ProgressPreference = 'SilentlyContinue';Configuration '#{configuration_name}'\n{\n\tnode 'localhost'\n{\n\t#{code}\n}}\n" end def configuration_document_generation_code(configuration_script, configuration_name) |