vagrant-vmware-desktop 0.0.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,342 @@
1
+ require "vagrant"
2
+
3
+ module HashiCorp
4
+ module VagrantVMwareDesktop
5
+ module Errors
6
+ # This is the base class for all errors within the VMware Fusion
7
+ # plugin.
8
+ class Base < Vagrant::Errors::VagrantError
9
+ error_namespace("hashicorp.vagrant_vmware_desktop.errors")
10
+
11
+ def initialize(message=nil, *args)
12
+ message ||= {}
13
+ message[:product] = PRODUCT_NAME.capitalize
14
+
15
+ super(message, *args)
16
+ end
17
+ end
18
+
19
+ class FeatureNotSupported < Base
20
+ error_key(:feature_not_supported)
21
+ end
22
+
23
+ class BoxVMXFileNotFound < Base
24
+ error_key(:box_vmx_file_not_found)
25
+ end
26
+
27
+ class CannotGetSSHInfo < Base
28
+ error_key(:cannot_get_ssh_info)
29
+ end
30
+
31
+ class CloneFolderExists < Base
32
+ error_key(:clone_folder_exists)
33
+ end
34
+
35
+ class CloneFolderNotFolder < Base
36
+ error_key(:clone_folder_not_folder)
37
+ end
38
+
39
+ class DiskNotCreated < Base
40
+ error_key(:disk_not_created)
41
+ end
42
+
43
+ class DiskNotResizedSnapshot < Base
44
+ error_key(:disk_not_resized_snapshot)
45
+ end
46
+
47
+ class MissingNATDevice < Base
48
+ error_key(:missing_nat_device)
49
+ end
50
+
51
+ class BaseAddressRange < Base
52
+ error_key(:base_address_range)
53
+ end
54
+
55
+ class DestroyInvalidState < Base
56
+ error_key(:destroy_invalid_state)
57
+ end
58
+
59
+ class DriverInvalidResponse < Base
60
+ error_key(:driver_invalid_response)
61
+ end
62
+
63
+ class DriverClonePermissionFailure < Base
64
+ error_key(:driver_clone_permission_failure)
65
+ end
66
+
67
+ class DriverDHCPLeasesReadPerms < Base
68
+ error_key(:driver_dhcp_leases_read_perms)
69
+ end
70
+
71
+ class DriverMissingDHCPLeasesFile < Base
72
+ error_key(:driver_missing_dhcp_leases_file)
73
+ end
74
+
75
+ class DriverMissingFPNatConf < Base
76
+ error_key(:driver_missing_fp_nat_conf)
77
+ end
78
+
79
+ class DriverMissingNetworkingFile < Base
80
+ error_key(:driver_missing_networking_file)
81
+ end
82
+
83
+ class DriverMissingServiceStarter < Base
84
+ error_key(:driver_missing_service_starter)
85
+ end
86
+
87
+ class DriverMissingVMNetCLI < Base
88
+ error_key(:driver_missing_vmnet_cli)
89
+ end
90
+
91
+ class DriverMissingVMX < Base
92
+ error_key(:driver_missing_vmx)
93
+ end
94
+
95
+ class DriverMissingVMXCLI < Base
96
+ error_key(:driver_missing_vmx_cli)
97
+ end
98
+
99
+ class DriverNetworkingFileNotFound < Base
100
+ error_key(:driver_networking_file_not_found)
101
+ end
102
+
103
+ class DriverNetworkingFileBadPermissions < Base
104
+ error_key(:driver_networking_file_bad_permissions)
105
+ end
106
+
107
+ class DriverReadVersionFailed < Base
108
+ error_key(:driver_read_version_failed)
109
+ end
110
+
111
+ class DriverVMNetCommandFailed < Base; end
112
+
113
+ class DriverVMNetConfigureFailed < DriverVMNetCommandFailed
114
+ error_key(:driver_vmnet_configure_failed)
115
+ end
116
+
117
+ class DriverVMNetStartFailed < DriverVMNetCommandFailed
118
+ error_key(:driver_vmnet_start_failed)
119
+ end
120
+
121
+ class DriverVMNetStopFailed < DriverVMNetCommandFailed
122
+ error_key(:driver_vmnet_stop_failed)
123
+ end
124
+
125
+ class ForwardedPortsCollideWithExistingNAT < Base
126
+ error_key(:forwarded_ports_collide_with_existing_nat)
127
+ end
128
+
129
+ class ForwardedPortNoGuestIP < Base
130
+ error_key(:forwarded_port_no_guest_ip)
131
+ end
132
+
133
+ class FusionUpgradeRequired < Base
134
+ error_key(:fusion_upgrade_required)
135
+ end
136
+
137
+ class GuestMissingHGFS < Base
138
+ error_key(:guest_missing_hgfs)
139
+ end
140
+
141
+ class HelperFailed < Base
142
+ error_key(:helper_failed)
143
+ end
144
+
145
+ class HelperInstallFailed < Base
146
+ error_key(:helper_install_failed)
147
+ end
148
+
149
+ class HelperInvalidCommand < Base
150
+ error_key(:helper_invalid_command)
151
+ end
152
+
153
+ class HelperNotRoot < Base
154
+ error_key(:helper_not_root)
155
+ end
156
+
157
+ class HelperRequiresCommand < Base
158
+ error_key(:helper_requires_command)
159
+ end
160
+
161
+ class HelperRequiresDataFile < Base
162
+ error_key(:helper_requires_data_file)
163
+ end
164
+
165
+ class HelperRequiresReinstall < Base
166
+ error_key(:helper_requires_reinstall)
167
+ end
168
+
169
+ class HelperWrapperMissing < Base
170
+ error_key(:helper_wrapper_missing)
171
+ end
172
+
173
+ class LinuxMountGIDFailed < Base
174
+ error_key(:linux_mount_gid_failed)
175
+ end
176
+
177
+ class LinuxMountUIDFailed < Base
178
+ error_key(:linux_mount_uid_failed)
179
+ end
180
+
181
+ class LinuxServiceInitScriptMissing < Base
182
+ error_key(:linux_service_init_script_missing)
183
+ end
184
+
185
+ class NetworkingFileMissingVersion < Base
186
+ error_key(:networking_file_missing_version)
187
+ end
188
+
189
+ class NetworkingFileUnsupportedVersion < Base
190
+ error_key(:networking_file_unsupported_version)
191
+ end
192
+
193
+ class NetworkingHostOnlyCollision < Base
194
+ error_key(:networking_host_only_collision)
195
+ end
196
+
197
+ class NetworkingNoSlotsForHighLevel < Base
198
+ error_key(:networking_no_slots_for_high_level)
199
+ end
200
+
201
+ class NFSNoNetwork < Base
202
+ error_key(:nfs_no_network)
203
+ end
204
+
205
+ class PackageNotSupported < Base
206
+ error_key(:package_not_supported)
207
+ end
208
+
209
+ class RoutingTableError < Base; end
210
+
211
+ class RoutingTableCommandNotFound < RoutingTableError
212
+ error_key(:routing_table_command_not_found)
213
+ end
214
+
215
+ class RoutingTableLoadError < RoutingTableError
216
+ error_key(:routing_table_load_error)
217
+ end
218
+
219
+ class RoutingTableUnsupportedOS < RoutingTableError
220
+ error_key(:routing_table_unsupported_os)
221
+ end
222
+
223
+ class SharedFolderSymlinkFailed < Base
224
+ error_key(:shared_folder_symlink_failed)
225
+ end
226
+
227
+ class SingleMachineLock < Base
228
+ error_key(:single_machine_lock)
229
+ end
230
+
231
+ class StartTimeout < Base
232
+ error_key(:start_timeout)
233
+ end
234
+
235
+ class UtilityUpgradeRequired < Base
236
+ error_key(:utility_upgrade_required)
237
+ end
238
+
239
+ class VMNetDeviceCreateFailed < Base
240
+ error_key(:vmnet_device_create_failed)
241
+ end
242
+
243
+ class VMNetDeviceRouteConflict < Base
244
+ error_key(:vmnet_device_route_conflict)
245
+ end
246
+
247
+ class VMNetDevicesWontStart < Base
248
+ error_key(:vmnet_devices_wont_start)
249
+ end
250
+
251
+ class VMNetSlotsFull < Base
252
+ error_key(:vmnet_slots_full)
253
+ end
254
+
255
+ class VMNetNoIPV6 < Base
256
+ error_key(:vmnet_no_ipv6)
257
+ end
258
+
259
+ class VMExecError < Base
260
+ error_key(:vmexec_error)
261
+ end
262
+
263
+ class VMRunError < Base
264
+ error_key(:vmrun_error)
265
+ end
266
+
267
+ class VMRunNotFound < Base
268
+ error_key(:vmrun_not_Found)
269
+ end
270
+
271
+ class VMwareLinuxServiceWontStart < Base
272
+ error_key(:vmware_linux_service_wont_start)
273
+ end
274
+
275
+ class VnetLibError < Base
276
+ error_key(:vnetlib_error)
277
+ end
278
+
279
+ class VnetLibNotFound < Base
280
+ error_key(:vnetlib_not_found)
281
+ end
282
+
283
+ class WorkstationUpgradeRequired < Base
284
+ error_key(:workstation_upgrade_required)
285
+ end
286
+
287
+ ## Driver API
288
+
289
+ class DriverAPICertificateError < Base
290
+ error_key(:driver_api_certificate_error)
291
+ end
292
+
293
+ class DriverAPIKeyError < Base
294
+ error_key(:driver_api_key_error)
295
+ end
296
+
297
+ class DriverAPIConnectionFailed < Base
298
+ error_key(:driver_api_connection_failed)
299
+ end
300
+
301
+ class DriverAPIRequestUnexpectedError < Base
302
+ error_key(:driver_api_request_unexpected_error)
303
+ end
304
+
305
+ class DriverAPIInvalidResponse < Base
306
+ error_key(:driver_api_invalid_response)
307
+ end
308
+
309
+ class DriverAPIPortForwardListError < Base
310
+ error_key(:driver_api_port_forward_list_error)
311
+ end
312
+
313
+ class DriverAPIDeviceCreateError < Base
314
+ error_key(:driver_api_device_create_error)
315
+ end
316
+
317
+ class DriverAPIPortForwardError < Base
318
+ error_key(:driver_api_port_forward_error)
319
+ end
320
+
321
+ class DriverAPIPortForwardPruneError < Base
322
+ error_key(:driver_api_port_forward_prune_error)
323
+ end
324
+
325
+ class DriverAPIDeviceListError < Base
326
+ error_key(:driver_api_device_list_error)
327
+ end
328
+
329
+ class DriverAPIVMwareVersionDetectionError < Base
330
+ error_key(:driver_api_vmware_version_detection_error)
331
+ end
332
+
333
+ class DriverAPIVMwarePathsDetectionError < Base
334
+ error_key(:driver_api_vmware_paths_detection_error)
335
+ end
336
+
337
+ class DriverAPIAddressReservationError < Base
338
+ error_key(:driver_api_address_reservation_error)
339
+ end
340
+ end
341
+ end
342
+ end
@@ -0,0 +1,158 @@
1
+ module HashiCorp
2
+ module VagrantVMwareDesktop
3
+ module GuestCap
4
+ module Linux
5
+ class MountVMwareSharedFolder
6
+ # Root location for vagrant generated vmhgfs mounts
7
+ VAGRANT_ROOT_MOUNT_POINT = "/mnt/vagrant-mounts".freeze
8
+
9
+ def self.mount_vmware_shared_folder(machine, name, guestpath, options)
10
+ expanded_guest_path = machine.guest.capability(
11
+ :shell_expand_guest_path, guestpath)
12
+
13
+ # Determine if we're using the HGFS kernel module or open-vm-tools.
14
+ # We prefer to use the kernel module so we test for that.
15
+ kernel_mod = machine.communicate.test("PATH=\"/sbin:$PATH\" lsmod | grep -i '^vmhgfs'")
16
+
17
+ # The user can also override the mount strategy used by specifying a
18
+ # vmware__mount_strategy option (the prefix is removed by Vagrant core).
19
+ kernel_mod = options[:mount_strategy].to_s == "kernel" if options[:mount_strategy]
20
+
21
+ # NOTE: This is pulled directly from the linux cap within vagrant proper. Once it is properly
22
+ # extracted in vagrant, this should just be a method call for consistency.
23
+ if options[:owner].to_i.to_s == options[:owner].to_s
24
+ mount_uid = options[:owner]
25
+ else
26
+ output = ""
27
+ uid_command = "id -u #{options[:owner]}"
28
+ machine.communicate.execute(uid_command, error_check: false) { |type, data|
29
+ output << data if type == :stdout
30
+ }
31
+ mount_uid = output.strip
32
+ if mount_uid.to_i.to_s != mount_uid
33
+ raise Errors::LinuxMountUIDFailed,
34
+ folder_name: name
35
+ end
36
+ end
37
+
38
+ if options[:group].to_i.to_s == options[:group].to_s
39
+ mount_gid = options[:group]
40
+ else
41
+ output = ""
42
+ gid_command = "getent group #{options[:group]}"
43
+ machine.communicate.execute(gid_command, error_check: false) { |type, data|
44
+ output << data if type == :stdout
45
+ }
46
+ mount_gid = output.strip.split(':').at(2)
47
+ if mount_gid.to_i.to_s != mount_gid && options[:owner] == options[:group]
48
+ output = ""
49
+ result = machine.communicate.execute("id -g #{options[:owner]}", error_check: false) { |type, data|
50
+ output << data if type == :stdout
51
+ }
52
+ mount_gid = output.strip
53
+ end
54
+ if mount_gid.to_i.to_s != mount_gid
55
+ raise Errors::LinuxMountGIDFailed,
56
+ folder_name: name
57
+ end
58
+ end
59
+ uid = mount_uid
60
+ gid = mount_gid
61
+
62
+ # Create the guest path if it doesn't exist
63
+ machine.communicate.sudo(
64
+ "test -L #{expanded_guest_path} && rm -rf #{expanded_guest_path}",
65
+ error_check: false)
66
+ machine.communicate.sudo("mkdir -p #{expanded_guest_path}")
67
+
68
+ # If the kernel module is in use, continue using existing mount strategy. If the
69
+ # kernel module is not in use, then we can assume the open-vm-tools are in use
70
+ # which will automatically mount the share into the /mnt/hgfs directory
71
+ if kernel_mod
72
+ # Expand the name to the proper VMware name
73
+ name = ".host:/#{name}"
74
+
75
+ # Start building the mount options starting with the basic UID/GID
76
+ mount_options = "-o uid=#{uid},gid=#{gid}"
77
+
78
+ # Options
79
+ mount_options += ",#{options[:extra]}" if options[:extra]
80
+ mount_options += ",#{options[:mount_options].join(",")}" if options[:mount_options]
81
+
82
+ # Build the full command
83
+ mount_command = "mount -t vmhgfs"
84
+ mount_command = "#{mount_command} #{mount_options} '#{name}' '#{expanded_guest_path}'"
85
+ # Attempt to mount the folder. We retry here a few times because
86
+ # it can fail early on.
87
+ attempts = 0
88
+ while true
89
+ success = true
90
+ machine.communicate.sudo(mount_command) do |type, data|
91
+ success = false if type == :stderr && data =~ /No such device/i
92
+
93
+ # Sometimes it takes extra time for the `vmhgfs` filesystem
94
+ # type to become available for use.
95
+ success = false if type == :stderr && data =~ /unknown filesystem type/i
96
+ end
97
+
98
+ break if success
99
+
100
+ attempts += 1
101
+ if attempts > 5
102
+ raise Vagrant::Errors::LinuxMountFailed,
103
+ command: mount_command
104
+ end
105
+ sleep 3
106
+ end
107
+ else
108
+ # If using vmhgfs-fuse mounting the shared folder directly results in invalid
109
+ # symlink generation. To resolve this we can bind mount the shared folder from
110
+ # the full host shared mount. The open-vm-tools will automatically mount in
111
+ # /mnt/hgfs, but the biggest issue with this mount is that it is fully accessible
112
+ # to all users. Instead, we unmount that point if it is found, and we remount the
113
+ # entire shared host (not just an individual folder) with uid and gid applied. The
114
+ # container directory is only accessible via root, and the bind mounts result in the
115
+ # expected behavior.
116
+ current_mount_point = "#{VAGRANT_ROOT_MOUNT_POINT}/#{uid}-#{gid}"
117
+ hgfs_mount_options = "allow_other,default_permissions,uid=#{uid},gid=#{gid}"
118
+ hgfs_mount_options << ",#{options[:extra]}" if options[:extra]
119
+ hgfs_mount_options << ",#{options[:mount_options].join(',')}" if options[:mount_options]
120
+ hgfs_mount = "vmhgfs-fuse -o #{hgfs_mount_options} .host:/ '#{current_mount_point}'"
121
+
122
+ # Allow user to disable unmounting of default vmhgfs-fuse mount point at /mnt/hgfs
123
+ # by setting: `unmount_default_hgfs = false` in the provider config
124
+ if machine.provider_config.unmount_default_hgfs
125
+ machine.communicate.sudo <<-EOH.gsub(/^ */, '')
126
+ if mount | grep /mnt/hgfs; then
127
+ umount /mnt/hgfs
128
+ fi
129
+ EOH
130
+ end
131
+
132
+ # Unique mount point based on uid/gid pair
133
+ machine.communicate.sudo <<-EOH.gsub(/^ */, '')
134
+ mount | grep " #{current_mount_point} "
135
+ if test $? -ne 0; then
136
+ mkdir -p '#{current_mount_point}'
137
+ chmod 700 '#{VAGRANT_ROOT_MOUNT_POINT}'
138
+ #{hgfs_mount}
139
+ fi
140
+ EOH
141
+
142
+ # Finally bind mount to the expected guest location
143
+ mount_command = "mount --bind '#{current_mount_point}/#{name}' '#{expanded_guest_path}'"
144
+ machine.communicate.sudo(mount_command)
145
+ end
146
+
147
+ # Emit an upstart event if we can
148
+ machine.communicate.sudo <<-EOH.gsub(/^ {14}/, '')
149
+ if command -v /sbin/init && /sbin/init --version | grep upstart; then
150
+ /sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT='#{expanded_guest_path}'
151
+ fi
152
+ EOH
153
+ end
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end