Class: HashiCorp::VagrantVMwareDesktop::Config
- Inherits:
-
Object
- Object
- HashiCorp::VagrantVMwareDesktop::Config
- Defined in:
- lib/vagrant-vmware-desktop/config.rb
Constant Summary collapse
- VALID_ALLOWLIST_VERIFIED_VALUES =
Valid list of values for allowlist verified
[true, false, :disable_warning].freeze
- DEFAULT_UTILITY_HOST =
Defaults for connecting to the utility service
"127.0.0.1".freeze
- DEFAULT_UTILITY_PORT =
9922
- VMWARE_MAC_OUI =
VMware organizationally unique identifier. MAC needs to start with this value to work.
"00:50:56".freeze
- VMWARE_MAC_PATTERN =
Regexp pattern for matching valid VMware OUI
/^#{Regexp.escape(VMWARE_MAC_OUI)}/
- MAC_ADDRESS_PATTERN =
Regexp pattern for matching valid MAC addresses
/^([0-9A-F]{2}:){5}[0-9A-F]{2}$/
Instance Attribute Summary collapse
-
#allowlist_verified ⇒ Boolean, Symbol
Boolean value to flag if this VMware box has been properly configured for allowed VMX settings.
-
#base_address ⇒ String
Set a specific address for the guest which should be reserved from the DHCP server.
-
#base_mac ⇒ String
Set a custom MAC address for the default NAT interface.
-
#clone_directory ⇒ String
If set, the VM will be cloned to this directory rather than in the “.vagrant” directory.
-
#enable_vmrun_ip_lookup ⇒ Boolean
If set to ‘true`, then Vagrant attempts to use `vmrun getGuestIPAddress` to look up the guest’s IP, and will fall back to VMX + DHCP lease file parsing only if that fails.
-
#force_vmware_license ⇒ String
Can be used to override the user VMware license information detected by the Vagrant VMware utility.
-
#functional_hgfs ⇒ Boolean
If set, VMware synced folders will be attempted.
-
#gui ⇒ Boolean
If set to ‘true`, then VMware VM will be launched with a GUI.
-
#linked_clone ⇒ Boolean
If set to ‘true`, then VMware VM will be cloned using a linked clone.
-
#nat_device ⇒ String
Device to use for NAT interface.
-
#network_adapters ⇒ Hash
readonly
The defined network adapters for the VMware machine.
-
#port_forward_network_pause ⇒ Integer
Integer value of the number of seconds to pause after applying port forwarding configuration.
-
#shared_folder_special_char ⇒ String
This is the character that will be used to replace any ‘/’ characters within shared folders to build the ID.
-
#ssh_info_public ⇒ Boolean
Use the public IP address and port for connecting to the guest VM.
-
#unmount_default_hgfs ⇒ Boolean
If set, the default mount point used by open-vm-tools will be unmounted.
-
#utility_certificate_path ⇒ String
Path to the certificate used when connecting to the utility service.
-
#utility_host ⇒ String
Host for connecting to the utility service.
-
#utility_port ⇒ Integer
Port for connecting to the utility service.
-
#verify_vmnet ⇒ Boolean
If set to ‘true`, then Vagrant verifies whether the vmnet devices are healthy before using them.
-
#vmx ⇒ Hash<String, String>
readonly
Hash of VMX key/values to set or unset.
Instance Method Summary collapse
-
#cpus=(count) ⇒ Object
Shortcut for setting CPU count for the virtual machine.
-
#detect_certificate_path ⇒ Object
Locate directory with utility service certificate files.
-
#finalize! ⇒ Object
This is the hook that is called to finalize the object before it is put into use.
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#memory=(size) ⇒ Object
Sets the memory (in megabytes).
- #merge(other) ⇒ Object
-
#network_adapter(slot, type, options = nil) ⇒ Object
This defines a network adapter for the VM in order to provide networking access to the machine.
-
#validate(machine) ⇒ Object
This is called to validate the configuration for the VMware adapter.
-
#whitelist_verified ⇒ Boolean, Symbol
Boolean value to flag if this VMware box has been properly configured for whitelisted VMX settings.
-
#whitelist_verified=(value) ⇒ Boolean, Symbol
Boolean value to flag if this VMware box has been properly configured for whitelisted VMX settings.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
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 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 155 def initialize @allowlist_verified = UNSET_VALUE @base_address = UNSET_VALUE @base_mac = UNSET_VALUE @clone_directory = UNSET_VALUE @functional_hgfs = UNSET_VALUE @unmount_default_hgfs = UNSET_VALUE @enable_vmrun_ip_lookup = UNSET_VALUE @gui = UNSET_VALUE @force_vmware_license = UNSET_VALUE @linked_clone = UNSET_VALUE @nat_device = UNSET_VALUE @network_adapters = {} @shared_folder_special_char = UNSET_VALUE @verify_vmnet = UNSET_VALUE @vmx = {} @port_forward_network_pause = UNSET_VALUE @ssh_info_public = UNSET_VALUE @utility_host = UNSET_VALUE @utility_port = UNSET_VALUE @utility_certificate_path = UNSET_VALUE @logger = Log4r::Logger.new("hashicorp::provider::vmware::config") # Setup a NAT adapter by default network_adapter(0, :nat, :auto_config => false) end |
Instance Attribute Details
#allowlist_verified ⇒ Boolean, Symbol
deprecated in favor of ‘:allowlist_verified`
Boolean value to flag if this VMware box has been properly configured for allowed VMX settings
31 32 33 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 31 def allowlist_verified @allowlist_verified end |
#base_address ⇒ String
Set a specific address for the guest which should be reserved from the DHCP server. Requires the ‘base_mac` to be set.
37 38 39 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 37 def base_address @base_address end |
#base_mac ⇒ String
Set a custom MAC address for the default NAT interface
42 43 44 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 42 def base_mac @base_mac end |
#clone_directory ⇒ String
If set, the VM will be cloned to this directory rather than in the “.vagrant” directory. This is useful for backup reasons (to specifically NOT back up the VM).
49 50 51 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 49 def clone_directory @clone_directory end |
#enable_vmrun_ip_lookup ⇒ Boolean
If set to ‘true`, then Vagrant attempts to use `vmrun getGuestIPAddress` to look up the guest’s IP, and will fall back to VMX + DHCP lease file parsing only if that fails. This is the default.
If set to ‘false`, then Vagrant will skip the `getGuestIPAddress` attempt.
59 60 61 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 59 def enable_vmrun_ip_lookup @enable_vmrun_ip_lookup end |
#force_vmware_license ⇒ String
Can be used to override the user VMware license information detected by the Vagrant VMware utility. This should not be visible to the public, but should be accessible to allow for workarounds and debugging.
67 68 69 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 67 def force_vmware_license @force_vmware_license end |
#functional_hgfs ⇒ Boolean
If set, VMware synced folders will be attempted.
72 73 74 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 72 def functional_hgfs @functional_hgfs end |
#gui ⇒ Boolean
If set to ‘true`, then VMware VM will be launched with a GUI.
77 78 79 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 77 def gui @gui end |
#linked_clone ⇒ Boolean
If set to ‘true`, then VMware VM will be cloned using a linked clone
82 83 84 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 82 def linked_clone @linked_clone end |
#nat_device ⇒ String
Device to use for NAT interface. By default the NAT interface will be detected automatically.
88 89 90 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 88 def nat_device @nat_device end |
#network_adapters ⇒ Hash (readonly)
The defined network adapters for the VMware machine.
93 94 95 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 93 def network_adapters @network_adapters end |
#port_forward_network_pause ⇒ Integer
Integer value of the number of seconds to pause after applying port forwarding configuration. This gives time for the guest to re-aquire a DHCP address if it detects a lost connection and drops its current IP address when the VMware network service is restarted
101 102 103 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 101 def port_forward_network_pause @port_forward_network_pause end |
#shared_folder_special_char ⇒ String
This is the character that will be used to replace any ‘/’ characters within shared folders to build the ID. WARNING: Modifying this is for ADVANCED usage only and can very easily cause the provider to break.
109 110 111 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 109 def shared_folder_special_char @shared_folder_special_char end |
#ssh_info_public ⇒ Boolean
Use the public IP address and port for connecting to the guest VM. By default this is false which directs the SSH connection through the forwarded SSH port on the localhost.
116 117 118 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 116 def ssh_info_public @ssh_info_public end |
#unmount_default_hgfs ⇒ Boolean
If set, the default mount point used by open-vm-tools will be unmounted.
122 123 124 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 122 def unmount_default_hgfs @unmount_default_hgfs end |
#utility_certificate_path ⇒ String
Path to the certificate used when connecting to the utility service
137 138 139 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 137 def utility_certificate_path @utility_certificate_path end |
#utility_host ⇒ String
Host for connecting to the utility service
127 128 129 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 127 def utility_host @utility_host end |
#utility_port ⇒ Integer
Port for connecting to the utility service
132 133 134 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 132 def utility_port @utility_port end |
#verify_vmnet ⇒ Boolean
If set to ‘true`, then Vagrant verifies whether the vmnet devices are healthy before using them. This is the default behavior.
Setting this to ‘false` skips the verify behavior, which might in some cases allow Vagrant to boot machines in a mostly-working state, skipping code that would proactively bail out.
147 148 149 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 147 def verify_vmnet @verify_vmnet end |
#vmx ⇒ Hash<String, String> (readonly)
Hash of VMX key/values to set or unset. The keys should be strings. If the value is nil then the key will be deleted.
153 154 155 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 153 def vmx @vmx end |
Instance Method Details
#cpus=(count) ⇒ Object
Shortcut for setting CPU count for the virtual machine.
195 196 197 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 195 def cpus=(count) vmx["numvcpus"] = count.to_s end |
#detect_certificate_path ⇒ Object
Locate directory with utility service certificate files. Error if path cannot be located
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 355 def detect_certificate_path if Vagrant::Util::Platform.windows? || VagrantVMwareDesktop.wsl? sysdrv = ENV.fetch("SYSTEMDRIVE", "C:") spath = ["HashiCorp", "vagrant-vmware-desktop", "certificates"] path = nil # NOTE: This directory is created by the utility service during # certificate installation. While the HashiCorp subdirectory is # specified as camel cased on creation, it ends up as all lower. # This presents a problem within the WSL as the path becomes # case sensitive. Both regular and all lower subdirectory # paths are checked from the ProgramData directory to prevent # future issues where the directory may be properly camel cased. [spath, spath.map(&:downcase)].each do |path_parts| path = VagrantVMwareDesktop.windows_to_wsl_path( File.join(sysdrv, "ProgramData", *path_parts) ) break if File.exist?(path) end path else "/opt/vagrant-vmware-desktop/certificates" end end |
#finalize! ⇒ Object
This is the hook that is called to finalize the object before it is put into use.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 249 def finalize! @clone_directory = nil if @clone_directory == UNSET_VALUE @clone_directory ||= ENV["VAGRANT_VMWARE_CLONE_DIRECTORY"] @enable_vmrun_ip_lookup = true if @enable_vmrun_ip_lookup == UNSET_VALUE @functional_hgfs = true if @functional_hgfs == UNSET_VALUE @unmount_default_hgfs = true if @unmount_default_hgfs == UNSET_VALUE # Default is to not show a GUI @gui = false if @gui == UNSET_VALUE if @shared_folder_special_char == UNSET_VALUE @shared_folder_special_char = '-' end if @nat_device == UNSET_VALUE @nat_device = nil else @nat_device = @nat_device.to_s end @verify_vmnet = true if @verify_vmnet == UNSET_VALUE @linked_clone = true if @linked_clone == UNSET_VALUE @allowlist_verified = false if @allowlist_verified == UNSET_VALUE @port_forward_network_pause = 0 if @port_forward_network_pause == UNSET_VALUE @ssh_info_public = false if @ssh_info_public == UNSET_VALUE @utility_host = DEFAULT_UTILITY_HOST if @utility_host == UNSET_VALUE @utility_port = DEFAULT_UTILITY_PORT if @utility_port == UNSET_VALUE if @utility_certificate_path == UNSET_VALUE @utility_certificate_path = detect_certificate_path end if @base_mac == UNSET_VALUE @base_mac = nil else @base_mac = @base_mac.to_s.upcase if !@base_mac.include?(":") @base_mac = @base_mac.scan(/../).join(":") end network_adapters[0].last[:mac_address] = @base_mac end @base_address = nil if @base_address == UNSET_VALUE @force_vmware_license = nil if @force_vmware_license == UNSET_VALUE @clone_directory = VagrantVMwareDesktop.wsl_to_windows_path(@clone_directory) if @clone_directory end |
#memory=(size) ⇒ Object
Sets the memory (in megabytes). This is shorthand for setting the VMX property directly.
203 204 205 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 203 def memory=(size) vmx["memsize"] = size.to_s end |
#merge(other) ⇒ Object
183 184 185 186 187 188 189 190 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 183 def merge(other) super.tap do |result| vmx = {} vmx.merge!(@vmx) if @vmx vmx.merge!(other.vmx) if other.vmx result.instance_variable_set(:@vmx, vmx) end end |
#network_adapter(slot, type, options = nil) ⇒ Object
This defines a network adapter for the VM in order to provide networking access to the machine.
213 214 215 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 213 def network_adapter(slot, type, =nil) @network_adapters[slot] = [type, || {}] end |
#validate(machine) ⇒ Object
This is called to validate the configuration for the VMware adapter. This is only called if we are actually booting up a VMware machine.
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 299 def validate(machine) errors = _detected_errors if @network_adapters[0][0] != :nat errors << I18n.t("hashicorp.vagrant_vmware_desktop.config.non_nat_adapter_zero") end # If the base_mac or base_address is set within the vm configuration # and has not been set within the provider config set them here. if !@base_mac && machine.config.vm.base_mac @base_mac = machine.config.vm.base_mac.to_s.upcase if !@base_mac.include?(":") @base_mac = @base_mac.scan(/../).join(":") end network_adapters[0].last[:mac_address] = @base_mac end if !@base_address && machine.config.vm.respond_to?(:base_address) && machine.config.vm.base_address @base_address = machine.config.vm.base_address end if @base_mac if @base_mac !~ MAC_ADDRESS_PATTERN errors << I18n.t("hashicorp.vagrant_vmware_desktop.config.base_mac_invalid", mac: @base_mac) end if @base_mac !~ VMWARE_MAC_PATTERN @logger.warn("Base MAC address is set but is not using the VMWare Organizationally Unique " \ "Identifier (#{VMWARE_MAC_OUI}). If networking problems persist, update the MAC address.") end end if @base_address begin IPAddr.new(@base_address) rescue IPAddr::InvalidAddressError errors << I18n.t("hashicorp.vagrant_vmware_desktop.config.base_address_invalid", address: @base_address) end end if @base_address && !@base_mac errors << I18n.t("hashicorp.vagrant_vmware_desktop.config.base_address_without_mac") end if @allowlist_verified && !VALID_ALLOWLIST_VERIFIED_VALUES.include?(@allowlist_verified) errors << I18n.t("hashicorp.vagrant_vmware_desktop.config.allowlist_verify_value_invalid", valid_values: VALID_ALLOWLIST_VERIFIED_VALUES.map(&:inspect).join(', ')) end { "VMware Desktop Provider" => errors } end |
#whitelist_verified ⇒ Boolean, Symbol
deprecated for ‘#allowlist_verified`
Boolean value to flag if this VMware box has been properly configured for whitelisted VMX settings
232 233 234 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 232 def whitelist_verified allowlist_verified end |
#whitelist_verified=(value) ⇒ Boolean, Symbol
deprecated for ‘#allowlist_verified=`
Boolean value to flag if this VMware box has been properly configured for whitelisted VMX settings
223 224 225 |
# File 'lib/vagrant-vmware-desktop/config.rb', line 223 def whitelist_verified=(value) self.allowlist_verified = value end |