vagrant-vmware-free 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.ruby-version +1 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +57 -0
- data/LICENSE +21 -0
- data/README.md +10 -0
- data/Rakefile +3 -0
- data/lib/vagrant_vmware_free.rb +5 -0
- data/lib/vagrant_vmware_free/action.rb +214 -0
- data/lib/vagrant_vmware_free/action/boot.rb +23 -0
- data/lib/vagrant_vmware_free/action/check_accessible.rb +23 -0
- data/lib/vagrant_vmware_free/action/check_created.rb +21 -0
- data/lib/vagrant_vmware_free/action/check_guest_additions.rb +45 -0
- data/lib/vagrant_vmware_free/action/check_running.rb +21 -0
- data/lib/vagrant_vmware_free/action/check_virtualbox.rb +22 -0
- data/lib/vagrant_vmware_free/action/clean_machine_folder.rb +43 -0
- data/lib/vagrant_vmware_free/action/clear_forwarded_ports.rb +18 -0
- data/lib/vagrant_vmware_free/action/clear_network_interfaces.rb +31 -0
- data/lib/vagrant_vmware_free/action/clear_shared_folders.rb +17 -0
- data/lib/vagrant_vmware_free/action/created.rb +20 -0
- data/lib/vagrant_vmware_free/action/customize.rb +43 -0
- data/lib/vagrant_vmware_free/action/destroy.rb +19 -0
- data/lib/vagrant_vmware_free/action/destroy_unused_network_interfaces.rb +23 -0
- data/lib/vagrant_vmware_free/action/discard_state.rb +20 -0
- data/lib/vagrant_vmware_free/action/export.rb +57 -0
- data/lib/vagrant_vmware_free/action/forced_halt.rb +25 -0
- data/lib/vagrant_vmware_free/action/forward_ports.rb +89 -0
- data/lib/vagrant_vmware_free/action/get_network_address.rb +27 -0
- data/lib/vagrant_vmware_free/action/import.rb +56 -0
- data/lib/vagrant_vmware_free/action/is_paused.rb +20 -0
- data/lib/vagrant_vmware_free/action/is_running.rb +20 -0
- data/lib/vagrant_vmware_free/action/is_saved.rb +20 -0
- data/lib/vagrant_vmware_free/action/match_mac_address.rb +21 -0
- data/lib/vagrant_vmware_free/action/message_already_running.rb +16 -0
- data/lib/vagrant_vmware_free/action/message_not_created.rb +16 -0
- data/lib/vagrant_vmware_free/action/message_not_running.rb +16 -0
- data/lib/vagrant_vmware_free/action/message_will_not_destroy.rb +17 -0
- data/lib/vagrant_vmware_free/action/network.rb +424 -0
- data/lib/vagrant_vmware_free/action/package.rb +20 -0
- data/lib/vagrant_vmware_free/action/package_vagrantfile.rb +33 -0
- data/lib/vagrant_vmware_free/action/prepare_forwarded_port_collision_params.rb +35 -0
- data/lib/vagrant_vmware_free/action/prepare_nfs_settings.rb +69 -0
- data/lib/vagrant_vmware_free/action/prune_nfs_exports.rb +20 -0
- data/lib/vagrant_vmware_free/action/resume.rb +26 -0
- data/lib/vagrant_vmware_free/action/sane_defaults.rb +91 -0
- data/lib/vagrant_vmware_free/action/set_name.rb +52 -0
- data/lib/vagrant_vmware_free/action/set_network.rb +17 -0
- data/lib/vagrant_vmware_free/action/setup_package_files.rb +51 -0
- data/lib/vagrant_vmware_free/action/share_folders.rb +128 -0
- data/lib/vagrant_vmware_free/action/suspend.rb +20 -0
- data/lib/vagrant_vmware_free/action/wait_for_vm_tools.rb +19 -0
- data/lib/vagrant_vmware_free/config.rb +38 -0
- data/lib/vagrant_vmware_free/driver/base.rb +14 -0
- data/lib/vagrant_vmware_free/driver/fusion.rb +17 -0
- data/lib/vagrant_vmware_free/driver/fusion_6.rb +188 -0
- data/lib/vagrant_vmware_free/driver/meta.rb +122 -0
- data/lib/vagrant_vmware_free/driver/vix.rb +19 -0
- data/lib/vagrant_vmware_free/driver/vix/functions.rb +38 -0
- data/lib/vagrant_vmware_free/driver/vix/helpers.rb +63 -0
- data/lib/vagrant_vmware_free/driver/vix/types.rb +143 -0
- data/lib/vagrant_vmware_free/errors.rb +9 -0
- data/lib/vagrant_vmware_free/plugin.rb +43 -0
- data/lib/vagrant_vmware_free/provider.rb +62 -0
- data/lib/vagrant_vmware_free/util/vmx.rb +48 -0
- data/vagrant-vmware-free.gemspec +21 -0
- metadata +190 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderVMwareFree
|
3
|
+
module Action
|
4
|
+
# This middleware checks that the VM is running, and raises an exception
|
5
|
+
# if it is not, notifying the user that the VM must be running.
|
6
|
+
class CheckRunning
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
if env[:machine].state.id != :running
|
13
|
+
raise Vagrant::Errors::VMNotRunningError
|
14
|
+
end
|
15
|
+
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderVMwareFree
|
3
|
+
module Action
|
4
|
+
# Checks that VirtualBox is installed and ready to be used.
|
5
|
+
class CheckVirtualbox
|
6
|
+
def initialize(app, env)
|
7
|
+
@app = app
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
# This verifies that VirtualBox is installed and the driver is
|
12
|
+
# ready to function. If not, then an exception will be raised
|
13
|
+
# which will break us out of execution of the middleware sequence.
|
14
|
+
Driver::Meta.new.verify!
|
15
|
+
|
16
|
+
# Carry on.
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ProviderVMwareFree
|
5
|
+
module Action
|
6
|
+
# Cleans up the VirtualBox machine folder for any ".xml-prev"
|
7
|
+
# files which VirtualBox may have left over. This is a bug in
|
8
|
+
# VirtualBox. As soon as this is fixed, this middleware can and
|
9
|
+
# will be removed.
|
10
|
+
class CleanMachineFolder
|
11
|
+
def initialize(app, env)
|
12
|
+
@app = app
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
clean_machine_folder(env[:machine].provider.driver.read_machine_folder)
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
|
20
|
+
def clean_machine_folder(machine_folder)
|
21
|
+
folder = File.join(machine_folder, "*")
|
22
|
+
|
23
|
+
# Small safeguard against potentially unwanted rm-rf, since the default
|
24
|
+
# machine folder will typically always be greater than 10 characters long.
|
25
|
+
# For users with it < 10, out of luck?
|
26
|
+
return if folder.length < 10
|
27
|
+
|
28
|
+
Dir[folder].each do |f|
|
29
|
+
next unless File.directory?(f)
|
30
|
+
|
31
|
+
keep = Dir["#{f}/**/*"].find do |d|
|
32
|
+
# Find a file that doesn't have ".xml-prev" as the suffix,
|
33
|
+
# which signals that we want to keep this folder
|
34
|
+
File.file?(d) && !(File.basename(d) =~ /\.vbox-prev$/)
|
35
|
+
end
|
36
|
+
|
37
|
+
FileUtils.rm_rf(f) if !keep
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderVMwareFree
|
3
|
+
module Action
|
4
|
+
class ClearForwardedPorts
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info I18n.t("vagrant.actions.vm.clear_forward_ports.deleting")
|
11
|
+
env[:machine].provider.driver.clear_forwarded_ports
|
12
|
+
|
13
|
+
@app.call(env)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderVMwareFree
|
3
|
+
module Action
|
4
|
+
class ClearNetworkInterfaces
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
# Create the adapters array to make all adapters nothing.
|
11
|
+
# We do adapters 2 to 8 because that is every built-in adapter
|
12
|
+
# excluding the NAT adapter on port 1 which Vagrant always
|
13
|
+
# expects to exist.
|
14
|
+
adapters = []
|
15
|
+
2.upto(env[:machine].provider.driver.max_network_adapters).each do |i|
|
16
|
+
adapters << {
|
17
|
+
:adapter => i,
|
18
|
+
:type => :none
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
# "Enable" all the adapters we setup.
|
23
|
+
env[:ui].info I18n.t("vagrant.actions.vm.clear_network_interfaces.deleting")
|
24
|
+
env[:machine].provider.driver.enable_adapters(adapters)
|
25
|
+
|
26
|
+
@app.call(env)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderVMwareFree
|
3
|
+
module Action
|
4
|
+
class ClearSharedFolders
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:machine].provider.driver.clear_shared_folders
|
11
|
+
|
12
|
+
@app.call(env)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderVMwareFree
|
3
|
+
module Action
|
4
|
+
class Created
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
# Set the result to be true if the machine is created.
|
11
|
+
env[:result] = env[:machine].state.id != :not_created
|
12
|
+
|
13
|
+
# Call the next if we have one (but we shouldn't, since this
|
14
|
+
# middleware is built to run with the Call-type middlewares)
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderVMwareFree
|
3
|
+
module Action
|
4
|
+
class Customize
|
5
|
+
def initialize(app, env, event)
|
6
|
+
@app = app
|
7
|
+
@event = event
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
customizations = []
|
12
|
+
env[:machine].provider_config.customizations.each do |event, command|
|
13
|
+
if event == @event
|
14
|
+
customizations << command
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
if !customizations.empty?
|
19
|
+
env[:ui].info I18n.t("vagrant.actions.vm.customize.running", event: @event)
|
20
|
+
|
21
|
+
# Execute each customization command.
|
22
|
+
customizations.each do |command|
|
23
|
+
processed_command = command.collect do |arg|
|
24
|
+
arg = env[:machine].id if arg == :id
|
25
|
+
arg.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
result = env[:machine].provider.driver.execute_command(processed_command)
|
29
|
+
if result.exit_code != 0
|
30
|
+
raise Vagrant::Errors::VMCustomizationFailed, {
|
31
|
+
:command => processed_command.inspect,
|
32
|
+
:error => result.stderr
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
@app.call(env)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderVMwareFree
|
3
|
+
module Action
|
4
|
+
class Destroy
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info I18n.t("vagrant.actions.vm.destroy.destroying")
|
11
|
+
env[:machine].provider.driver.delete
|
12
|
+
env[:machine].id = nil
|
13
|
+
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ProviderVMwareFree
|
5
|
+
module Action
|
6
|
+
class DestroyUnusedNetworkInterfaces
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
@logger = Log4r::Logger.new("vagrant::plugins::virtualbox::destroy_unused_netifs")
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
if env[:machine].provider_config.destroy_unused_network_interfaces
|
14
|
+
@logger.info("Destroying unused network interfaces...")
|
15
|
+
env[:machine].provider.driver.delete_unused_host_only_networks
|
16
|
+
end
|
17
|
+
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderVMwareFree
|
3
|
+
module Action
|
4
|
+
class DiscardState
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
if env[:machine].provider.state.id == :saved
|
11
|
+
env[:ui].info I18n.t("vagrant.actions.vm.discard_state.discarding")
|
12
|
+
env[:machine].provider.driver.discard_saved_state
|
13
|
+
end
|
14
|
+
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ProviderVMwareFree
|
5
|
+
module Action
|
6
|
+
class Export
|
7
|
+
attr_reader :temp_dir
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
@env = env
|
15
|
+
|
16
|
+
raise Vagrant::Errors::VMPowerOffToPackage if \
|
17
|
+
@env[:machine].provider.state.id != :poweroff
|
18
|
+
|
19
|
+
setup_temp_dir
|
20
|
+
export
|
21
|
+
|
22
|
+
@app.call(env)
|
23
|
+
|
24
|
+
recover(env) # called to cleanup temp directory
|
25
|
+
end
|
26
|
+
|
27
|
+
def recover(env)
|
28
|
+
if temp_dir && File.exist?(temp_dir)
|
29
|
+
FileUtils.rm_rf(temp_dir)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup_temp_dir
|
34
|
+
@env[:ui].info I18n.t("vagrant.actions.vm.export.create_dir")
|
35
|
+
@temp_dir = @env["export.temp_dir"] = @env[:tmp_path].join(Time.now.to_i.to_s)
|
36
|
+
FileUtils.mkpath(@env["export.temp_dir"])
|
37
|
+
end
|
38
|
+
|
39
|
+
def export
|
40
|
+
@env[:ui].info I18n.t("vagrant.actions.vm.export.exporting")
|
41
|
+
@env[:machine].provider.driver.export(ovf_path) do |progress|
|
42
|
+
@env[:ui].clear_line
|
43
|
+
@env[:ui].report_progress(progress.percent, 100, false)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Clear the line a final time so the next data can appear
|
47
|
+
# alone on the line.
|
48
|
+
@env[:ui].clear_line
|
49
|
+
end
|
50
|
+
|
51
|
+
def ovf_path
|
52
|
+
File.join(@env["export.temp_dir"], "box.ovf")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderVMwareFree
|
3
|
+
module Action
|
4
|
+
class ForcedHalt
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
current_state = env[:machine].state.id
|
11
|
+
if current_state == :running || current_state == :gurumeditation
|
12
|
+
env[:ui].info I18n.t("vagrant.actions.vm.halt.force")
|
13
|
+
env[:machine].provider.driver.halt
|
14
|
+
end
|
15
|
+
|
16
|
+
# Sleep for a second to verify that the VM properly
|
17
|
+
# cleans itself up. Silly VirtualBox.
|
18
|
+
sleep 1 if !env["vagrant.test"]
|
19
|
+
|
20
|
+
@app.call(env)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderVMwareFree
|
3
|
+
module Action
|
4
|
+
class ForwardPorts
|
5
|
+
include Util::CompileForwardedPorts
|
6
|
+
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
#--------------------------------------------------------------
|
12
|
+
# Execution
|
13
|
+
#--------------------------------------------------------------
|
14
|
+
def call(env)
|
15
|
+
@env = env
|
16
|
+
|
17
|
+
# Get the ports we're forwarding
|
18
|
+
env[:forwarded_ports] ||= compile_forwarded_ports(env[:machine].config)
|
19
|
+
|
20
|
+
# Warn if we're port forwarding to any privileged ports...
|
21
|
+
env[:forwarded_ports].each do |fp|
|
22
|
+
if fp.host_port <= 1024
|
23
|
+
env[:ui].warn I18n.t("vagrant.actions.vm.forward_ports.privileged_ports")
|
24
|
+
break
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
env[:ui].info I18n.t("vagrant.actions.vm.forward_ports.forwarding")
|
29
|
+
forward_ports
|
30
|
+
|
31
|
+
@app.call(env)
|
32
|
+
end
|
33
|
+
|
34
|
+
def forward_ports
|
35
|
+
ports = []
|
36
|
+
|
37
|
+
interfaces = @env[:machine].provider.driver.read_network_interfaces
|
38
|
+
|
39
|
+
@env[:forwarded_ports].each do |fp|
|
40
|
+
message_attributes = {
|
41
|
+
:adapter => fp.adapter,
|
42
|
+
:guest_port => fp.guest_port,
|
43
|
+
:host_port => fp.host_port
|
44
|
+
}
|
45
|
+
|
46
|
+
# Assuming the only reason to establish port forwarding is
|
47
|
+
# because the VM is using Virtualbox NAT networking. Host-only
|
48
|
+
# bridged networking don't require port-forwarding and establishing
|
49
|
+
# forwarded ports on these attachment types has uncertain behaviour.
|
50
|
+
@env[:ui].info(I18n.t("vagrant.actions.vm.forward_ports.forwarding_entry",
|
51
|
+
message_attributes))
|
52
|
+
|
53
|
+
# Verify we have the network interface to attach to
|
54
|
+
if !interfaces[fp.adapter]
|
55
|
+
raise Vagrant::Errors::ForwardPortAdapterNotFound,
|
56
|
+
:adapter => fp.adapter.to_s,
|
57
|
+
:guest => fp.guest_port.to_s,
|
58
|
+
:host => fp.host_port.to_s
|
59
|
+
end
|
60
|
+
|
61
|
+
# Port forwarding requires the network interface to be a NAT interface,
|
62
|
+
# so verify that that is the case.
|
63
|
+
if interfaces[fp.adapter][:type] != :nat
|
64
|
+
@env[:ui].info(I18n.t("vagrant.actions.vm.forward_ports.non_nat",
|
65
|
+
message_attributes))
|
66
|
+
next
|
67
|
+
end
|
68
|
+
|
69
|
+
# Add the options to the ports array to send to the driver later
|
70
|
+
ports << {
|
71
|
+
:adapter => fp.adapter,
|
72
|
+
:guestip => fp.guest_ip,
|
73
|
+
:guestport => fp.guest_port,
|
74
|
+
:hostip => fp.host_ip,
|
75
|
+
:hostport => fp.host_port,
|
76
|
+
:name => fp.id,
|
77
|
+
:protocol => fp.protocol
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
if !ports.empty?
|
82
|
+
# We only need to forward ports if there are any to forward
|
83
|
+
@env[:machine].provider.driver.forward_ports(ports)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|