Class: Chef::Util::DSC::ConfigurationGenerator

Inherits:
Object
  • Object
show all
Includes:
Mixin::PowershellExec
Defined in:
lib/chef/util/dsc/configuration_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(node, config_directory) ⇒ ConfigurationGenerator

Returns a new instance of ConfigurationGenerator.



25
26
27
28
# File 'lib/chef/util/dsc/configuration_generator.rb', line 25

def initialize(node, config_directory)
  @node = node
  @config_directory = config_directory
end

Instance Method Details

#configuration_document_from_script_code(code, configuration_flags, imports) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/chef/util/dsc/configuration_generator.rb', line 30

def configuration_document_from_script_code(code, configuration_flags, imports)
  Chef::Log.trace("DSC: DSC code:\n '#{code}'")
  generated_script_path = write_document_generation_script(code, "chef_dsc", imports)
  begin
    configuration_document_from_script_path(generated_script_path, "chef_dsc", configuration_flags)
  ensure
    ::FileUtils.rm(generated_script_path)
  end
end

#configuration_document_from_script_path(script_path, configuration_name, configuration_flags) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/chef/util/dsc/configuration_generator.rb', line 40

def configuration_document_from_script_path(script_path, configuration_name, configuration_flags)
  validate_configuration_name!(configuration_name)

  config_generation_code = configuration_document_generation_code(script_path, configuration_name)
  switches_string = command_switches_string(get_merged_configuration_flags!(configuration_flags, configuration_name))

  powershell_exec!("#{config_generation_code} #{switches_string}")
  configuration_document_location = find_configuration_document(configuration_name)

  unless configuration_document_location
    raise "No DSC configuration for '#{configuration_name}' was generated from supplied DSC script"
  end

  configuration_document = get_configuration_document(configuration_document_location)
  ::FileUtils.rm_rf(configuration_document_location)
  configuration_document
end