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.
- checksums.yaml +4 -4
- data/lib/vagrant-vmware-desktop.rb +190 -0
- data/lib/vagrant-vmware-desktop/action.rb +442 -0
- data/lib/vagrant-vmware-desktop/action/base_mac_to_ip.rb +55 -0
- data/lib/vagrant-vmware-desktop/action/boot.rb +26 -0
- data/lib/vagrant-vmware-desktop/action/check_existing_network.rb +35 -0
- data/lib/vagrant-vmware-desktop/action/check_vmware.rb +28 -0
- data/lib/vagrant-vmware-desktop/action/checkpoint.rb +86 -0
- data/lib/vagrant-vmware-desktop/action/clear_shared_folders.rb +25 -0
- data/lib/vagrant-vmware-desktop/action/common.rb +16 -0
- data/lib/vagrant-vmware-desktop/action/compatibility.rb +36 -0
- data/lib/vagrant-vmware-desktop/action/created.rb +20 -0
- data/lib/vagrant-vmware-desktop/action/destroy.rb +32 -0
- data/lib/vagrant-vmware-desktop/action/discard_suspended_state.rb +32 -0
- data/lib/vagrant-vmware-desktop/action/export.rb +29 -0
- data/lib/vagrant-vmware-desktop/action/fix_old_machine_id.rb +29 -0
- data/lib/vagrant-vmware-desktop/action/forward_ports.rb +110 -0
- data/lib/vagrant-vmware-desktop/action/halt.rb +27 -0
- data/lib/vagrant-vmware-desktop/action/import.rb +138 -0
- data/lib/vagrant-vmware-desktop/action/machine_lock.rb +26 -0
- data/lib/vagrant-vmware-desktop/action/message_already_running.rb +18 -0
- data/lib/vagrant-vmware-desktop/action/message_not_created.rb +18 -0
- data/lib/vagrant-vmware-desktop/action/message_not_running.rb +18 -0
- data/lib/vagrant-vmware-desktop/action/network.rb +339 -0
- data/lib/vagrant-vmware-desktop/action/package_vagrantfile.rb +46 -0
- data/lib/vagrant-vmware-desktop/action/prepare_forwarded_port_collision_params.rb +28 -0
- data/lib/vagrant-vmware-desktop/action/prepare_nfs_settings.rb +43 -0
- data/lib/vagrant-vmware-desktop/action/prepare_synced_folder_cleanup.rb +19 -0
- data/lib/vagrant-vmware-desktop/action/prune_forwarded_ports.rb +30 -0
- data/lib/vagrant-vmware-desktop/action/prune_nfs_exports.rb +22 -0
- data/lib/vagrant-vmware-desktop/action/running.rb +20 -0
- data/lib/vagrant-vmware-desktop/action/set_display_name.rb +37 -0
- data/lib/vagrant-vmware-desktop/action/share_folders.rb +97 -0
- data/lib/vagrant-vmware-desktop/action/snapshot_delete.rb +26 -0
- data/lib/vagrant-vmware-desktop/action/snapshot_restore.rb +26 -0
- data/lib/vagrant-vmware-desktop/action/snapshot_save.rb +26 -0
- data/lib/vagrant-vmware-desktop/action/suspend.rb +26 -0
- data/lib/vagrant-vmware-desktop/action/suspended.rb +24 -0
- data/lib/vagrant-vmware-desktop/action/vmx_modify.rb +39 -0
- data/lib/vagrant-vmware-desktop/action/wait_for_address.rb +31 -0
- data/lib/vagrant-vmware-desktop/action/wait_for_communicator_compat.rb +32 -0
- data/lib/vagrant-vmware-desktop/action/wait_for_vmx_halt.rb +35 -0
- data/lib/vagrant-vmware-desktop/cap/disk.rb +287 -0
- data/lib/vagrant-vmware-desktop/cap/provider.rb +37 -0
- data/lib/vagrant-vmware-desktop/cap/snapshot.rb +41 -0
- data/lib/vagrant-vmware-desktop/checkpoint_client.rb +203 -0
- data/lib/vagrant-vmware-desktop/config.rb +377 -0
- data/lib/vagrant-vmware-desktop/constants.rb +16 -0
- data/lib/vagrant-vmware-desktop/driver.rb +15 -0
- data/lib/vagrant-vmware-desktop/driver/base.rb +1356 -0
- data/lib/vagrant-vmware-desktop/errors.rb +342 -0
- data/lib/vagrant-vmware-desktop/guest_cap/linux/mount_vmware_shared_folder.rb +158 -0
- data/lib/vagrant-vmware-desktop/guest_cap/linux/verify_vmware_hgfs.rb +27 -0
- data/lib/vagrant-vmware-desktop/helper/lock.rb +26 -0
- data/lib/vagrant-vmware-desktop/helper/routing_table.rb +182 -0
- data/lib/vagrant-vmware-desktop/helper/vagrant_utility.rb +185 -0
- data/lib/vagrant-vmware-desktop/plugin.rb +148 -0
- data/lib/vagrant-vmware-desktop/provider.rb +96 -0
- data/lib/vagrant-vmware-desktop/setup_plugin.rb +24 -0
- data/lib/vagrant-vmware-desktop/synced_folder.rb +93 -0
- data/locales/en.yml +634 -0
- metadata +71 -17
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'vagrant/util/template_renderer'
|
2
|
+
|
3
|
+
module HashiCorp
|
4
|
+
module VagrantVMwareDesktop
|
5
|
+
module Action
|
6
|
+
class PackageVagrantfile
|
7
|
+
# For TemplateRenderer
|
8
|
+
include Vagrant::Util
|
9
|
+
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
@env = env
|
16
|
+
create_metadata
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
|
20
|
+
# This method creates the auto-generated Vagrantfile at the root of the
|
21
|
+
# box. This Vagrantfile contains the MAC address so that the user doesn't
|
22
|
+
# have to worry about it.
|
23
|
+
#
|
24
|
+
# @note This is deprecated as the base mac is no longer required to be set.
|
25
|
+
# The method (and template) are preserved to easily allow enabling
|
26
|
+
# this functionality in the future for a different purpose if requried.
|
27
|
+
def create_vagrantfile
|
28
|
+
mac_addresses = @env[:machine].provider.driver.read_mac_addresses
|
29
|
+
base_mac = mac_addresses[mac_addresses.keys.min]
|
30
|
+
File.open(File.join(@env["export.temp_dir"], "Vagrantfile"), "w") do |f|
|
31
|
+
f.write(TemplateRenderer.render("package_Vagrantfile", {
|
32
|
+
base_mac: base_mac
|
33
|
+
}))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Creates a metadata.json file which includes provider information
|
38
|
+
def create_metadata
|
39
|
+
File.open(File.join(@env["export.temp_dir"], "metadata.json"), "w") do |f|
|
40
|
+
f.write({provider: "vmware_desktop"}.to_json)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module HashiCorp
|
4
|
+
module VagrantVMwareDesktop
|
5
|
+
module Action
|
6
|
+
# This prepares some variables for the environment hash so that
|
7
|
+
# forwarded port collision detection works properly with VMware.
|
8
|
+
class PrepareForwardedPortCollisionParams
|
9
|
+
include Common
|
10
|
+
|
11
|
+
def initialize(app, env)
|
12
|
+
@app = app
|
13
|
+
@logger = Log4r::Logger.new("hashicorp::provider::vmware::prepare_fp_collision")
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
# Get the forwared ports for all NAT devices and mark them as in use.
|
18
|
+
env[:port_collision_extra_in_use] = env[:machine].provider.driver.all_forwarded_ports
|
19
|
+
|
20
|
+
# Repair the forwarded port collisions
|
21
|
+
env[:port_collision_repair] = true
|
22
|
+
|
23
|
+
@app.call(env)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module HashiCorp
|
2
|
+
module VagrantVMwareDesktop
|
3
|
+
module Action
|
4
|
+
class PrepareNFSSettings
|
5
|
+
include Common
|
6
|
+
|
7
|
+
def initialize(app,env)
|
8
|
+
@app = app
|
9
|
+
@logger = Log4r::Logger.new("vagrant::action::vm::nfs")
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
@app.call(env)
|
14
|
+
|
15
|
+
env[:nfs_machine_ip] = env[:machine].provider.driver.read_ip(
|
16
|
+
env[:machine].provider_config.enable_vmrun_ip_lookup
|
17
|
+
)
|
18
|
+
|
19
|
+
# We just assume the machine IP is the first 3 octets
|
20
|
+
# with "1" for the last octet. Poor assumption but can
|
21
|
+
# be fixed later.
|
22
|
+
if env[:nfs_machine_ip]
|
23
|
+
host_ip = env[:nfs_machine_ip].split(".").map(&:to_i)
|
24
|
+
host_ip[3] = 1
|
25
|
+
env[:nfs_host_ip] = host_ip.join(".")
|
26
|
+
end
|
27
|
+
|
28
|
+
using_nfs = false
|
29
|
+
env[:machine].config.vm.synced_folders.each do |id, opts|
|
30
|
+
if opts[:nfs]
|
31
|
+
using_nfs = true
|
32
|
+
break
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
if using_nfs
|
37
|
+
raise Errors::NFSNoNetwork if !env[:nfs_machine_ip]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module HashiCorp
|
2
|
+
module VagrantVMwareDesktop
|
3
|
+
module Action
|
4
|
+
class PrepareSyncedFolderCleanup
|
5
|
+
include Common
|
6
|
+
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
env[:nfs_valid_ids] = env[:machine].provider.driver.read_running_vms
|
13
|
+
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
require "vagrant-vmware-desktop/helper/lock"
|
4
|
+
|
5
|
+
module HashiCorp
|
6
|
+
module VagrantVMwareDesktop
|
7
|
+
module Action
|
8
|
+
# This action prunes out forwarded ports that aren't in use any longer,
|
9
|
+
# usually by machines that don't exist anymore.
|
10
|
+
class PruneForwardedPorts
|
11
|
+
include Common
|
12
|
+
|
13
|
+
def initialize(app, env)
|
14
|
+
@app = app
|
15
|
+
@logger = Log4r::Logger.new("hashicorp::provider::vmware::prune_forwarded_ports")
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
@logger.info("Pruning forwarded ports...")
|
20
|
+
Helper::Lock.lock(env[:machine], "vmware-network") do
|
21
|
+
env[:machine].provider.driver.prune_forwarded_ports
|
22
|
+
end
|
23
|
+
|
24
|
+
# Carry on
|
25
|
+
@app.call(env)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module HashiCorp
|
2
|
+
module VagrantVMwareDesktop
|
3
|
+
module Action
|
4
|
+
class PruneNFSExports
|
5
|
+
include Common
|
6
|
+
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
if env[:host]
|
13
|
+
vms = env[:machine].provider.driver.read_running_vms
|
14
|
+
env[:host].nfs_prune(vms)
|
15
|
+
end
|
16
|
+
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module HashiCorp
|
2
|
+
module VagrantVMwareDesktop
|
3
|
+
module Action
|
4
|
+
# This can be used with "Call" built-in to check if the machine
|
5
|
+
# is running.
|
6
|
+
class Running
|
7
|
+
include Common
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
env[:result] = env[:machine].state.id == :running
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module HashiCorp
|
4
|
+
module VagrantVMwareDesktop
|
5
|
+
module Action
|
6
|
+
# This class sets the default displayName for the VM.
|
7
|
+
class SetDisplayName
|
8
|
+
include Common
|
9
|
+
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
@logger = Log4r::Logger.new("hashicorp::provider::vmware::vmx_modify")
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
default_name = "#{env[:root_path].basename.to_s}: #{env[:machine].name}"
|
17
|
+
|
18
|
+
@logger.info("Setting the default display name: #{default_name}")
|
19
|
+
env[:machine].provider.driver.vmx_modify do |vmx|
|
20
|
+
# Delete any alternate casings
|
21
|
+
vmx.keys.each do |key|
|
22
|
+
if key.downcase == "displayname"
|
23
|
+
vmx.delete(key)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Set the displayName
|
28
|
+
vmx["displayname"] = default_name
|
29
|
+
end
|
30
|
+
|
31
|
+
# Carry on
|
32
|
+
@app.call(env)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
require "vagrant/util/scoped_hash_override"
|
4
|
+
|
5
|
+
module HashiCorp
|
6
|
+
module VagrantVMwareDesktop
|
7
|
+
module Action
|
8
|
+
# This takes the configured synced folders on the VM and shares them
|
9
|
+
# into the VMware guest.
|
10
|
+
class ShareFolders
|
11
|
+
include Common
|
12
|
+
|
13
|
+
include Vagrant::Util::ScopedHashOverride
|
14
|
+
|
15
|
+
def initialize(app, env)
|
16
|
+
@app = app
|
17
|
+
@logger = Log4r::Logger.new("hashicorp::provider::vmware::shared_folders")
|
18
|
+
end
|
19
|
+
|
20
|
+
def call(env)
|
21
|
+
# Move on first so that the machine is powered on
|
22
|
+
@app.call(env)
|
23
|
+
|
24
|
+
shared_folders = {}
|
25
|
+
env[:machine].config.vm.synced_folders.each do |id, data|
|
26
|
+
data = scoped_hash_override(data, :vmware)
|
27
|
+
|
28
|
+
# Ignore disabled shared folders
|
29
|
+
if data[:disabled]
|
30
|
+
@logger.info("Disabled shared folder, ignoring: #{id}")
|
31
|
+
next
|
32
|
+
end
|
33
|
+
|
34
|
+
# Ignore NFS shared folders as well
|
35
|
+
next if data[:nfs]
|
36
|
+
|
37
|
+
# Use it!
|
38
|
+
shared_folders[id] = data
|
39
|
+
end
|
40
|
+
|
41
|
+
if shared_folders.empty?
|
42
|
+
@logger.info("No shared folders. Doing nothing.")
|
43
|
+
return
|
44
|
+
end
|
45
|
+
|
46
|
+
# Verify that the machine can actually support sharing folders
|
47
|
+
# if we can.
|
48
|
+
if env[:machine].guest.capability?(:verify_vmware_hgfs)
|
49
|
+
@logger.info("Verifying HGFS is on the guest...")
|
50
|
+
if !env[:machine].guest.capability(:verify_vmware_hgfs)
|
51
|
+
raise Errors::GuestMissingHGFS
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Get the SSH info which we'll use later
|
56
|
+
ssh_info = env[:machine].ssh_info
|
57
|
+
|
58
|
+
# short guestpaths first, so we don't step on ourselves
|
59
|
+
shared_folders = shared_folders.dup.sort_by do |id, data|
|
60
|
+
if data[:guestpath]
|
61
|
+
data[:guestpath].length
|
62
|
+
else
|
63
|
+
# A long enough path to just do this at the end.
|
64
|
+
10000
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
@logger.info("Preparing shared folders with VMX...")
|
69
|
+
env[:ui].info I18n.t("hashicorp.vagrant_vmware_desktop.sharing_folders")
|
70
|
+
env[:machine].provider.driver.enable_shared_folders
|
71
|
+
shared_folders.each do |id, data|
|
72
|
+
id = id.gsub('/', env[:machine].provider_config.shared_folder_special_char)
|
73
|
+
path = File.expand_path(data[:hostpath], env[:root_path])
|
74
|
+
guestpath = data[:guestpath]
|
75
|
+
|
76
|
+
env[:ui].info(I18n.t("hashicorp.vagrant_vmware_desktop.sharing_folder_single",
|
77
|
+
hostpath: path,
|
78
|
+
guestpath: guestpath))
|
79
|
+
|
80
|
+
env[:machine].provider.driver.share_folder(id, path)
|
81
|
+
|
82
|
+
# Remove trailing slashes
|
83
|
+
guestpath = guestpath.gsub(/\/+$/, "")
|
84
|
+
|
85
|
+
# Calculate the owner and group
|
86
|
+
data[:owner] ||= ssh_info[:username]
|
87
|
+
data[:group] ||= ssh_info[:username]
|
88
|
+
|
89
|
+
# Mount it!
|
90
|
+
env[:machine].guest.capability(
|
91
|
+
:mount_vmware_shared_folder, id, data[:guestpath], data)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module HashiCorp
|
4
|
+
module VagrantVMwareDesktop
|
5
|
+
module Action
|
6
|
+
# This snapshots the VMware machine.
|
7
|
+
class SnapshotDelete
|
8
|
+
include Common
|
9
|
+
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
@logger = Log4r::Logger.new("hashicorp::provider::vmware::snapshot_delete")
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
env[:ui].info(I18n.t(
|
17
|
+
"hashicorp.vagrant_vmware_desktop.snapshot_deleting",
|
18
|
+
name: env[:snapshot_name]))
|
19
|
+
env[:machine].provider.driver.snapshot_delete(env[:snapshot_name])
|
20
|
+
|
21
|
+
@app.call(env)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module HashiCorp
|
4
|
+
module VagrantVMwareDesktop
|
5
|
+
module Action
|
6
|
+
# This snapshots the VMware machine.
|
7
|
+
class SnapshotRestore
|
8
|
+
include Common
|
9
|
+
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
@logger = Log4r::Logger.new("hashicorp::provider::vmware::snapshot_restore")
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
env[:ui].info(I18n.t(
|
17
|
+
"hashicorp.vagrant_vmware_desktop.snapshot_restoring",
|
18
|
+
name: env[:snapshot_name]))
|
19
|
+
env[:machine].provider.driver.snapshot_revert(env[:snapshot_name])
|
20
|
+
|
21
|
+
@app.call(env)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module HashiCorp
|
4
|
+
module VagrantVMwareDesktop
|
5
|
+
module Action
|
6
|
+
# This snapshots the VMware machine.
|
7
|
+
class SnapshotSave
|
8
|
+
include Common
|
9
|
+
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
@logger = Log4r::Logger.new("hashicorp::provider::vmware::snapshot_save")
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
env[:ui].info(I18n.t(
|
17
|
+
"hashicorp.vagrant_vmware_desktop.snapshot_saving",
|
18
|
+
name: env[:snapshot_name]))
|
19
|
+
env[:machine].provider.driver.snapshot_take(env[:snapshot_name])
|
20
|
+
|
21
|
+
@app.call(env)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module HashiCorp
|
4
|
+
module VagrantVMwareDesktop
|
5
|
+
module Action
|
6
|
+
# This suspends the VMware machine.
|
7
|
+
class Suspend
|
8
|
+
include Common
|
9
|
+
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
@logger = Log4r::Logger.new("hashicorp::provider::vmware::suspend")
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
if env[:machine].provider.state.id == :running
|
17
|
+
env[:ui].info(I18n.t("hashicorp.vagrant_vmware_desktop.suspending"))
|
18
|
+
env[:machine].provider.driver.suspend
|
19
|
+
end
|
20
|
+
|
21
|
+
@app.call(env)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|