vagrantup 0.4.3.dev → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/config/default.rb +6 -6
  4. data/lib/vagrant.rb +6 -3
  5. data/lib/vagrant/action.rb +77 -0
  6. data/lib/vagrant/action/action_exception.rb +16 -0
  7. data/lib/vagrant/action/box/destroy.rb +19 -0
  8. data/lib/vagrant/action/box/download.rb +78 -0
  9. data/lib/vagrant/action/box/unpackage.rb +58 -0
  10. data/lib/vagrant/action/box/verify.rb +23 -0
  11. data/lib/vagrant/action/builder.rb +151 -0
  12. data/lib/vagrant/action/builtin.rb +114 -0
  13. data/lib/vagrant/action/env/error_halt.rb +16 -0
  14. data/lib/vagrant/action/env/set.rb +18 -0
  15. data/lib/vagrant/action/environment.rb +98 -0
  16. data/lib/vagrant/action/exception_catcher.rb +14 -0
  17. data/lib/vagrant/action/vm/boot.rb +54 -0
  18. data/lib/vagrant/action/vm/check_box.rb +27 -0
  19. data/lib/vagrant/action/vm/check_guest_additions.rb +32 -0
  20. data/lib/vagrant/action/vm/clean_machine_folder.rb +43 -0
  21. data/lib/vagrant/action/vm/clear_forwarded_ports.rb +39 -0
  22. data/lib/vagrant/action/vm/clear_nfs_exports.rb +20 -0
  23. data/lib/vagrant/action/vm/clear_shared_folders.rb +32 -0
  24. data/lib/vagrant/action/vm/customize.rb +21 -0
  25. data/lib/vagrant/action/vm/destroy.rb +20 -0
  26. data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +35 -0
  27. data/lib/vagrant/action/vm/disable_networks.rb +26 -0
  28. data/lib/vagrant/action/vm/export.rb +53 -0
  29. data/lib/vagrant/action/vm/forward_ports.rb +121 -0
  30. data/lib/vagrant/action/vm/forward_ports_helpers.rb +28 -0
  31. data/lib/vagrant/action/vm/halt.rb +34 -0
  32. data/lib/vagrant/action/vm/import.rb +33 -0
  33. data/lib/vagrant/action/vm/match_mac_address.rb +19 -0
  34. data/lib/vagrant/{actions → action}/vm/network.rb +47 -55
  35. data/lib/vagrant/action/vm/nfs.rb +161 -0
  36. data/lib/vagrant/action/vm/nfs_helpers.rb +11 -0
  37. data/lib/vagrant/action/vm/package.rb +99 -0
  38. data/lib/vagrant/action/vm/persist.rb +22 -0
  39. data/lib/vagrant/action/vm/provision.rb +50 -0
  40. data/lib/vagrant/action/vm/resume.rb +20 -0
  41. data/lib/vagrant/{actions/vm/shared_folders.rb → action/vm/share_folders.rb} +48 -45
  42. data/lib/vagrant/action/vm/suspend.rb +20 -0
  43. data/lib/vagrant/box.rb +3 -7
  44. data/lib/vagrant/commands/base.rb +1 -3
  45. data/lib/vagrant/commands/package.rb +4 -9
  46. data/lib/vagrant/commands/up.rb +0 -2
  47. data/lib/vagrant/config.rb +15 -1
  48. data/lib/vagrant/downloaders/file.rb +1 -1
  49. data/lib/vagrant/downloaders/http.rb +2 -1
  50. data/lib/vagrant/environment.rb +18 -14
  51. data/lib/vagrant/hosts/base.rb +77 -0
  52. data/lib/vagrant/hosts/bsd.rb +53 -0
  53. data/lib/vagrant/hosts/linux.rb +52 -0
  54. data/lib/vagrant/provisioners/base.rb +17 -9
  55. data/lib/vagrant/provisioners/chef.rb +1 -1
  56. data/lib/vagrant/provisioners/chef_server.rb +4 -8
  57. data/lib/vagrant/provisioners/chef_solo.rb +1 -2
  58. data/lib/vagrant/ssh.rb +12 -4
  59. data/lib/vagrant/systems/base.rb +4 -0
  60. data/lib/vagrant/systems/linux.rb +12 -1
  61. data/lib/vagrant/util.rb +16 -0
  62. data/lib/vagrant/util/busy.rb +59 -0
  63. data/lib/vagrant/util/plain_logger.rb +11 -0
  64. data/lib/vagrant/util/platform.rb +18 -0
  65. data/lib/vagrant/util/resource_logger.rb +128 -0
  66. data/lib/vagrant/version.rb +6 -0
  67. data/lib/vagrant/vm.rb +10 -12
  68. data/templates/chef_solo_solo.erb +2 -1
  69. data/templates/nfs/exports.erb +3 -0
  70. data/templates/nfs/exports_linux.erb +3 -0
  71. data/templates/strings.yml +23 -3
  72. metadata +121 -196
  73. data/.gitignore +0 -11
  74. data/Gemfile +0 -18
  75. data/Rakefile +0 -41
  76. data/VERSION +0 -1
  77. data/bin/.gitignore +0 -0
  78. data/lib/vagrant/actions/base.rb +0 -130
  79. data/lib/vagrant/actions/box/add.rb +0 -23
  80. data/lib/vagrant/actions/box/destroy.rb +0 -14
  81. data/lib/vagrant/actions/box/download.rb +0 -67
  82. data/lib/vagrant/actions/box/unpackage.rb +0 -42
  83. data/lib/vagrant/actions/box/verify.rb +0 -32
  84. data/lib/vagrant/actions/collection.rb +0 -36
  85. data/lib/vagrant/actions/runner.rb +0 -131
  86. data/lib/vagrant/actions/vm/boot.rb +0 -43
  87. data/lib/vagrant/actions/vm/customize.rb +0 -19
  88. data/lib/vagrant/actions/vm/destroy.rb +0 -24
  89. data/lib/vagrant/actions/vm/down.rb +0 -22
  90. data/lib/vagrant/actions/vm/export.rb +0 -45
  91. data/lib/vagrant/actions/vm/forward_ports.rb +0 -134
  92. data/lib/vagrant/actions/vm/halt.rb +0 -24
  93. data/lib/vagrant/actions/vm/import.rb +0 -23
  94. data/lib/vagrant/actions/vm/move_hard_drive.rb +0 -51
  95. data/lib/vagrant/actions/vm/package.rb +0 -94
  96. data/lib/vagrant/actions/vm/provision.rb +0 -49
  97. data/lib/vagrant/actions/vm/reload.rb +0 -17
  98. data/lib/vagrant/actions/vm/resume.rb +0 -16
  99. data/lib/vagrant/actions/vm/start.rb +0 -26
  100. data/lib/vagrant/actions/vm/suspend.rb +0 -16
  101. data/lib/vagrant/actions/vm/up.rb +0 -53
  102. data/lib/vagrant/busy.rb +0 -79
  103. data/lib/vagrant/resource_logger.rb +0 -126
  104. data/lib/vagrant/util/error_helper.rb +0 -13
  105. data/lib/vagrant/util/output_helper.rb +0 -9
  106. data/test/test_helper.rb +0 -149
  107. data/test/vagrant/actions/base_test.rb +0 -32
  108. data/test/vagrant/actions/box/add_test.rb +0 -36
  109. data/test/vagrant/actions/box/destroy_test.rb +0 -17
  110. data/test/vagrant/actions/box/download_test.rb +0 -137
  111. data/test/vagrant/actions/box/unpackage_test.rb +0 -99
  112. data/test/vagrant/actions/box/verify_test.rb +0 -44
  113. data/test/vagrant/actions/collection_test.rb +0 -113
  114. data/test/vagrant/actions/runner_test.rb +0 -268
  115. data/test/vagrant/actions/vm/boot_test.rb +0 -49
  116. data/test/vagrant/actions/vm/customize_test.rb +0 -21
  117. data/test/vagrant/actions/vm/destroy_test.rb +0 -37
  118. data/test/vagrant/actions/vm/down_test.rb +0 -39
  119. data/test/vagrant/actions/vm/export_test.rb +0 -88
  120. data/test/vagrant/actions/vm/forward_ports_test.rb +0 -253
  121. data/test/vagrant/actions/vm/halt_test.rb +0 -65
  122. data/test/vagrant/actions/vm/import_test.rb +0 -45
  123. data/test/vagrant/actions/vm/move_hard_drive_test.rb +0 -106
  124. data/test/vagrant/actions/vm/network_test.rb +0 -291
  125. data/test/vagrant/actions/vm/package_test.rb +0 -254
  126. data/test/vagrant/actions/vm/provision_test.rb +0 -99
  127. data/test/vagrant/actions/vm/reload_test.rb +0 -46
  128. data/test/vagrant/actions/vm/resume_test.rb +0 -26
  129. data/test/vagrant/actions/vm/shared_folders_test.rb +0 -211
  130. data/test/vagrant/actions/vm/start_test.rb +0 -73
  131. data/test/vagrant/actions/vm/suspend_test.rb +0 -26
  132. data/test/vagrant/actions/vm/up_test.rb +0 -96
  133. data/test/vagrant/active_list_test.rb +0 -173
  134. data/test/vagrant/box_test.rb +0 -154
  135. data/test/vagrant/busy_test.rb +0 -78
  136. data/test/vagrant/command_test.rb +0 -53
  137. data/test/vagrant/commands/base_test.rb +0 -139
  138. data/test/vagrant/commands/box/add_test.rb +0 -34
  139. data/test/vagrant/commands/box/list_test.rb +0 -32
  140. data/test/vagrant/commands/box/remove_test.rb +0 -41
  141. data/test/vagrant/commands/destroy_test.rb +0 -44
  142. data/test/vagrant/commands/halt_test.rb +0 -50
  143. data/test/vagrant/commands/init_test.rb +0 -55
  144. data/test/vagrant/commands/package_test.rb +0 -104
  145. data/test/vagrant/commands/provision_test.rb +0 -60
  146. data/test/vagrant/commands/reload_test.rb +0 -44
  147. data/test/vagrant/commands/resume_test.rb +0 -44
  148. data/test/vagrant/commands/ssh_config_test.rb +0 -77
  149. data/test/vagrant/commands/ssh_test.rb +0 -129
  150. data/test/vagrant/commands/status_test.rb +0 -40
  151. data/test/vagrant/commands/suspend_test.rb +0 -44
  152. data/test/vagrant/commands/up_test.rb +0 -47
  153. data/test/vagrant/config_test.rb +0 -287
  154. data/test/vagrant/downloaders/base_test.rb +0 -28
  155. data/test/vagrant/downloaders/file_test.rb +0 -33
  156. data/test/vagrant/downloaders/http_test.rb +0 -62
  157. data/test/vagrant/environment_test.rb +0 -770
  158. data/test/vagrant/provisioners/base_test.rb +0 -33
  159. data/test/vagrant/provisioners/chef_server_test.rb +0 -176
  160. data/test/vagrant/provisioners/chef_solo_test.rb +0 -183
  161. data/test/vagrant/provisioners/chef_test.rb +0 -175
  162. data/test/vagrant/resource_logger_test.rb +0 -145
  163. data/test/vagrant/ssh_session_test.rb +0 -46
  164. data/test/vagrant/ssh_test.rb +0 -296
  165. data/test/vagrant/systems/linux_test.rb +0 -179
  166. data/test/vagrant/util/error_helper_test.rb +0 -5
  167. data/test/vagrant/util/output_helper_test.rb +0 -5
  168. data/test/vagrant/util/plain_logger_test.rb +0 -17
  169. data/test/vagrant/util/platform_test.rb +0 -18
  170. data/test/vagrant/util/stacked_proc_runner_test.rb +0 -43
  171. data/test/vagrant/util/template_renderer_test.rb +0 -144
  172. data/test/vagrant/util/translator_test.rb +0 -61
  173. data/test/vagrant/util_test.rb +0 -27
  174. data/test/vagrant/vm_test.rb +0 -235
  175. data/vagrant.gemspec +0 -291
