vagrant-vmware-desktop 0.0.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vagrant-vmware-desktop.rb +190 -0
  3. data/lib/vagrant-vmware-desktop/action.rb +442 -0
  4. data/lib/vagrant-vmware-desktop/action/base_mac_to_ip.rb +55 -0
  5. data/lib/vagrant-vmware-desktop/action/boot.rb +26 -0
  6. data/lib/vagrant-vmware-desktop/action/check_existing_network.rb +35 -0
  7. data/lib/vagrant-vmware-desktop/action/check_vmware.rb +28 -0
  8. data/lib/vagrant-vmware-desktop/action/checkpoint.rb +86 -0
  9. data/lib/vagrant-vmware-desktop/action/clear_shared_folders.rb +25 -0
  10. data/lib/vagrant-vmware-desktop/action/common.rb +16 -0
  11. data/lib/vagrant-vmware-desktop/action/compatibility.rb +36 -0
  12. data/lib/vagrant-vmware-desktop/action/created.rb +20 -0
  13. data/lib/vagrant-vmware-desktop/action/destroy.rb +32 -0
  14. data/lib/vagrant-vmware-desktop/action/discard_suspended_state.rb +32 -0
  15. data/lib/vagrant-vmware-desktop/action/export.rb +29 -0
  16. data/lib/vagrant-vmware-desktop/action/fix_old_machine_id.rb +29 -0
  17. data/lib/vagrant-vmware-desktop/action/forward_ports.rb +110 -0
  18. data/lib/vagrant-vmware-desktop/action/halt.rb +27 -0
  19. data/lib/vagrant-vmware-desktop/action/import.rb +138 -0
  20. data/lib/vagrant-vmware-desktop/action/machine_lock.rb +26 -0
  21. data/lib/vagrant-vmware-desktop/action/message_already_running.rb +18 -0
  22. data/lib/vagrant-vmware-desktop/action/message_not_created.rb +18 -0
  23. data/lib/vagrant-vmware-desktop/action/message_not_running.rb +18 -0
  24. data/lib/vagrant-vmware-desktop/action/network.rb +339 -0
  25. data/lib/vagrant-vmware-desktop/action/package_vagrantfile.rb +46 -0
  26. data/lib/vagrant-vmware-desktop/action/prepare_forwarded_port_collision_params.rb +28 -0
  27. data/lib/vagrant-vmware-desktop/action/prepare_nfs_settings.rb +43 -0
  28. data/lib/vagrant-vmware-desktop/action/prepare_synced_folder_cleanup.rb +19 -0
  29. data/lib/vagrant-vmware-desktop/action/prune_forwarded_ports.rb +30 -0
  30. data/lib/vagrant-vmware-desktop/action/prune_nfs_exports.rb +22 -0
  31. data/lib/vagrant-vmware-desktop/action/running.rb +20 -0
  32. data/lib/vagrant-vmware-desktop/action/set_display_name.rb +37 -0
  33. data/lib/vagrant-vmware-desktop/action/share_folders.rb +97 -0
  34. data/lib/vagrant-vmware-desktop/action/snapshot_delete.rb +26 -0
  35. data/lib/vagrant-vmware-desktop/action/snapshot_restore.rb +26 -0
  36. data/lib/vagrant-vmware-desktop/action/snapshot_save.rb +26 -0
  37. data/lib/vagrant-vmware-desktop/action/suspend.rb +26 -0
  38. data/lib/vagrant-vmware-desktop/action/suspended.rb +24 -0
  39. data/lib/vagrant-vmware-desktop/action/vmx_modify.rb +39 -0
  40. data/lib/vagrant-vmware-desktop/action/wait_for_address.rb +31 -0
  41. data/lib/vagrant-vmware-desktop/action/wait_for_communicator_compat.rb +32 -0
  42. data/lib/vagrant-vmware-desktop/action/wait_for_vmx_halt.rb +35 -0
  43. data/lib/vagrant-vmware-desktop/cap/disk.rb +287 -0
  44. data/lib/vagrant-vmware-desktop/cap/provider.rb +37 -0
  45. data/lib/vagrant-vmware-desktop/cap/snapshot.rb +41 -0
  46. data/lib/vagrant-vmware-desktop/checkpoint_client.rb +203 -0
  47. data/lib/vagrant-vmware-desktop/config.rb +377 -0
  48. data/lib/vagrant-vmware-desktop/constants.rb +16 -0
  49. data/lib/vagrant-vmware-desktop/driver.rb +15 -0
  50. data/lib/vagrant-vmware-desktop/driver/base.rb +1356 -0
  51. data/lib/vagrant-vmware-desktop/errors.rb +342 -0
  52. data/lib/vagrant-vmware-desktop/guest_cap/linux/mount_vmware_shared_folder.rb +158 -0
  53. data/lib/vagrant-vmware-desktop/guest_cap/linux/verify_vmware_hgfs.rb +27 -0
  54. data/lib/vagrant-vmware-desktop/helper/lock.rb +26 -0
  55. data/lib/vagrant-vmware-desktop/helper/routing_table.rb +182 -0
  56. data/lib/vagrant-vmware-desktop/helper/vagrant_utility.rb +185 -0
  57. data/lib/vagrant-vmware-desktop/plugin.rb +148 -0
  58. data/lib/vagrant-vmware-desktop/provider.rb +96 -0
  59. data/lib/vagrant-vmware-desktop/setup_plugin.rb +24 -0
  60. data/lib/vagrant-vmware-desktop/synced_folder.rb +93 -0
  61. data/locales/en.yml +634 -0
  62. metadata +71 -17
