Class: VagrantPlugins::DSC::Config
- Inherits:
-
Object
- Object
- VagrantPlugins::DSC::Config
- Extended by:
- Vagrant::Util::Counter
- Defined in:
- lib/vagrant-dsc/config.rb
Overview
The “Configuration” represents a configuration of how the DSC provisioner should behave: data directories, working directory, DSC Manifests etc.
Instance Attribute Summary collapse
-
#configuration_file ⇒ Object
Relative path to the DSC Configuration file.
-
#configuration_name ⇒ Object
The name of the Configuration module.
-
#configuration_params ⇒ Hash
Set of Parameters to pass to the DSC Configuration.
-
#expanded_configuration_file ⇒ Object
Fully qualified path to the configuration file.
-
#manifests_path ⇒ Object
Relative path to the folder containing the root Configuration manifest file.
-
#module_path ⇒ Array
Set of module paths relative to the Vagrantfile dir.
-
#mof_path ⇒ Object
Relative path to a folder, containing the pre-generated MOF file.
-
#synced_folder_type ⇒ Object
The type of synced folders to use when sharing the data required for the provisioner to work properly.
-
#temp_dir ⇒ Object
Temporary working directory on the guest machine.
Instance Method Summary collapse
-
#expanded_module_paths(root_path) ⇒ Array
Returns the module paths as an array of paths expanded relative to the root path.
-
#finalize! ⇒ Object
Final step of the Configuration lifecyle prior to validation.
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#validate(machine) ⇒ Hash
Validate configuration and return a hash of errors.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vagrant-dsc/config.rb', line 62 def initialize super @configuration_file = UNSET_VALUE @manifests_path = UNSET_VALUE @configuration_name = UNSET_VALUE @mof_path = UNSET_VALUE @module_path = UNSET_VALUE @configuration_params = {} @synced_folder_type = UNSET_VALUE @temp_dir = UNSET_VALUE @logger = Log4r::Logger.new("vagrant::vagrant_dsc") end |
Instance Attribute Details
#configuration_file ⇒ Object
Relative path to the DSC Configuration file.
Path is relative to the folder containing the Vagrantfile.
25 26 27 |
# File 'lib/vagrant-dsc/config.rb', line 25 def configuration_file @configuration_file end |
#configuration_name ⇒ Object
The name of the Configuration module
Defaults to the basename of the “configuration_file” e.g. “Foo.ps1” becomes “Foo”
37 38 39 |
# File 'lib/vagrant-dsc/config.rb', line 37 def configuration_name @configuration_name end |
#configuration_params ⇒ Hash
Set of Parameters to pass to the DSC Configuration.
15 16 17 |
# File 'lib/vagrant-dsc/config.rb', line 15 def configuration_params @configuration_params end |
#expanded_configuration_file ⇒ Object
Fully qualified path to the configuration file.
Do not override this.
60 61 62 |
# File 'lib/vagrant-dsc/config.rb', line 60 def @expanded_configuration_file end |
#manifests_path ⇒ Object
Relative path to the folder containing the root Configuration manifest file. Defaults to ‘manifests’.
Path is relative to the folder containing the Vagrantfile.
31 32 33 |
# File 'lib/vagrant-dsc/config.rb', line 31 def manifests_path @manifests_path end |
#module_path ⇒ Array
Set of module paths relative to the Vagrantfile dir.
These paths are added to the DSC Configuration running environment to enable local modules to be addressed.
45 46 47 |
# File 'lib/vagrant-dsc/config.rb', line 45 def module_path @module_path end |
#mof_path ⇒ Object
Relative path to a folder, containing the pre-generated MOF file.
Path is relative to the folder containing the Vagrantfile.
20 21 22 |
# File 'lib/vagrant-dsc/config.rb', line 20 def mof_path @mof_path end |
#synced_folder_type ⇒ Object
The type of synced folders to use when sharing the data required for the provisioner to work properly.
By default this will use the default synced folder type. For example, you can set this to “nfs” to use NFS synced folders.
52 53 54 |
# File 'lib/vagrant-dsc/config.rb', line 52 def synced_folder_type @synced_folder_type end |
#temp_dir ⇒ Object
Temporary working directory on the guest machine.
55 56 57 |
# File 'lib/vagrant-dsc/config.rb', line 55 def temp_dir @temp_dir end |
Instance Method Details
#expanded_module_paths(root_path) ⇒ Array
Returns the module paths as an array of paths expanded relative to the root path.
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/vagrant-dsc/config.rb', line 110 def (root_path) return [] if !module_path # Get all the paths and expand them relative to the root path, returning # the array of expanded paths paths = module_path paths = [paths] if !paths.is_a?(Array) paths.map do |path| Pathname.new(path).(root_path).to_s end end |
#finalize! ⇒ Object
Final step of the Configuration lifecyle prior to validation.
Ensures all attributes are set to defaults if not provided.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/vagrant-dsc/config.rb', line 80 def finalize! super # Null checks @configuration_file = "default.ps1" if @configuration_file == UNSET_VALUE @module_path = nil if @module_path == UNSET_VALUE @synced_folder_type = nil if @synced_folder_type == UNSET_VALUE @temp_dir = nil if @temp_dir == UNSET_VALUE @mof_path = nil if @mof_path == UNSET_VALUE @configuration_name = File.basename(@configuration_file, File.extname(@configuration_file)) if @configuration_name == UNSET_VALUE @manifests_path = File.dirname(@configuration_file) if @manifests_path == UNSET_VALUE # Can't supply them both! if (@configuration_file != nil && @mof_path != nil) raise DSCError, :manifest_and_mof_provided end # Set a default temp dir that has an increasing counter so # that multiple DSC definitions won't overwrite each other if !@temp_dir counter = self.class.get_and_update_counter(:dsc_config) @temp_dir = "/tmp/vagrant-dsc-#{counter}" end end |
#validate(machine) ⇒ Hash
Validate configuration and return a hash of errors.
Does not check that DSC itself is properly configured, which is performed at run-time.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/vagrant-dsc/config.rb', line 129 def validate(machine) @logger.info("==> Configurin' DSC man!") errors = _detected_errors # Calculate the manifests and module paths based on env = (machine.env.root_path) # Manifest file validation .each do |path| errors << I18n.t("vagrant_dsc.errors.module_path_missing", path: path) if !Pathname.new(path).(machine.env.root_path).directory? end = Pathname.new(manifests_path). (machine.env.root_path) if !.directory? errors << I18n.t("vagrant_dsc.errors.manifests_path_missing", path: .to_s) end @expanded_configuration_file = .join(File.basename(configuration_file)) if !.file? && !.directory? errors << I18n.t("vagrant_dsc.errors.manifest_missing", manifest: .to_s) end { "dsc provisioner" => errors } end |