@@ -0,0 +1,20 @@
1
+ require File.join(File.dirname(__FILE__), 'nfs_helpers')
2
+
3
+ module Vagrant
4
+ class Action
5
+ module VM
6
+ class ClearNFSExports
7
+ include NFSHelpers
8
+
9
+ def initialize(app, env)
10
+ @app = app
11
+ end
12
+
13
+ def call(env)
14
+ clear_nfs_exports(env)
15
+ @app.call(env)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,32 @@
1
+ module Vagrant
2
+ class Action
3
+ module VM
4
+ class ClearSharedFolders
5
+ def initialize(app, env)
6
+ @app = app
7
+ @env = env
8
+ end
9
+
10
+ def call(env)
11
+ @env = env
12
+
13
+ clear_shared_folders
14
+ @app.call(env)
15
+ end
16
+
17
+ def clear_shared_folders
18
+ if @env["vm"].vm.shared_folders.length > 0
19
+ @env.logger.info "Clearing previously set shared folders..."
20
+
21
+ folders = @env["vm"].vm.shared_folders.dup
22
+ folders.each do |shared_folder|
23
+ shared_folder.destroy
24
+ end
25
+
26
+ @env["vm"].reload!
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ module Vagrant
2
+ class Action
3
+ module VM
4
+ class Customize
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ if !env.env.config.vm.proc_stack.empty?
11
+ env.logger.info "Running any VM customizations..."
12
+ env.env.config.vm.run_procs!(env["vm"].vm)
13
+ env["vm"].vm.save
14
+ end
15
+
16
+ @app.call(env)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ module Vagrant
2
+ class Action
3
+ module VM
4
+ class Destroy
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env.logger.info "Destroying VM and associated drives..."
11
+ env["vm"].vm.destroy(:destroy_medium => :delete)
12
+ env["vm"].vm = nil
13
+ env.env.update_dotfile
14
+
15
+ @app.call(env)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ module Vagrant
2
+ class Action
3
+ module VM
4
+ # Destroys the unused host only interfaces. This middleware cleans
5
+ # up any created host only networks.
6
+ class DestroyUnusedNetworkInterfaces
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ # We need to check if the host only network specified by any
13
+ # of the adapters would not have any more clients if it was
14
+ # destroyed. And if so, then destroy the host only network
15
+ # itself.
16
+ interfaces = env["vm"].vm.network_adapters.collect do |adapter|
17
+ adapter.host_interface_object
18
+ end
19
+
20
+ interfaces.compact.uniq.each do |interface|
21
+ # Destroy the network interface if there is only one
22
+ # attached VM (which must be this VM)
23
+ if interface.attached_vms.length == 1
24
+ env.logger.info "Destroying unused network interface..."
25
+ interface.destroy
26
+ end
27
+ end
28
+
29
+ # Continue along
30
+ @app.call(env)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,26 @@
1
+ module Vagrant
2
+ class Action
3
+ module VM
4
+ # Middleware to disable all host only networks on the
5
+ # VM
6
+ class DisableNetworks
7
+ def initialize(app, env)
8
+ @app = app
9
+ @env = env
10
+ end
11
+
12
+ def call(env)
13
+ env.logger.info "Disabling host only networks..."
14
+
15
+ env["vm"].vm.network_adapters.each do |adapter|
16
+ next if adapter.attachment_type != :host_only
17
+ adapter.enabled = false
18
+ adapter.save
19
+ end
20
+
21
+ @app.call(env)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,53 @@
1
+ module Vagrant
2
+ class Action
3
+ module VM
4
+ class Export
5
+ attr_reader :temp_dir
6
+
7
+ def initialize(app, env)
8
+ @app = app
9
+ @env = env
10
+ end
11
+
12
+ def call(env)
13
+ @env = env
14
+
15
+ return env.error!(:vm_power_off_to_package) if !@env["vm"].vm.powered_off?
16
+ return if env.error?
17
+
18
+ setup_temp_dir
19
+ export
20
+
21
+ @app.call(env) if !env.error?
22
+
23
+ cleanup
24
+ end
25
+
26
+ def cleanup
27
+ if temp_dir && File.exist?(temp_dir)
28
+ FileUtils.rm_rf(temp_dir)
29
+ end
30
+ end
31
+
32
+ def setup_temp_dir
33
+ @env.logger.info "Creating temporary directory for export..."
34
+ @temp_dir = @env["export.temp_dir"] = File.join(@env.env.tmp_path, Time.now.to_i.to_s)
35
+ FileUtils.mkpath(@env["export.temp_dir"])
36
+ end
37
+
38
+ def export
39
+ @env.logger.info "Exporting VM to #{ovf_path}..."
40
+ @env["vm"].vm.export(ovf_path) do |progress|
41
+ @env.logger.report_progress(progress.percent, 100, false)
42
+ end
43
+ ensure
44
+ @env.logger.clear_progress
45
+ end
46
+
47
+ def ovf_path
48
+ File.join(@env["export.temp_dir"], @env.env.config.vm.box_ovf)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,121 @@
1
+ require File.join(File.dirname(__FILE__), 'forward_ports_helpers')
2
+
3
+ module Vagrant
4
+ class Action
5
+ module VM
6
+ class ForwardPorts
7
+ include ForwardPortsHelpers
8
+
9
+ def initialize(app,env)
10
+ @app = app
11
+ @env = env
12
+
13
+ threshold_check
14
+ external_collision_check if !env.error?
15
+ end
16
+
17
+ #--------------------------------------------------------------
18
+ # Prepare Helpers - These functions are not involved in actually
19
+ # executing the action
20
+ #--------------------------------------------------------------
21
+
22
+ # This method checks for any forwarded ports on the host below
23
+ # 1024, which causes the forwarded ports to fail.
24
+ def threshold_check
25
+ @env.env.config.vm.forwarded_ports.each do |name, options|
26
+ return @env.error!(:vm_port_below_threshold) if options[:hostport] <= 1024
27
+ end
28
+ end
29
+
30
+ # This method checks for any port collisions with any VMs
31
+ # which are already created (by Vagrant or otherwise).
32
+ # report the collisions detected or will attempt to fix them
33
+ # automatically if the port is configured to do so.
34
+ def external_collision_check
35
+ existing = used_ports
36
+ @env.env.config.vm.forwarded_ports.each do |name, options|
37
+ if existing.include?(options[:hostport].to_s)
38
+ handle_collision(name, options, existing)
39
+ end
40
+ end
41
+ end
42
+
43
+ # Handles any collisions. This method will either attempt to
44
+ # fix the collision automatically or will raise an error if
45
+ # auto fixing is disabled.
46
+ def handle_collision(name, options, existing_ports)
47
+ if !options[:auto]
48
+ # Auto fixing is disabled for this port forward, so we
49
+ # must throw an error so the user can fix it.
50
+ return @env.error!(:vm_port_collision, :name => name, :hostport => options[:hostport].to_s, :guestport => options[:guestport].to_s, :adapter => options[:adapter])
51
+ end
52
+
53
+ # Get the auto port range and get rid of the used ports and
54
+ # ports which are being used in other forwards so we're just
55
+ # left with available ports.
56
+ range = @env.env.config.vm.auto_port_range.to_a
57
+ range -= @env.env.config.vm.forwarded_ports.collect { |n, o| o[:hostport].to_i }
58
+ range -= existing_ports
59
+
60
+ if range.empty?
61
+ return @env.error!(:vm_port_auto_empty, :vm_name => @env["vm"].name, :name => name, :options => options)
62
+ end
63
+
64
+ # Set the port up to be the first one and add that port to
65
+ # the used list.
66
+ options[:hostport] = range.shift
67
+ existing_ports << options[:hostport]
68
+
69
+ # Notify the user
70
+ @env.logger.info "Fixed port collision: #{name} now on port #{options[:hostport]}"
71
+ end
72
+
73
+ #--------------------------------------------------------------
74
+ # Execution
75
+ #--------------------------------------------------------------
76
+ def call(env)
77
+ @env = env
78
+
79
+ forward_ports
80
+
81
+ @app.call(env)
82
+ end
83
+
84
+ def forward_ports
85
+ @env.logger.info "Forwarding ports..."
86
+
87
+ @env.env.config.vm.forwarded_ports.each do |name, options|
88
+ adapter = options[:adapter]
89
+
90
+ # Assuming the only reason to establish port forwarding is because the VM is using Virtualbox NAT networking.
91
+ # Host-only or Bridged networking don't require port-forwarding and establishing forwarded ports on these
92
+ # attachment types has uncertain behaviour.
93
+ if @env["vm"].vm.network_adapters[adapter].attachment_type == :nat
94
+ @env.logger.info "Forwarding \"#{name}\": #{options[:guestport]} on adapter \##{adapter+1} => #{options[:hostport]}"
95
+ forward_port(name, options)
96
+ else
97
+ @env.logger.info "VirtualBox adapter \##{adapter+1} not configured as \"NAT\"."
98
+ @env.logger.info "Skipped port forwarding \"#{name}\": #{options[:guestport]} on adapter\##{adapter+1} => #{options[:hostport]}"
99
+ end
100
+ end
101
+
102
+ @env["vm"].vm.save
103
+ @env["vm"].reload!
104
+ end
105
+
106
+ #--------------------------------------------------------------
107
+ # General Helpers
108
+ #--------------------------------------------------------------
109
+
110
+ # Forwards a port.
111
+ def forward_port(name, options)
112
+ port = VirtualBox::NATForwardedPort.new
113
+ port.name = name
114
+ port.guestport = options[:guestport]
115
+ port.hostport = options[:hostport]
116
+ @env["vm"].vm.network_adapters[options[:adapter]].nat_driver.forwarded_ports << port
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,28 @@
1
+ module Vagrant
2
+ class Action
3
+ module VM
4
+ # Helper methods for forwarding ports. Requires that the environment
5
+ # is set to the `@env` instance variable.
6
+ module ForwardPortsHelpers
7
+ # Returns an array of used ports. This method is implemented
8
+ # differently depending on the VirtualBox version, but the
9
+ # behavior is the same.
10
+ #
11
+ # @return [Array<String>]
12
+ def used_ports
13
+ result = VirtualBox::VM.all.collect do |vm|
14
+ if vm.running? && vm.uuid != @env["vm"].uuid
15
+ vm.network_adapters.collect do |na|
16
+ na.nat_driver.forwarded_ports.collect do |fp|
17
+ fp.hostport.to_s
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ result.flatten.uniq
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,34 @@
1
+ module Vagrant
2
+ class Action
3
+ module VM
4
+ class Halt
5
+ include ExceptionCatcher
6
+
7
+ def initialize(app, env, options=nil)
8
+ @app = app
9
+ env.merge!(options || {})
10
+ end
11
+
12
+ def call(env)
13
+ if env["vm"].vm.running?
14
+ if !env["force"]
15
+ catch_action_exception(env) { env["vm"].system.halt }
16
+ return if env.error?
17
+ end
18
+
19
+ if env["vm"].vm.state(true) != :powered_off
20
+ env.logger.info "Forcing shutdown of VM..."
21
+ env["vm"].vm.stop
22
+ end
23
+
24
+ # Sleep for a second to verify that the VM properly
25
+ # cleans itself up
26
+ sleep 1 if !env["vagrant.test"]
27
+ end
28
+
29
+ @app.call(env)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,33 @@
1
+ module Vagrant
2
+ class Action
3
+ module VM
4
+ class Import
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env.logger.info "Importing base VM (#{env.env.box.ovf_file})"
11
+
12
+ begin
13
+ # Import the virtual machine
14
+ env.env.vm.vm = VirtualBox::VM.import(env.env.box.ovf_file) do |progress|
15
+ env.logger.report_progress(progress.percent, 100, false)
16
+ end
17
+
18
+ # Flag as erroneous and return if import failed
19
+ return env.error!(:virtualbox_import_failure) if !env['vm'].vm
20
+ ensure
21
+ env.logger.clear_progress
22
+ end
23
+
24
+ # Import completed successfully. Continue the chain
25
+ @app.call(env) if !env.error?
26
+
27
+ # Interrupted, destroy the VM
28
+ env["actions"].run(:destroy) if env.interrupted?
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,19 @@
1
+ module Vagrant
2
+ class Action
3
+ module VM
4
+ class MatchMACAddress
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env.logger.info "Matching MAC addresses..."
11
+ env["vm"].vm.network_adapters.first.mac_address = env.env.config.vm.base_mac
12
+ env["vm"].vm.save
13
+
14
+ @app.call(env)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end