@@ -0,0 +1,37 @@
1
+ require "json"
2
+
3
+ module HashiCorp
4
+ module VagrantVMwareDesktop
5
+ module Cap
6
+ module Provider
7
+
8
+ def self.forwarded_ports(machine)
9
+ path = machine.data_dir.join("forwarded_ports")
10
+ return JSON.parse(path.read) if path.file?
11
+ {}
12
+ end
13
+
14
+ def self.public_address(machine)
15
+ guest_ip = nil
16
+ 5.times do |_|
17
+ guest_ip = machine.provider.driver.read_ip(
18
+ machine.provider_config.enable_vmrun_ip_lookup
19
+ )
20
+ break if guest_ip
21
+ sleep 2
22
+ end
23
+
24
+ guest_ip
25
+ end
26
+
27
+ def self.nic_mac_addresses(machine)
28
+ machine.provider.driver.read_mac_addresses
29
+ end
30
+
31
+ def self.scrub_forwarded_ports(machine)
32
+ machine.provider.driver.scrub_forwarded_ports
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,41 @@
1
+ module HashiCorp
2
+ module VagrantVMwareDesktop
3
+ module Cap
4
+ module Snapshot
5
+
6
+ @@logger = Log4r::Logger.new("hashicorp::provider::vmware::cap::snapshot")
7
+
8
+ # List snapshots
9
+ #
10
+ # @param [Vagrant::Machine] machine - the current machine
11
+ # @return [List<String>] - snapshot names
12
+ def self.snapshot_list(machine)
13
+ machine.provider.driver.snapshot_tree
14
+ end
15
+
16
+ # Delete all snapshots for the machine
17
+ #
18
+ # @param [Vagrant::Machine] machine - the current machine
19
+ def self.delete_all_snapshots(machine)
20
+ # To delete a snapshot with children of the same name, use the
21
+ # full path to the snapshot. eg. /clone/clone if the machine
22
+ # has 2 snapshots called "clone"
23
+ snapshots = machine.provider.driver.snapshot_tree
24
+ snapshots.sort {|x, y| y.length <=> x.length}.each do |snapshot|
25
+ @@logger.info("Deleting snapshot #{snapshot}")
26
+ machine.provider.driver.snapshot_delete(snapshot)
27
+ end
28
+ end
29
+
30
+ # Delete a given snapstho
31
+ #
32
+ # @param [Vagrant::Machine] machine - the current machine
33
+ # @param [String] snapshot_name - name of the snapshot to delete
34
+ def self.delete_snapshot(machine, snapshot_name)
35
+ @@logger.info("Deleting snapshot #{snapshot_name}")
36
+ machine.provider.driver.snapshot_delete(snapshot_name)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,203 @@
1
+ require "log4r"
2
+ require "singleton"
3
+ require "vagrant-vmware-desktop/config"
4
+ require "vagrant-vmware-desktop/constants"
5
+
6
+ module HashiCorp
7
+ module VagrantVMwareDesktop
8
+ class CheckpointClient
9
+
10
+ include Singleton
11
+
12
+ # Maximum number of seconds to wait for check to complete
13
+ CHECKPOINT_TIMEOUT = 10
14
+
15
+ # @return [Log4r::Logger]
16
+ attr_reader :logger
17
+
18
+ # @return [Boolean]
19
+ attr_reader :enabled
20
+
21
+ # @return [Hash]
22
+ attr_reader :files
23
+
24
+ # @return [Vagrant::Environment]
25
+ attr_reader :env
26
+
27
+ def initialize
28
+ @logger = Log4r::Logger.new("hashicorp::provider::vmware::checkpoint_client")
29
+ @enabled = false
30
+ end
31
+
32
+ # Setup will attempt to load the checkpoint library and log if
33
+ # it is not found. Checkpoint should be around as it is a
34
+ # dependency of Vagrant, but if it's not, it shouldn't be a
35
+ # show stopper
36
+ #
37
+ # @param [Vagrant::Environment] env
38
+ # @return [self]
39
+ def setup(env)
40
+ begin
41
+ require "checkpoint"
42
+ @enabled = true
43
+ rescue LoadError
44
+ @logger.debug("checkpoint library not found. disabling.")
45
+ end
46
+ if ENV["VAGRANT_CHECKPOINT_DISABLE"]
47
+ @logger.debug("checkpoint disabled via explicit request with environment variable")
48
+ @enabled = false
49
+ end
50
+ @files = {
51
+ plugin_signature: env.data_dir.join("checkpoint_signature-vmp"),
52
+ plugin_cache: env.data_dir.join("checkpoint_cache-vmp"),
53
+ utility_signature: env.data_dir.join("checkpoint_signature-vmu"),
54
+ utility_cache: env.data_dir.join("checkpoint_cache-vmu")
55
+ }
56
+ @checkpoint_threads = {}
57
+ @env = env
58
+ self
59
+ end
60
+
61
+ # Start checkpoint checks for both the plugin and utility
62
+ #
63
+ # @return [self]
64
+ def check
65
+ check_plugin
66
+ check_utility
67
+ self
68
+ end
69
+
70
+ # All checks complete
71
+ def complete?
72
+ complete_plugin? && complete_utility?
73
+ end
74
+
75
+ # Plugin check complete
76
+ def complete_plugin?
77
+ if @checkpoint_threads.key?(:plugin)
78
+ !@checkpoint_threads[:plugin].alive?
79
+ else
80
+ true
81
+ end
82
+ end
83
+
84
+ # Utility check complete
85
+ def complete_utility?
86
+ if @checkpoint_threads.key?(:utility)
87
+ !@checkpoint_threads[:utility].alive?
88
+ else
89
+ true
90
+ end
91
+ end
92
+
93
+ # Result of all checks
94
+ #
95
+ # @return [Hash]
96
+ def result
97
+ {
98
+ desktop: result_plugin,
99
+ utility: result_utility
100
+ }
101
+ end
102
+
103
+ # Get result from plugin check, wait if not complete
104
+ def result_plugin
105
+ if !enabled || !@checkpoint_threads.key?(:plugin)
106
+ nil
107
+ elsif !defined?(@result_plugin)
108
+ @checkpoint_threads[:plugin].join(CHECKPOINT_TIMEOUT)
109
+ @result_plugin = @checkpoint_threads[:result]
110
+ else
111
+ @result_plugin
112
+ end
113
+ end
114
+
115
+ # Get result from utility check, wait if not complete
116
+ def result_utility
117
+ if !enabled || !@checkpoint_threads.key?(:utility)
118
+ nil
119
+ elsif !defined?(@result_utility)
120
+ @checkpoint_threads[:utility].join(CHECKPOINT_TIMEOUT)
121
+ @result_utility = @checkpoint_threads[:result]
122
+ else
123
+ @result_utility
124
+ end
125
+ end
126
+
127
+ # Run check for plugin
128
+ #
129
+ # @return [self]
130
+ def check_plugin
131
+ if enabled && !@checkpoint_threads.key?(:plugin)
132
+ logger.debug("starting plugin check")
133
+ @checkpoint_threads[:plugin] = Thread.new do
134
+ Thread.current.abort_on_exception = false
135
+ Thread.current.report_on_exception = false
136
+ begin
137
+ Thread.current[:result] = Checkpoint.check(
138
+ product: "vagrant-vmware-desktop",
139
+ version: VERSION,
140
+ signature_file: files[:plugin_signature],
141
+ cache_file: files[:plugin_cache]
142
+ )
143
+ if Thread.current[:result].is_a?(Hash)
144
+ Thread.current[:result].merge!("installed_version" => VERSION)
145
+ else
146
+ Thread.current[:result] = nil
147
+ end
148
+ logger.debug("plugin check complete")
149
+ rescue => e
150
+ logger.debug("plugin check failure - #{e}")
151
+ end
152
+ end
153
+ end
154
+ self
155
+ end
156
+
157
+ # Run check for utility
158
+ #
159
+ # @return [self]
160
+ def check_utility
161
+ if enabled && !@checkpoint_threads.key?(:utility)
162
+ logger.debug("starting utility check")
163
+ @checkpoint_threads[:utility] = Thread.new do
164
+ Thread.current.abort_on_exception = false
165
+ Thread.current.report_on_exception = false
166
+ begin
167
+ tmp_config = Config.new
168
+ tmp_config.finalize!
169
+ driver = Driver.create(nil, tmp_config)
170
+ @logger.debug("getting utility version")
171
+ utility_version = driver.vmware_utility_version
172
+ @logger.debug("got utility version: #{utility_version.inspect}")
173
+ if utility_version
174
+ begin
175
+ @logger.debug("running utility checkpoint check")
176
+ Thread.current[:result] = Checkpoint.check(
177
+ product: "vagrant-vmware-utility",
178
+ version: utility_version,
179
+ signature_file: files[:utility_signature],
180
+ cache_file: files[:utility_cache]
181
+ )
182
+ if Thread.current[:result].is_a?(Hash)
183
+ Thread.current[:result].merge!("installed_version" => utility_version)
184
+ else
185
+ Thread.current[:result] = nil
186
+ end
187
+ logger.debug("utility check complete")
188
+ rescue => e
189
+ logger.debug("utility check failure - #{e}")
190
+ end
191
+ else
192
+ logger.debug("skipping utility checkpoint, unable to determine version")
193
+ end
194
+ rescue => e
195
+ logger.debug("utility communication error - #{e}")
196
+ end
197
+ end
198
+ end
199
+ nil
200
+ end
201
+ end
202
+ end
203
+ end
@@ -0,0 +1,377 @@
1
+ require "vagrant"
2
+ require "ipaddr"
3
+
4
+ module HashiCorp
5
+ module VagrantVMwareDesktop
6
+ class Config < Vagrant.plugin("2", :config)
7
+
8
+ # Valid list of values for allowlist verified
9
+ VALID_ALLOWLIST_VERIFIED_VALUES = [true, false, :disable_warning].freeze
10
+
11
+ # Defaults for connecting to the utility service
12
+ DEFAULT_UTILITY_HOST = "127.0.0.1".freeze
13
+ DEFAULT_UTILITY_PORT = 9922
14
+
15
+ # VMware organizationally unique identifier. MAC needs to start with this value to work.
16
+ VMWARE_MAC_OUI = "00:50:56".freeze
17
+ # Regexp pattern for matching valid VMware OUI
18
+ VMWARE_MAC_PATTERN = /^#{Regexp.escape(VMWARE_MAC_OUI)}/
19
+ # Regexp pattern for matching valid MAC addresses
20
+ MAC_ADDRESS_PATTERN = /^([0-9A-F]{2}:){5}[0-9A-F]{2}$/
21
+
22
+ # Boolean value to flag if this VMware box has been properly configured
23
+ # for allowed VMX settings
24
+ #
25
+ # @return [Boolean, Symbol] true if verified, false if unverified,
26
+ # :disable_warning if silenced
27
+ # @note deprecated in favor of `:allowlist_verified`
28
+ attr_reader :allowlist_verified
29
+
30
+ # Set a specific address for the guest which should be reserved
31
+ # from the DHCP server. Requires the `base_mac` to be set.
32
+ #
33
+ # @return [String]
34
+ attr_accessor :base_address
35
+
36
+ # Set a custom MAC address for the default NAT interface
37
+ #
38
+ # @return [String]
39
+ attr_accessor :base_mac
40
+
41
+ # If set, the VM will be cloned to this directory rather than
42
+ # in the ".vagrant" directory. This is useful for backup reasons (to
43
+ # specifically NOT back up the VM).
44
+ #
45
+ # @return [String]
46
+ attr_accessor :clone_directory
47
+
48
+ # If set to `true`, then Vagrant attempts to use `vmrun
49
+ # getGuestIPAddress` to look up the guest's IP, and will fall back to VMX
50
+ # + DHCP lease file parsing only if that fails. This is the default.
51
+ #
52
+ # If set to `false`, then Vagrant will skip the `getGuestIPAddress`
53
+ # attempt.
54
+ #
55
+ # @return [Boolean]
56
+ attr_accessor :enable_vmrun_ip_lookup
57
+
58
+ # Can be used to override the user VMware license information
59
+ # detected by the Vagrant VMware utility. This should not be
60
+ # visible to the public, but should be accessible to allow
61
+ # for workarounds and debugging.
62
+ #
63
+ # @return [String]
64
+ attr_accessor :force_vmware_license
65
+
66
+ # If set, VMware synced folders will be attempted.
67
+ #
68
+ # @return [Boolean]
69
+ attr_accessor :functional_hgfs
70
+
71
+ # If set to `true`, then VMware VM will be launched with a GUI.
72
+ #
73
+ # @return [Boolean]
74
+ attr_accessor :gui
75
+
76
+ # If set to `true`, then VMware VM will be cloned using a linked clone
77
+ #
78
+ # @return [Boolean]
79
+ attr_accessor :linked_clone
80
+
81
+ # Device to use for NAT interface. By default the NAT interface will
82
+ # be detected automatically.
83
+ #
84
+ # @return [String]
85
+ attr_accessor :nat_device
86
+
87
+ # The defined network adapters for the VMware machine.
88
+ #
89
+ # @return [Hash]
90
+ attr_reader :network_adapters
91
+
92
+ # Integer value of the number of seconds to pause after applying port
93
+ # forwarding configuration. This gives time for the guest to re-aquire
94
+ # a DHCP address if it detects a lost connection and drops its current
95
+ # IP address when the VMware network service is restarted
96
+ #
97
+ # @return [Integer]
98
+ attr_accessor :port_forward_network_pause
99
+
100
+ # This is the character that will be used to replace any '/' characters
101
+ # within shared folders to build the ID. WARNING: Modifying this is
102
+ # for ADVANCED usage only and can very easily cause the provider to
103
+ # break.
104
+ #
105
+ # @return [String]
106
+ attr_accessor :shared_folder_special_char
107
+
108
+ # Use the public IP address and port for connecting to the guest VM. By
109
+ # default this is false which directs the SSH connection through the
110
+ # forwarded SSH port on the localhost.
111
+ #
112
+ # @return [Boolean]
113
+ attr_accessor :ssh_info_public
114
+
115
+ # If set, the default mount point used by open-vm-tools will
116
+ # be unmounted.
117
+ #
118
+ # @return [Boolean]
119
+ attr_accessor :unmount_default_hgfs
120
+
121
+ # Host for connecting to the utility service
122
+ #
123
+ # @return [String]
124
+ attr_accessor :utility_host
125
+
126
+ # Port for connecting to the utility service
127
+ #
128
+ # @return [Integer]
129
+ attr_accessor :utility_port
130
+
131
+ # Path to the certificate used when connecting to the utility service
132
+ #
133
+ # @return [String]
134
+ attr_accessor :utility_certificate_path
135
+
136
+ # If set to `true`, then Vagrant verifies whether the vmnet devices are
137
+ # healthy before using them. This is the default behavior.
138
+ #
139
+ # Setting this to `false` skips the verify behavior, which might in some
140
+ # cases allow Vagrant to boot machines in a mostly-working state,
141
+ # skipping code that would proactively bail out.
142
+ #
143
+ # @return [Boolean]
144
+ attr_accessor :verify_vmnet
145
+
146
+ # Hash of VMX key/values to set or unset. The keys should be strings.
147
+ # If the value is nil then the key will be deleted.
148
+ #
149
+ # @return [Hash<String, String>]
150
+ attr_reader :vmx
151
+
152
+ def initialize
153
+ @allowlist_verified = UNSET_VALUE
154
+ @base_address = UNSET_VALUE
155
+ @base_mac = UNSET_VALUE
156
+ @clone_directory = UNSET_VALUE
157
+ @functional_hgfs = UNSET_VALUE
158
+ @unmount_default_hgfs = UNSET_VALUE
159
+ @enable_vmrun_ip_lookup = UNSET_VALUE
160
+ @gui = UNSET_VALUE
161
+ @force_vmware_license = UNSET_VALUE
162
+ @linked_clone = UNSET_VALUE
163
+ @nat_device = UNSET_VALUE
164
+ @network_adapters = {}
165
+ @shared_folder_special_char = UNSET_VALUE
166
+ @verify_vmnet = UNSET_VALUE
167
+ @vmx = {}
168
+ @port_forward_network_pause = UNSET_VALUE
169
+ @ssh_info_public = UNSET_VALUE
170
+ @utility_host = UNSET_VALUE
171
+ @utility_port = UNSET_VALUE
172
+ @utility_certificate_path = UNSET_VALUE
173
+
174
+ @logger = Log4r::Logger.new("hashicorp::provider::vmware::config")
175
+
176
+ # Setup a NAT adapter by default
177
+ network_adapter(0, :nat, :auto_config => false)
178
+ end
179
+
180
+ def merge(other)
181
+ super.tap do |result|
182
+ vmx = {}
183
+ vmx.merge!(@vmx) if @vmx
184
+ vmx.merge!(other.vmx) if other.vmx
185
+ result.instance_variable_set(:@vmx, vmx)
186
+ end
187
+ end
188
+
189
+ # Shortcut for setting CPU count for the virtual machine.
190
+ #
191
+ # @param [Integer, String] count
192
+ def cpus=(count)
193
+ vmx["numvcpus"] = count.to_s
194
+ end
195
+
196
+ # Sets the memory (in megabytes). This is shorthand for
197
+ # setting the VMX property directly.
198
+ #
199
+ # @param [String] size
200
+ def memory=(size)
201
+ vmx["memsize"] = size.to_s
202
+ end
203
+
204
+ # This defines a network adapter for the VM in order to
205
+ # provide networking access to the machine.
206
+ #
207
+ # @param [Integer] slot
208
+ # @param [Symbol] type
209
+ # @param [Hash] options The options for this network adapter.
210
+ def network_adapter(slot, type, options=nil)
211
+ @network_adapters[slot] = [type, options || {}]
212
+ end
213
+
214
+ # Boolean value to flag if this VMware box has been properly configured
215
+ # for whitelisted VMX settings
216
+ #
217
+ # @param [Boolean, Symbol] value
218
+ # @return [Boolean, Symbol] true if verified, false if unverified, :disable_warning if silenced
219
+ # @note deprecated for `#allowlist_verified=`
220
+ def whitelist_verified=(value)
221
+ self.allowlist_verified = value
222
+ end
223
+
224
+ # Boolean value to flag if this VMware box has been properly configured
225
+ # for whitelisted VMX settings
226
+ #
227
+ # @return [Boolean, Symbol] true if verified, false if unverified, :disable_warning if silenced
228
+ # @note deprecated for `#allowlist_verified`
229
+ def whitelist_verified
230
+ allowlist_verified
231
+ end
232
+
233
+ # Boolean value to flag if this VMware box has been properly configured
234
+ # for allowlisted VMX settings
235
+ #
236
+ # @param [Boolean, Symbol] value
237
+ # @return [Boolean, Symbol] true if verified, false if unverified, :disable_warning if silenced
238
+ # @note deprecated for `allowlist_verified`
239
+ def allowlist_verified=(value)
240
+ value = value.to_sym if value.is_a?(String)
241
+ @allowlist_verified = value
242
+ end
243
+
244
+ # This is the hook that is called to finalize the object before it
245
+ # is put into use.
246
+ def finalize!
247
+ @clone_directory = nil if @clone_directory == UNSET_VALUE
248
+ @clone_directory ||= ENV["VAGRANT_VMWARE_CLONE_DIRECTORY"]
249
+
250
+ @enable_vmrun_ip_lookup = true if @enable_vmrun_ip_lookup == UNSET_VALUE
251
+
252
+ @functional_hgfs = true if @functional_hgfs == UNSET_VALUE
253
+ @unmount_default_hgfs = true if @unmount_default_hgfs == UNSET_VALUE
254
+
255
+ # Default is to not show a GUI
256
+ @gui = false if @gui == UNSET_VALUE
257
+
258
+ if @shared_folder_special_char == UNSET_VALUE
259
+ @shared_folder_special_char = '-'
260
+ end
261
+
262
+ if @nat_device == UNSET_VALUE
263
+ @nat_device = nil
264
+ else
265
+ @nat_device = @nat_device.to_s
266
+ end
267
+
268
+ @verify_vmnet = true if @verify_vmnet == UNSET_VALUE
269
+ @linked_clone = true if @linked_clone == UNSET_VALUE
270
+ @allowlist_verified = false if @allowlist_verified == UNSET_VALUE
271
+ @port_forward_network_pause = 0 if @port_forward_network_pause == UNSET_VALUE
272
+ @ssh_info_public = false if @ssh_info_public == UNSET_VALUE
273
+ @utility_host = DEFAULT_UTILITY_HOST if @utility_host == UNSET_VALUE
274
+ @utility_port = DEFAULT_UTILITY_PORT if @utility_port == UNSET_VALUE
275
+ if @utility_certificate_path == UNSET_VALUE
276
+ @utility_certificate_path = detect_certificate_path
277
+ end
278
+
279
+ if @base_mac == UNSET_VALUE
280
+ @base_mac = nil
281
+ else
282
+ @base_mac = @base_mac.to_s.upcase
283
+ if !@base_mac.include?(":")
284
+ @base_mac = @base_mac.scan(/../).join(":")
285
+ end
286
+ network_adapters[0].last[:mac_address] = @base_mac
287
+ end
288
+ @base_address = nil if @base_address == UNSET_VALUE
289
+ @force_vmware_license = nil if @force_vmware_license == UNSET_VALUE
290
+ @clone_directory = VagrantVMwareDesktop.wsl_to_windows_path(@clone_directory) if @clone_directory
291
+ end
292
+
293
+ # This is called to validate the configuration for the VMware
294
+ # adapter. This is only called if we are actually booting up a VMware
295
+ # machine.
296
+ def validate(machine)
297
+ errors = _detected_errors
298
+
299
+ if @network_adapters[0][0] != :nat
300
+ errors << I18n.t("hashicorp.vagrant_vmware_desktop.config.non_nat_adapter_zero")
301
+ end
302
+
303
+ # If the base_mac or base_address is set within the vm configuration
304
+ # and has not been set within the provider config set them here.
305
+ if !@base_mac && machine.config.vm.base_mac
306
+ @base_mac = machine.config.vm.base_mac.to_s.upcase
307
+ if !@base_mac.include?(":")
308
+ @base_mac = @base_mac.scan(/../).join(":")
309
+ end
310
+ network_adapters[0].last[:mac_address] = @base_mac
311
+ end
312
+
313
+ if !@base_address && machine.config.vm.respond_to?(:base_address) && machine.config.vm.base_address
314
+ @base_address = machine.config.vm.base_address
315
+ end
316
+
317
+ if @base_mac
318
+ if @base_mac !~ MAC_ADDRESS_PATTERN
319
+ errors << I18n.t("hashicorp.vagrant_vmware_desktop.config.base_mac_invalid",
320
+ mac: @base_mac)
321
+ end
322
+
323
+ if @base_mac !~ VMWARE_MAC_PATTERN
324
+ @logger.warn("Base MAC address is set but is not using the VMWare Organizationally Unique " \
325
+ "Identifier (#{VMWARE_MAC_OUI}). If networking problems persist, update the MAC address.")
326
+ end
327
+ end
328
+
329
+ if @base_address
330
+ begin
331
+ IPAddr.new(@base_address)
332
+ rescue IPAddr::InvalidAddressError
333
+ errors << I18n.t("hashicorp.vagrant_vmware_desktop.config.base_address_invalid",
334
+ address: @base_address)
335
+ end
336
+ end
337
+
338
+ if @base_address && !@base_mac
339
+ errors << I18n.t("hashicorp.vagrant_vmware_desktop.config.base_address_without_mac")
340
+ end
341
+
342
+ if @allowlist_verified && !VALID_ALLOWLIST_VERIFIED_VALUES.include?(@allowlist_verified)
343
+ errors << I18n.t("hashicorp.vagrant_vmware_desktop.config.allowlist_verify_value_invalid",
344
+ valid_values: VALID_ALLOWLIST_VERIFIED_VALUES.map(&:inspect).join(', '))
345
+ end
346
+
347
+ { "VMware Desktop Provider" => errors }
348
+ end
349
+
350
+ # Locate directory with utility service certificate files. Error if
351
+ # path cannot be located
352
+ def detect_certificate_path
353
+ if Vagrant::Util::Platform.windows? || VagrantVMwareDesktop.wsl?
354
+ sysdrv = ENV.fetch("SYSTEMDRIVE", "C:")
355
+ spath = ["HashiCorp", "vagrant-vmware-desktop", "certificates"]
356
+ path = nil
357
+ # NOTE: This directory is created by the utility service during
358
+ # certificate installation. While the HashiCorp subdirectory is
359
+ # specified as camel cased on creation, it ends up as all lower.
360
+ # This presents a problem within the WSL as the path becomes
361
+ # case sensitive. Both regular and all lower subdirectory
362
+ # paths are checked from the ProgramData directory to prevent
363
+ # future issues where the directory may be properly camel cased.
364
+ [spath, spath.map(&:downcase)].each do |path_parts|
365
+ path = VagrantVMwareDesktop.windows_to_wsl_path(
366
+ File.join(sysdrv, "ProgramData", *path_parts)
367
+ )
368
+ break if File.exist?(path)
369
+ end
370
+ path
371
+ else
372
+ "/opt/vagrant-vmware-desktop/certificates"
373
+ end
374
+ end
375
+ end
376
+ end
377
+ end