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,114 @@
1
+ module Vagrant
2
+ class Action
3
+ # Registers the builtin actions. These are locked away in a
4
+ # method so that their definition can be deferred until after
5
+ # all the necessary Vagrant libraries are loaded. Hopefully
6
+ # in the future this will no longer be necessary with autoloading.
7
+ def self.builtin!
8
+ # provision - Provisions a running VM
9
+ provision = Builder.new do
10
+ use VM::Provision
11
+ end
12
+
13
+ register :provision, provision
14
+
15
+ # start - Starts a VM, assuming it already exists on the
16
+ # environment.
17
+ start = Builder.new do
18
+ use VM::CleanMachineFolder
19
+ use VM::Customize
20
+ use VM::ClearForwardedPorts
21
+ use VM::ForwardPorts
22
+ use VM::Provision
23
+ use VM::NFS
24
+ use VM::ClearSharedFolders
25
+ use VM::ShareFolders
26
+ use VM::Network
27
+ use VM::Boot
28
+ end
29
+
30
+ register :start, start
31
+
32
+ # halt - Halts the VM, attempting gracefully but then forcing
33
+ # a restart if fails.
34
+ halt = Builder.new do
35
+ use VM::Halt
36
+ use VM::DisableNetworks
37
+ end
38
+
39
+ register :halt, halt
40
+
41
+ # suspend - Suspends the VM
42
+ suspend = Builder.new do
43
+ use VM::Suspend
44
+ end
45
+
46
+ register :suspend, suspend
47
+
48
+ # resume - Resume a VM
49
+ resume = Builder.new do
50
+ use VM::Resume
51
+ end
52
+
53
+ register :resume, resume
54
+
55
+ # reload - Halts then restarts the VM
56
+ reload = Builder.new do
57
+ use Action[:halt]
58
+ use Action[:start]
59
+ end
60
+
61
+ register :reload, reload
62
+
63
+ # up - Imports, prepares, then starts a fresh VM.
64
+ up = Builder.new do
65
+ use VM::CheckBox
66
+ use VM::Import
67
+ use VM::Persist
68
+ use VM::MatchMACAddress
69
+ use VM::CheckGuestAdditions
70
+ use Action[:start]
71
+ end
72
+
73
+ register :up, up
74
+
75
+ # destroy - Halts, cleans up, and destroys an existing VM
76
+ destroy = Builder.new do
77
+ use Action[:halt], :force => true
78
+ use VM::ClearNFSExports
79
+ use VM::DestroyUnusedNetworkInterfaces
80
+ use VM::Destroy
81
+ use VM::CleanMachineFolder
82
+ end
83
+
84
+ register :destroy, destroy
85
+
86
+ # package - Export and package the VM
87
+ package = Builder.new do
88
+ use Action[:halt]
89
+ use VM::ClearForwardedPorts
90
+ use VM::ClearSharedFolders
91
+ use VM::Export
92
+ use VM::Package
93
+ end
94
+
95
+ register :package, package
96
+
97
+ # box_add - Download and add a box.
98
+ box_add = Builder.new do
99
+ use Box::Download
100
+ use Box::Unpackage
101
+ use Box::Verify
102
+ end
103
+
104
+ register :box_add, box_add
105
+
106
+ # box_remove - Removes/deletes a box.
107
+ box_remove = Builder.new do
108
+ use Box::Destroy
109
+ end
110
+
111
+ register :box_remove, box_remove
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,16 @@
1
+ module Vagrant
2
+ class Action
3
+ module Env
4
+ # A middleware which simply halts if the environment is erroneous.
5
+ class ErrorHalt
6
+ def initialize(app,env)
7
+ @app = app
8
+ end
9
+
10
+ def call(env)
11
+ @app.call(env) if !env.error?
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ module Vagrant
2
+ class Action
3
+ module Env
4
+ # A middleware which just sets up the environment with some
5
+ # options which are passed to it.
6
+ class Set
7
+ def initialize(app,env,options=nil)
8
+ @app = app
9
+ env.merge!(options || {})
10
+ end
11
+
12
+ def call(env)
13
+ @app.call(env)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,98 @@
1
+ module Vagrant
2
+ class Action
3
+ # Represents an action environment which is what is passed
4
+ # to the `call` method of each action. This environment contains
5
+ # some helper methods for accessing the environment as well
6
+ # as being a hash, to store any additional options.
7
+ class Environment < Hash
8
+ # The {Vagrant::Environment} object represented by this
9
+ # action environment.
10
+ attr_reader :env
11
+
12
+ # If nonnil, the error associated with this environment. Set
13
+ # using {#error!}
14
+ attr_reader :error
15
+
16
+ def initialize(env)
17
+ super() do |h,k|
18
+ # By default, try to find the key as a method on the
19
+ # environment. Gross eval use here.
20
+ begin
21
+ value = eval("h.env.#{k}")
22
+ h[k] = value
23
+ rescue Exception
24
+ nil
25
+ end
26
+ end
27
+
28
+ @env = env
29
+ @error = nil
30
+ end
31
+
32
+ # Returns a logger associated with the environment.
33
+ def logger
34
+ env.logger
35
+ end
36
+
37
+ # Flags the environment as erroneous. Stores the given key
38
+ # and options until the end of the action sequence.
39
+ #
40
+ # @param [Symbol] key Key to translation to display error message.
41
+ # @param [Hash] options Variables to pass to the translation
42
+ def error!(key, options=nil)
43
+ @error = [key, (options || {})]
44
+ end
45
+
46
+ # Returns boolean denoting if environment is in erroneous state.
47
+ #
48
+ # @return [Boolean]
49
+ def error?
50
+ !error.nil?
51
+ end
52
+
53
+ # Returns a boolean denoting if environment has been interrupted
54
+ # with a SIGINT.
55
+ def interrupted?
56
+ error? && error.first == :interrupt
57
+ end
58
+
59
+ #-----------------------------------------------------------------
60
+ # Hash with indifferent access
61
+ #-----------------------------------------------------------------
62
+ def [](key)
63
+ super(convert_key(key))
64
+ end
65
+
66
+ def []=(key, value)
67
+ super(convert_key(key), value)
68
+ end
69
+
70
+ def delete(key)
71
+ super(convert_key(key))
72
+ end
73
+
74
+ def values_at(*indices)
75
+ indices.collect { |key| self[convert_key(key)] }
76
+ end
77
+
78
+ def merge(other)
79
+ dup.merge!(other)
80
+ end
81
+
82
+ def merge!(other)
83
+ other.each do |key, value|
84
+ self[convert_key(key)] = value
85
+ end
86
+ self
87
+ end
88
+
89
+ def has_key?(key)
90
+ super(convert_key(key))
91
+ end
92
+
93
+ def convert_key(key)
94
+ key.is_a?(Symbol) ? key.to_s : key
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,14 @@
1
+ module Vagrant
2
+ class Action
3
+ # A helper to catch any ActionExceptions raised and to
4
+ # apply the error to the environment.
5
+ module ExceptionCatcher
6
+ def catch_action_exception(env)
7
+ yield env
8
+ rescue ActionException => e
9
+ env.error!(e.key, e.data)
10
+ false
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,54 @@
1
+ module Vagrant
2
+ class Action
3
+ module VM
4
+ class Boot
5
+ def initialize(app, env)
6
+ @app = app
7
+ @env = env
8
+ end
9
+
10
+ def call(env)
11
+ # Do nothing if the environment is erroneous
12
+ return if env.error?
13
+
14
+ @env = env
15
+
16
+ # Start up the VM and wait for it to boot.
17
+ boot
18
+ return env.error!(:vm_failed_to_boot) if !wait_for_boot
19
+ return if env.error?
20
+
21
+ @app.call(env)
22
+ end
23
+
24
+ def boot
25
+ @env.logger.info "Booting VM..."
26
+ @env["vm"].vm.start(@env.env.config.vm.boot_mode)
27
+ end
28
+
29
+ def wait_for_boot
30
+ @env.logger.info "Waiting for VM to boot..."
31
+
32
+ @env.env.config.ssh.max_tries.to_i.times do |i|
33
+ @env.logger.info "Trying to connect (attempt ##{i+1} of #{@env.env.config[:ssh][:max_tries]})..."
34
+
35
+ if @env["vm"].ssh.up?
36
+ @env.logger.info "VM booted and ready for use!"
37
+ return true
38
+ end
39
+
40
+ # Return true so that the vm_failed_to_boot error doesn't
41
+ # get shown
42
+ return true if @env.interrupted?
43
+
44
+ sleep 5 if !@env["vagrant.test"]
45
+ end
46
+
47
+ @env.logger.info "Failed to connect to VM! Failed to boot?"
48
+ false
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+
@@ -0,0 +1,27 @@
1
+ module Vagrant
2
+ class Action
3
+ module VM
4
+ class CheckBox
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ box_name = env["config"].vm.box
11
+ return env.error!(:box_not_specified) if !box_name
12
+
13
+ if !Vagrant::Box.find(env.env , box_name)
14
+ box_url = env["config"].vm.box_url
15
+ return env.error!(:box_specified_doesnt_exist, :box_name => box_name) if !box_url
16
+
17
+ env.logger.info "Box #{box_name} not found. Fetching box since URL specified..."
18
+ Vagrant::Box.add(env.env, box_name, box_url)
19
+ env.env.load_box!
20
+ end
21
+
22
+ @app.call(env)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ module Vagrant
2
+ class Action
3
+ module VM
4
+ # Middleware which verifies that the VM has the proper guest additions
5
+ # installed and prints a warning if they're not detected or if the
6
+ # version does not match the installed VirtualBox version.
7
+ class CheckGuestAdditions
8
+ include Util
9
+
10
+ def initialize(app, env)
11
+ @app = app
12
+ end
13
+
14
+ def call(env)
15
+ # Use the raw interface for now, while the virtualbox gem
16
+ # doesn't support guest properties (due to cross platform issues)
17
+ version = env["vm"].vm.interface.get_guest_property_value("/VirtualBox/GuestAdd/Version")
18
+ if version.empty?
19
+ env.logger.error Translator.t(:vm_additions_not_detected)
20
+ elsif version != VirtualBox.version
21
+ env.logger.error Translator.t(:vm_additions_version_mismatch,
22
+ :guest_additions_version => version,
23
+ :virtualbox_version => VirtualBox.version)
24
+ end
25
+
26
+ # Continue
27
+ @app.call(env)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,43 @@
1
+ require 'fileutils'
2
+
3
+ module Vagrant
4
+ class Action
5
+ module VM
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
17
+ @app.call(env)
18
+ end
19
+
20
+ def clean_machine_folder
21
+ folder = File.join(VirtualBox::Global.global.system_properties.default_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) =~ /\.xml-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,39 @@
1
+ require File.join(File.dirname(__FILE__), 'forward_ports_helpers')
2
+
3
+ module Vagrant
4
+ class Action
5
+ module VM
6
+ class ClearForwardedPorts
7
+ include ForwardPortsHelpers
8
+
9
+ def initialize(app, env)
10
+ @app = app
11
+ @env = env
12
+ end
13
+
14
+ def call(env)
15
+ @env = env
16
+ clear
17
+ @app.call(env)
18
+ end
19
+
20
+ def clear
21
+ if used_ports.length > 0
22
+ @env.logger.info "Deleting any previously set forwarded ports..."
23
+ clear_ports
24
+ @env["vm"].reload!
25
+ end
26
+ end
27
+
28
+ # Deletes existing forwarded ports.
29
+ def clear_ports
30
+ @env["vm"].vm.network_adapters.each do |na|
31
+ na.nat_driver.forwarded_ports.dup.each do |fp|
32
+ fp.destroy
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end