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_data_file ⇒ Object
Relative path to the DSC Configuration Data file.
-
#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_data_file ⇒ Object
Fully qualified path to the configuration data file.
-
#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.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/vagrant-dsc/config.rb', line 74 def initialize super @configuration_file = UNSET_VALUE @configuration_data_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_data_file ⇒ Object
Relative path to the DSC Configuration Data file.
Configuration data is used to parameterise the configuration_file.
Path is relative to the folder containing the Vagrantfile.
32 33 34 |
# File 'lib/vagrant-dsc/config.rb', line 32 def configuration_data_file @configuration_data_file end |
#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”
44 45 46 |
# File 'lib/vagrant-dsc/config.rb', line 44 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_data_file ⇒ Object
Fully qualified path to the configuration data file.
Do not override this.
72 73 74 |
# File 'lib/vagrant-dsc/config.rb', line 72 def end |
#expanded_configuration_file ⇒ Object
Fully qualified path to the configuration file.
Do not override this.
67 68 69 |
# File 'lib/vagrant-dsc/config.rb', line 67 def 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.
38 39 40 |
# File 'lib/vagrant-dsc/config.rb', line 38 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.
52 53 54 |
# File 'lib/vagrant-dsc/config.rb', line 52 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.
59 60 61 |
# File 'lib/vagrant-dsc/config.rb', line 59 def synced_folder_type @synced_folder_type end |
#temp_dir ⇒ Object
Temporary working directory on the guest machine.
62 63 64 |
# File 'lib/vagrant-dsc/config.rb', line 62 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.
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/vagrant-dsc/config.rb', line 124 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.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/vagrant-dsc/config.rb', line 93 def finalize! super # Null checks @configuration_file = "default.ps1" if @configuration_file == UNSET_VALUE @configuration_data_file = nil if @configuration_data_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.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/vagrant-dsc/config.rb', line 143 def validate(machine) @logger.info("==> Configuring DSC") 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 host_manifest_path = Pathname.new(manifests_path).(machine.env.root_path) if !host_manifest_path.directory? errors << I18n.t("vagrant_dsc.errors.manifests_path_missing", path: host_manifest_path.to_s) end # Path to manifest file on the host machine must exist = host_manifest_path.join(File.basename(configuration_file)) if !.file? && !.directory? errors << I18n.t("vagrant_dsc.errors.manifest_missing", manifest: .to_s) end # Set absolute path to manifest file on the guest = Pathname.new(File.dirname(configuration_file)).(temp_dir).join(File.basename(configuration_file)) # Check path of the configuration data file on host if configuration_data_file != nil = Pathname.new(File.dirname(configuration_data_file)).(machine.env.root_path) = .join(File.basename(configuration_data_file)) if !.file? && !.directory? errors << I18n.t("vagrant_dsc.errors.configuration_data_missing", path: .to_s) end = Pathname.new(File.dirname(configuration_data_file)).(temp_dir).join(File.basename(configuration_data_file)) end { "dsc provisioner" => errors } end |