diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-01-20 11:14:20 -0800 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-01-20 11:33:58 -0800 |
commit | 947ca116dd23cea2023cb9def5fd068e4220a2e5 (patch) | |
tree | c782989e5f8ca3caf9581c0b38f9765524959c0f /lib | |
parent | 46bda1acef603842ab50d2a54e6f70177367a512 (diff) | |
download | chef-947ca116dd23cea2023cb9def5fd068e4220a2e5.tar.gz |
Modified dsc_script resource provider to use the imports hash
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/provider/dsc_script.rb | 2 | ||||
-rw-r--r-- | lib/chef/util/dsc/configuration_generator.rb | 36 |
2 files changed, 31 insertions, 7 deletions
diff --git a/lib/chef/provider/dsc_script.rb b/lib/chef/provider/dsc_script.rb index 5db50e74b3..a5bca0d6b8 100644 --- a/lib/chef/provider/dsc_script.rb +++ b/lib/chef/provider/dsc_script.rb @@ -123,7 +123,7 @@ class Chef else # If code is also not provided, we mimic what the other script resources do (execute nothing) Chef::Log.warn("Neither code or command were provided for dsc_resource[#{@dsc_resource.name}].") unless @dsc_resource.code - generator.configuration_document_from_script_code(@dsc_resource.code || '', configuration_flags, shellout_flags) + generator.configuration_document_from_script_code(@dsc_resource.code || '', configuration_flags, @dsc_resource.imports, shellout_flags) end end diff --git a/lib/chef/util/dsc/configuration_generator.rb b/lib/chef/util/dsc/configuration_generator.rb index 12cd5dc3a2..160f0d0c78 100644 --- a/lib/chef/util/dsc/configuration_generator.rb +++ b/lib/chef/util/dsc/configuration_generator.rb @@ -25,9 +25,9 @@ class Chef::Util::DSC @config_directory = config_directory end - def configuration_document_from_script_code(code, configuration_flags, shellout_flags) + def configuration_document_from_script_code(code, configuration_flags, imports, shellout_flags) Chef::Log.debug("DSC: DSC code:\n '#{code}'") - generated_script_path = write_document_generation_script(code, 'chef_dsc') + generated_script_path = write_document_generation_script(code, 'chef_dsc', imports) begin configuration_document_from_script_path(generated_script_path, 'chef_dsc', configuration_flags, shellout_flags) ensure @@ -80,18 +80,42 @@ class Chef::Util::DSC merged_configuration_flags end - def configuration_code(code, configuration_name) - "$ProgressPreference = 'SilentlyContinue';Configuration '#{configuration_name}'\n{\n\tnode 'localhost'\n{\n\t#{code}\n}}\n" + def configuration_code(code, configuration_name, imports) + <<-EOF +$ProgressPreference = 'SilentlyContinue'; +Configuration '#{configuration_name}' +{ + #{generate_import_resource_statements(imports).join(" \n")} + node 'localhost' + { + #{code} + } +} + EOF + end + + def generate_import_resource_statements(imports) + if imports + imports.map do |resource_module, resources| + if resources.length > 0 + "Import-DscResource -ModuleName #{resource_module} -Name #{resources.join(',')}" + else + "Import-DscResource -ModuleName #{resource_module}" + end + end + else + [] + end end def configuration_document_generation_code(configuration_script, configuration_name) ". '#{configuration_script}';#{configuration_name}" end - def write_document_generation_script(code, configuration_name) + def write_document_generation_script(code, configuration_name, imports) script_path = "#{@config_directory}/chef_dsc_config.ps1" ::File.open(script_path, 'wt') do | script | - script.write(configuration_code(code, configuration_name)) + script.write(configuration_code(code, configuration_name, imports)) end script_path end |