vagrantup 0.4.3.dev → 0.5.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.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/config/default.rb +6 -6
- data/lib/vagrant.rb +6 -3
- data/lib/vagrant/action.rb +77 -0
- data/lib/vagrant/action/action_exception.rb +16 -0
- data/lib/vagrant/action/box/destroy.rb +19 -0
- data/lib/vagrant/action/box/download.rb +78 -0
- data/lib/vagrant/action/box/unpackage.rb +58 -0
- data/lib/vagrant/action/box/verify.rb +23 -0
- data/lib/vagrant/action/builder.rb +151 -0
- data/lib/vagrant/action/builtin.rb +114 -0
- data/lib/vagrant/action/env/error_halt.rb +16 -0
- data/lib/vagrant/action/env/set.rb +18 -0
- data/lib/vagrant/action/environment.rb +98 -0
- data/lib/vagrant/action/exception_catcher.rb +14 -0
- data/lib/vagrant/action/vm/boot.rb +54 -0
- data/lib/vagrant/action/vm/check_box.rb +27 -0
- data/lib/vagrant/action/vm/check_guest_additions.rb +32 -0
- data/lib/vagrant/action/vm/clean_machine_folder.rb +43 -0
- data/lib/vagrant/action/vm/clear_forwarded_ports.rb +39 -0
- data/lib/vagrant/action/vm/clear_nfs_exports.rb +20 -0
- data/lib/vagrant/action/vm/clear_shared_folders.rb +32 -0
- data/lib/vagrant/action/vm/customize.rb +21 -0
- data/lib/vagrant/action/vm/destroy.rb +20 -0
- data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +35 -0
- data/lib/vagrant/action/vm/disable_networks.rb +26 -0
- data/lib/vagrant/action/vm/export.rb +53 -0
- data/lib/vagrant/action/vm/forward_ports.rb +121 -0
- data/lib/vagrant/action/vm/forward_ports_helpers.rb +28 -0
- data/lib/vagrant/action/vm/halt.rb +34 -0
- data/lib/vagrant/action/vm/import.rb +33 -0
- data/lib/vagrant/action/vm/match_mac_address.rb +19 -0
- data/lib/vagrant/{actions → action}/vm/network.rb +47 -55
- data/lib/vagrant/action/vm/nfs.rb +161 -0
- data/lib/vagrant/action/vm/nfs_helpers.rb +11 -0
- data/lib/vagrant/action/vm/package.rb +99 -0
- data/lib/vagrant/action/vm/persist.rb +22 -0
- data/lib/vagrant/action/vm/provision.rb +50 -0
- data/lib/vagrant/action/vm/resume.rb +20 -0
- data/lib/vagrant/{actions/vm/shared_folders.rb → action/vm/share_folders.rb} +48 -45
- data/lib/vagrant/action/vm/suspend.rb +20 -0
- data/lib/vagrant/box.rb +3 -7
- data/lib/vagrant/commands/base.rb +1 -3
- data/lib/vagrant/commands/package.rb +4 -9
- data/lib/vagrant/commands/up.rb +0 -2
- data/lib/vagrant/config.rb +15 -1
- data/lib/vagrant/downloaders/file.rb +1 -1
- data/lib/vagrant/downloaders/http.rb +2 -1
- data/lib/vagrant/environment.rb +18 -14
- data/lib/vagrant/hosts/base.rb +77 -0
- data/lib/vagrant/hosts/bsd.rb +53 -0
- data/lib/vagrant/hosts/linux.rb +52 -0
- data/lib/vagrant/provisioners/base.rb +17 -9
- data/lib/vagrant/provisioners/chef.rb +1 -1
- data/lib/vagrant/provisioners/chef_server.rb +4 -8
- data/lib/vagrant/provisioners/chef_solo.rb +1 -2
- data/lib/vagrant/ssh.rb +12 -4
- data/lib/vagrant/systems/base.rb +4 -0
- data/lib/vagrant/systems/linux.rb +12 -1
- data/lib/vagrant/util.rb +16 -0
- data/lib/vagrant/util/busy.rb +59 -0
- data/lib/vagrant/util/plain_logger.rb +11 -0
- data/lib/vagrant/util/platform.rb +18 -0
- data/lib/vagrant/util/resource_logger.rb +128 -0
- data/lib/vagrant/version.rb +6 -0
- data/lib/vagrant/vm.rb +10 -12
- data/templates/chef_solo_solo.erb +2 -1
- data/templates/nfs/exports.erb +3 -0
- data/templates/nfs/exports_linux.erb +3 -0
- data/templates/strings.yml +23 -3
- metadata +121 -196
- data/.gitignore +0 -11
- data/Gemfile +0 -18
- data/Rakefile +0 -41
- data/VERSION +0 -1
- data/bin/.gitignore +0 -0
- data/lib/vagrant/actions/base.rb +0 -130
- data/lib/vagrant/actions/box/add.rb +0 -23
- data/lib/vagrant/actions/box/destroy.rb +0 -14
- data/lib/vagrant/actions/box/download.rb +0 -67
- data/lib/vagrant/actions/box/unpackage.rb +0 -42
- data/lib/vagrant/actions/box/verify.rb +0 -32
- data/lib/vagrant/actions/collection.rb +0 -36
- data/lib/vagrant/actions/runner.rb +0 -131
- data/lib/vagrant/actions/vm/boot.rb +0 -43
- data/lib/vagrant/actions/vm/customize.rb +0 -19
- data/lib/vagrant/actions/vm/destroy.rb +0 -24
- data/lib/vagrant/actions/vm/down.rb +0 -22
- data/lib/vagrant/actions/vm/export.rb +0 -45
- data/lib/vagrant/actions/vm/forward_ports.rb +0 -134
- data/lib/vagrant/actions/vm/halt.rb +0 -24
- data/lib/vagrant/actions/vm/import.rb +0 -23
- data/lib/vagrant/actions/vm/move_hard_drive.rb +0 -51
- data/lib/vagrant/actions/vm/package.rb +0 -94
- data/lib/vagrant/actions/vm/provision.rb +0 -49
- data/lib/vagrant/actions/vm/reload.rb +0 -17
- data/lib/vagrant/actions/vm/resume.rb +0 -16
- data/lib/vagrant/actions/vm/start.rb +0 -26
- data/lib/vagrant/actions/vm/suspend.rb +0 -16
- data/lib/vagrant/actions/vm/up.rb +0 -53
- data/lib/vagrant/busy.rb +0 -79
- data/lib/vagrant/resource_logger.rb +0 -126
- data/lib/vagrant/util/error_helper.rb +0 -13
- data/lib/vagrant/util/output_helper.rb +0 -9
- data/test/test_helper.rb +0 -149
- data/test/vagrant/actions/base_test.rb +0 -32
- data/test/vagrant/actions/box/add_test.rb +0 -36
- data/test/vagrant/actions/box/destroy_test.rb +0 -17
- data/test/vagrant/actions/box/download_test.rb +0 -137
- data/test/vagrant/actions/box/unpackage_test.rb +0 -99
- data/test/vagrant/actions/box/verify_test.rb +0 -44
- data/test/vagrant/actions/collection_test.rb +0 -113
- data/test/vagrant/actions/runner_test.rb +0 -268
- data/test/vagrant/actions/vm/boot_test.rb +0 -49
- data/test/vagrant/actions/vm/customize_test.rb +0 -21
- data/test/vagrant/actions/vm/destroy_test.rb +0 -37
- data/test/vagrant/actions/vm/down_test.rb +0 -39
- data/test/vagrant/actions/vm/export_test.rb +0 -88
- data/test/vagrant/actions/vm/forward_ports_test.rb +0 -253
- data/test/vagrant/actions/vm/halt_test.rb +0 -65
- data/test/vagrant/actions/vm/import_test.rb +0 -45
- data/test/vagrant/actions/vm/move_hard_drive_test.rb +0 -106
- data/test/vagrant/actions/vm/network_test.rb +0 -291
- data/test/vagrant/actions/vm/package_test.rb +0 -254
- data/test/vagrant/actions/vm/provision_test.rb +0 -99
- data/test/vagrant/actions/vm/reload_test.rb +0 -46
- data/test/vagrant/actions/vm/resume_test.rb +0 -26
- data/test/vagrant/actions/vm/shared_folders_test.rb +0 -211
- data/test/vagrant/actions/vm/start_test.rb +0 -73
- data/test/vagrant/actions/vm/suspend_test.rb +0 -26
- data/test/vagrant/actions/vm/up_test.rb +0 -96
- data/test/vagrant/active_list_test.rb +0 -173
- data/test/vagrant/box_test.rb +0 -154
- data/test/vagrant/busy_test.rb +0 -78
- data/test/vagrant/command_test.rb +0 -53
- data/test/vagrant/commands/base_test.rb +0 -139
- data/test/vagrant/commands/box/add_test.rb +0 -34
- data/test/vagrant/commands/box/list_test.rb +0 -32
- data/test/vagrant/commands/box/remove_test.rb +0 -41
- data/test/vagrant/commands/destroy_test.rb +0 -44
- data/test/vagrant/commands/halt_test.rb +0 -50
- data/test/vagrant/commands/init_test.rb +0 -55
- data/test/vagrant/commands/package_test.rb +0 -104
- data/test/vagrant/commands/provision_test.rb +0 -60
- data/test/vagrant/commands/reload_test.rb +0 -44
- data/test/vagrant/commands/resume_test.rb +0 -44
- data/test/vagrant/commands/ssh_config_test.rb +0 -77
- data/test/vagrant/commands/ssh_test.rb +0 -129
- data/test/vagrant/commands/status_test.rb +0 -40
- data/test/vagrant/commands/suspend_test.rb +0 -44
- data/test/vagrant/commands/up_test.rb +0 -47
- data/test/vagrant/config_test.rb +0 -287
- data/test/vagrant/downloaders/base_test.rb +0 -28
- data/test/vagrant/downloaders/file_test.rb +0 -33
- data/test/vagrant/downloaders/http_test.rb +0 -62
- data/test/vagrant/environment_test.rb +0 -770
- data/test/vagrant/provisioners/base_test.rb +0 -33
- data/test/vagrant/provisioners/chef_server_test.rb +0 -176
- data/test/vagrant/provisioners/chef_solo_test.rb +0 -183
- data/test/vagrant/provisioners/chef_test.rb +0 -175
- data/test/vagrant/resource_logger_test.rb +0 -145
- data/test/vagrant/ssh_session_test.rb +0 -46
- data/test/vagrant/ssh_test.rb +0 -296
- data/test/vagrant/systems/linux_test.rb +0 -179
- data/test/vagrant/util/error_helper_test.rb +0 -5
- data/test/vagrant/util/output_helper_test.rb +0 -5
- data/test/vagrant/util/plain_logger_test.rb +0 -17
- data/test/vagrant/util/platform_test.rb +0 -18
- data/test/vagrant/util/stacked_proc_runner_test.rb +0 -43
- data/test/vagrant/util/template_renderer_test.rb +0 -144
- data/test/vagrant/util/translator_test.rb +0 -61
- data/test/vagrant/util_test.rb +0 -27
- data/test/vagrant/vm_test.rb +0 -235
- data/vagrant.gemspec +0 -291
@@ -1,43 +0,0 @@
|
|
1
|
-
module Vagrant
|
2
|
-
module Actions
|
3
|
-
module VM
|
4
|
-
class Boot < Base
|
5
|
-
def execute!
|
6
|
-
@runner.invoke_around_callback(:boot) do
|
7
|
-
# Startup the VM
|
8
|
-
boot
|
9
|
-
|
10
|
-
# Wait for it to complete booting, or error if we could
|
11
|
-
# never detect it booted up successfully
|
12
|
-
if !wait_for_boot
|
13
|
-
error_and_exit(:vm_failed_to_boot)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def boot
|
19
|
-
logger.info "Booting VM..."
|
20
|
-
@runner.vm.start(@runner.env.config.vm.boot_mode)
|
21
|
-
end
|
22
|
-
|
23
|
-
def wait_for_boot(sleeptime=5)
|
24
|
-
logger.info "Waiting for VM to boot..."
|
25
|
-
|
26
|
-
@runner.env.config.ssh.max_tries.to_i.times do |i|
|
27
|
-
logger.info "Trying to connect (attempt ##{i+1} of #{@runner.env.config[:ssh][:max_tries]})..."
|
28
|
-
|
29
|
-
if @runner.ssh.up?
|
30
|
-
logger.info "VM booted and ready for use!"
|
31
|
-
return true
|
32
|
-
end
|
33
|
-
|
34
|
-
sleep sleeptime
|
35
|
-
end
|
36
|
-
|
37
|
-
logger.info "Failed to connect to VM! Failed to boot?"
|
38
|
-
false
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Vagrant
|
2
|
-
module Actions
|
3
|
-
module VM
|
4
|
-
class Customize < Base
|
5
|
-
def execute!
|
6
|
-
if !runner.env.config.vm.proc_stack.empty?
|
7
|
-
logger.info "Running any VM customizations..."
|
8
|
-
|
9
|
-
# Run the customization procs over the VM
|
10
|
-
runner.env.config.vm.run_procs!(@runner.vm)
|
11
|
-
|
12
|
-
# Save the vm
|
13
|
-
runner.vm.save
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Vagrant
|
2
|
-
module Actions
|
3
|
-
module VM
|
4
|
-
class Destroy < Base
|
5
|
-
def execute!
|
6
|
-
@runner.invoke_around_callback(:destroy) do
|
7
|
-
destroy_vm
|
8
|
-
update_dotfile
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def destroy_vm
|
13
|
-
logger.info "Destroying VM and associated drives..."
|
14
|
-
@runner.vm.destroy(:destroy_medium => :delete)
|
15
|
-
@runner.vm = nil
|
16
|
-
end
|
17
|
-
|
18
|
-
def update_dotfile
|
19
|
-
@runner.env.update_dotfile
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Vagrant
|
2
|
-
module Actions
|
3
|
-
module VM
|
4
|
-
class Down < Base
|
5
|
-
def prepare
|
6
|
-
# The true as the 2nd parameter always forces the shutdown so its
|
7
|
-
# fast (since we're destroying anyways)
|
8
|
-
@runner.add_action(Halt, :force => true) if @runner.vm.running?
|
9
|
-
@runner.add_action(Network)
|
10
|
-
@runner.add_action(Destroy)
|
11
|
-
end
|
12
|
-
|
13
|
-
def after_halt
|
14
|
-
# This sleep is necessary to wait for the VM to clean itself up.
|
15
|
-
# There appears to be nothing in the API that does this "wait"
|
16
|
-
# for us.
|
17
|
-
Kernel.sleep(1)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
module Vagrant
|
2
|
-
module Actions
|
3
|
-
module VM
|
4
|
-
class Export < Base
|
5
|
-
attr_reader :temp_dir
|
6
|
-
|
7
|
-
def execute!
|
8
|
-
setup_temp_dir
|
9
|
-
export
|
10
|
-
end
|
11
|
-
|
12
|
-
def cleanup
|
13
|
-
if temp_dir
|
14
|
-
logger.info "Removing temporary export directory..."
|
15
|
-
FileUtils.rm_r(temp_dir)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def rescue(exception)
|
20
|
-
cleanup
|
21
|
-
end
|
22
|
-
|
23
|
-
def setup_temp_dir
|
24
|
-
@temp_dir = File.join(@runner.env.tmp_path, Time.now.to_i.to_s)
|
25
|
-
|
26
|
-
logger.info "Creating temporary directory for export..."
|
27
|
-
FileUtils.mkpath(temp_dir)
|
28
|
-
end
|
29
|
-
|
30
|
-
def ovf_path
|
31
|
-
File.join(temp_dir, @runner.env.config.vm.box_ovf)
|
32
|
-
end
|
33
|
-
|
34
|
-
def export
|
35
|
-
logger.info "Exporting VM to #{ovf_path}..."
|
36
|
-
@runner.vm.export(ovf_path) do |progress|
|
37
|
-
logger.report_progress(progress.percent, 100, false)
|
38
|
-
end
|
39
|
-
|
40
|
-
logger.clear_progress
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,134 +0,0 @@
|
|
1
|
-
module Vagrant
|
2
|
-
module Actions
|
3
|
-
module VM
|
4
|
-
class ForwardPorts < Base
|
5
|
-
def prepare
|
6
|
-
external_collision_check
|
7
|
-
end
|
8
|
-
|
9
|
-
# This method checks for any port collisions with any VMs
|
10
|
-
# which are already created (by Vagrant or otherwise).
|
11
|
-
# report the collisions detected or will attempt to fix them
|
12
|
-
# automatically if the port is configured to do so.
|
13
|
-
def external_collision_check
|
14
|
-
existing = used_ports
|
15
|
-
runner.env.config.vm.forwarded_ports.each do |name, options|
|
16
|
-
if existing.include?(options[:hostport].to_s)
|
17
|
-
handle_collision(name, options, existing)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# Handles any collisions. This method will either attempt to
|
23
|
-
# fix the collision automatically or will raise an error if
|
24
|
-
# auto fixing is disabled.
|
25
|
-
def handle_collision(name, options, existing_ports)
|
26
|
-
if !options[:auto]
|
27
|
-
# Auto fixing is disabled for this port forward, so we
|
28
|
-
# must throw an error so the user can fix it.
|
29
|
-
raise ActionException.new(:vm_port_collision, :name => name, :hostport => options[:hostport].to_s, :guestport => options[:guestport].to_s, :adapter => options[:adapter])
|
30
|
-
end
|
31
|
-
|
32
|
-
# Get the auto port range and get rid of the used ports and
|
33
|
-
# ports which are being used in other forwards so we're just
|
34
|
-
# left with available ports.
|
35
|
-
range = runner.env.config.vm.auto_port_range.to_a
|
36
|
-
range -= runner.env.config.vm.forwarded_ports.collect { |n, o| o[:hostport].to_i }
|
37
|
-
range -= existing_ports
|
38
|
-
|
39
|
-
if range.empty?
|
40
|
-
raise ActionException.new(:vm_port_auto_empty, :vm_name => @runner.name, :name => name, :options => options)
|
41
|
-
end
|
42
|
-
|
43
|
-
# Set the port up to be the first one and add that port to
|
44
|
-
# the used list.
|
45
|
-
options[:hostport] = range.shift
|
46
|
-
existing_ports << options[:hostport]
|
47
|
-
|
48
|
-
# Notify the user
|
49
|
-
logger.info "Fixed port collision: #{name} now on port #{options[:hostport]}"
|
50
|
-
end
|
51
|
-
|
52
|
-
def execute!
|
53
|
-
clear
|
54
|
-
forward_ports
|
55
|
-
end
|
56
|
-
|
57
|
-
def clear
|
58
|
-
if used_ports.length > 0
|
59
|
-
logger.info "Deleting any previously set forwarded ports..."
|
60
|
-
clear_ports
|
61
|
-
runner.reload!
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def forward_ports
|
66
|
-
logger.info "Forwarding ports..."
|
67
|
-
|
68
|
-
runner.env.config.vm.forwarded_ports.each do |name, options|
|
69
|
-
adapter = options[:adapter]
|
70
|
-
|
71
|
-
# Assuming the only reason to establish port forwarding is because the VM is using Virtualbox NAT networking.
|
72
|
-
# Host-only or Bridged networking don't require port-forwarding and establishing forwarded ports on these
|
73
|
-
# attachment types has uncertain behaviour.
|
74
|
-
if @runner.vm.network_adapters[adapter].attachment_type == :nat
|
75
|
-
logger.info "Forwarding \"#{name}\": #{options[:guestport]} on adapter \##{adapter+1} => #{options[:hostport]}"
|
76
|
-
forward_port(name, options)
|
77
|
-
else
|
78
|
-
logger.info "VirtualBox adapter \##{adapter+1} not configured as \"NAT\"."
|
79
|
-
logger.info "Skipped port forwarding \"#{name}\": #{options[:guestport]} on adapter\##{adapter+1} => #{options[:hostport]}"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
runner.vm.save
|
84
|
-
runner.reload!
|
85
|
-
end
|
86
|
-
|
87
|
-
#------------------------------------------------------------
|
88
|
-
# VirtualBox version-specific helpers below. VirtualBox 3.2
|
89
|
-
# introduced a breaking change into the way that forwarded
|
90
|
-
# ports are handled. For backwards compatability with 3.1, we
|
91
|
-
# need this trickery.
|
92
|
-
#------------------------------------------------------------
|
93
|
-
# TODO In a future version, fix this.
|
94
|
-
|
95
|
-
# Returns an array of used ports. This method is implemented
|
96
|
-
# differently depending on the VirtualBox version, but the
|
97
|
-
# behavior is the same.
|
98
|
-
#
|
99
|
-
# @return [Array<String>]
|
100
|
-
def used_ports
|
101
|
-
result = VirtualBox::VM.all.collect do |vm|
|
102
|
-
if vm.running? && vm.uuid != runner.uuid
|
103
|
-
vm.network_adapters.collect do |na|
|
104
|
-
na.nat_driver.forwarded_ports.collect do |fp|
|
105
|
-
fp.hostport.to_s
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
result.flatten.uniq
|
112
|
-
end
|
113
|
-
|
114
|
-
# Deletes existing forwarded ports.
|
115
|
-
def clear_ports
|
116
|
-
runner.vm.network_adapters.each do |na|
|
117
|
-
na.nat_driver.forwarded_ports.dup.each do |fp|
|
118
|
-
fp.destroy
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
# Forwards a port.
|
124
|
-
def forward_port(name, options)
|
125
|
-
port = VirtualBox::NATForwardedPort.new
|
126
|
-
port.name = name
|
127
|
-
port.guestport = options[:guestport]
|
128
|
-
port.hostport = options[:hostport]
|
129
|
-
runner.vm.network_adapters[options[:adapter]].nat_driver.forwarded_ports << port
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Vagrant
|
2
|
-
module Actions
|
3
|
-
module VM
|
4
|
-
class Halt < Base
|
5
|
-
def execute!
|
6
|
-
raise ActionException.new(:vm_not_running) unless @runner.vm.running?
|
7
|
-
|
8
|
-
@runner.invoke_around_callback(:halt) do
|
9
|
-
@runner.system.halt if !options[:force]
|
10
|
-
|
11
|
-
if @runner.vm.state(true) != :powered_off
|
12
|
-
logger.info "Forcing shutdown of VM..."
|
13
|
-
@runner.vm.stop
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def force?
|
19
|
-
!!options[:force]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Vagrant
|
2
|
-
module Actions
|
3
|
-
module VM
|
4
|
-
class Import < Base
|
5
|
-
def execute!
|
6
|
-
@runner.invoke_around_callback(:import) do
|
7
|
-
Busy.busy do
|
8
|
-
logger.info "Importing base VM (#{@runner.env.box.ovf_file})..."
|
9
|
-
# Use the first argument passed to the action
|
10
|
-
@runner.vm = VirtualBox::VM.import(@runner.env.box.ovf_file) do |progress|
|
11
|
-
logger.report_progress(progress.percent, 100, false)
|
12
|
-
end
|
13
|
-
|
14
|
-
logger.clear_progress
|
15
|
-
|
16
|
-
raise ActionException.new(:virtualbox_import_failure) unless @runner.vm
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
module Vagrant
|
2
|
-
module Actions
|
3
|
-
module VM
|
4
|
-
class MoveHardDrive < Base
|
5
|
-
def execute!
|
6
|
-
unless @runner.powered_off?
|
7
|
-
error_and_exit(:vm_power_off_to_move_hd)
|
8
|
-
return
|
9
|
-
end
|
10
|
-
|
11
|
-
destroy_drive_after { clone_and_attach }
|
12
|
-
end
|
13
|
-
|
14
|
-
def hard_drive
|
15
|
-
@hard_drive ||= find_hard_drive
|
16
|
-
end
|
17
|
-
|
18
|
-
# TODO won't work if the first disk is not the boot disk or even if there are multiple disks
|
19
|
-
def find_hard_drive
|
20
|
-
@runner.vm.storage_controllers.each do |sc|
|
21
|
-
sc.devices.each do |d|
|
22
|
-
return d if d.image.is_a?(VirtualBox::HardDrive)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def clone_and_attach
|
28
|
-
logger.info "Cloning current VM Disk to new location (#{new_image_path})..."
|
29
|
-
hard_drive.image = hard_drive.image.clone(new_image_path, @runner.env.config.vm.disk_image_format, true)
|
30
|
-
|
31
|
-
logger.info "Attaching new disk to VM ..."
|
32
|
-
@runner.vm.save
|
33
|
-
end
|
34
|
-
|
35
|
-
def destroy_drive_after
|
36
|
-
old_image = hard_drive.image
|
37
|
-
|
38
|
-
yield
|
39
|
-
|
40
|
-
logger.info "Destroying old VM Disk (#{old_image.filename})..."
|
41
|
-
old_image.destroy(true)
|
42
|
-
end
|
43
|
-
|
44
|
-
# Returns the path to the new location for the hard drive
|
45
|
-
def new_image_path
|
46
|
-
File.join(@runner.env.config.vm.hd_location, hard_drive.image.filename)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
module Vagrant
|
2
|
-
module Actions
|
3
|
-
module VM
|
4
|
-
class Package < Base
|
5
|
-
attr_reader :export_action
|
6
|
-
|
7
|
-
def initialize(*args)
|
8
|
-
super
|
9
|
-
@temp_path = nil
|
10
|
-
end
|
11
|
-
|
12
|
-
def prepare
|
13
|
-
raise ActionException.new(:box_file_exists, :output_file => tar_path) if File.exist?(tar_path)
|
14
|
-
|
15
|
-
# Verify the existance of all the additional files, if any
|
16
|
-
include_files.each do |file|
|
17
|
-
raise ActionException.new(:package_include_file_doesnt_exist, :filename => file) unless File.exists?(file)
|
18
|
-
end
|
19
|
-
|
20
|
-
# Get the export action and store a reference to it
|
21
|
-
@export_action = @runner.find_action(Export)
|
22
|
-
raise ActionException.new(:packaged_requires_export) unless @export_action
|
23
|
-
end
|
24
|
-
|
25
|
-
def execute!
|
26
|
-
compress
|
27
|
-
end
|
28
|
-
|
29
|
-
def out_path
|
30
|
-
options[:output] || "package"
|
31
|
-
end
|
32
|
-
|
33
|
-
def include_files
|
34
|
-
options[:include] || []
|
35
|
-
end
|
36
|
-
|
37
|
-
def tar_path
|
38
|
-
File.join(FileUtils.pwd, "#{out_path}#{@runner.env.config.package.extension}")
|
39
|
-
end
|
40
|
-
|
41
|
-
def temp_path
|
42
|
-
export_action.temp_dir
|
43
|
-
end
|
44
|
-
|
45
|
-
# This method copies the include files (passed in via command line)
|
46
|
-
# to the temporary directory so they are included in a sub-folder within
|
47
|
-
# the actual box
|
48
|
-
def copy_include_files
|
49
|
-
if include_files.length > 0
|
50
|
-
include_dir = File.join(temp_path, "include")
|
51
|
-
FileUtils.mkdir_p(include_dir)
|
52
|
-
|
53
|
-
include_files.each do |f|
|
54
|
-
logger.info "Packaging additional file: #{f}"
|
55
|
-
FileUtils.cp(f, include_dir)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# This method creates the auto-generated Vagrantfile at the root of the
|
61
|
-
# box. This Vagrantfile contains the MAC address so that the user doesn't
|
62
|
-
# have to worry about it.
|
63
|
-
def create_vagrantfile
|
64
|
-
File.open(File.join(temp_path, "Vagrantfile"), "w") do |f|
|
65
|
-
f.write(TemplateRenderer.render("package_Vagrantfile", {
|
66
|
-
:base_mac => @runner.vm.network_adapters.first.mac_address
|
67
|
-
}))
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def compress
|
72
|
-
logger.info "Packaging VM into #{tar_path}..."
|
73
|
-
File.open(tar_path, Platform.tar_file_options) do |tar|
|
74
|
-
Archive::Tar::Minitar::Output.open(tar) do |output|
|
75
|
-
begin
|
76
|
-
current_dir = FileUtils.pwd
|
77
|
-
|
78
|
-
copy_include_files
|
79
|
-
create_vagrantfile
|
80
|
-
|
81
|
-
FileUtils.cd(temp_path)
|
82
|
-
Dir.glob(File.join(".", "**", "*")).each do |entry|
|
83
|
-
Archive::Tar::Minitar.pack_file(entry, output)
|
84
|
-
end
|
85
|
-
ensure
|
86
|
-
FileUtils.cd(current_dir)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|