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

Inherits:
Object
  • Object
show all
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.



23
24
25
26
# File 'lib/chef/util/dsc/configuration_generator.rb', line 23

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

Instance Method Details

#configuration_document_from_script_code(code, configuration_flags, imports, shellout_flags) ⇒ Object



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

def configuration_document_from_script_code(code, configuration_flags, imports, shellout_flags)
  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, shellout_flags)
  ensure
    ::FileUtils.rm(generated_script_path)
  end
end

#configuration_document_from_script_path(script_path, configuration_name, configuration_flags, shellout_flags) ⇒ Object



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

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

  document_generation_cmdlet = Chef::Util::Powershell::Cmdlet.new(
    @node,
    configuration_document_generation_code(script_path, configuration_name)
  )

  merged_configuration_flags = get_merged_configuration_flags!(configuration_flags, configuration_name)

  document_generation_cmdlet.run!(merged_configuration_flags, shellout_flags)
  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