Nice error message if port collisions are detected on `resume` [GH-602]
This commit is contained in:
parent
fc9bda08cd
commit
76f605f08d
|
@ -29,6 +29,7 @@ module Vagrant
|
|||
autoload :CheckAccessible, 'vagrant/action/vm/check_accessible'
|
||||
autoload :CheckBox, 'vagrant/action/vm/check_box'
|
||||
autoload :CheckGuestAdditions, 'vagrant/action/vm/check_guest_additions'
|
||||
autoload :CheckPortCollisions, 'vagrant/action/vm/check_port_collisions'
|
||||
autoload :CleanMachineFolder, 'vagrant/action/vm/clean_machine_folder'
|
||||
autoload :ClearForwardedPorts, 'vagrant/action/vm/clear_forwarded_ports'
|
||||
autoload :ClearNFSExports, 'vagrant/action/vm/clear_nfs_exports'
|
||||
|
|
|
@ -59,6 +59,7 @@ module Vagrant
|
|||
Builder.new do
|
||||
use General::Validate
|
||||
use VM::CheckAccessible
|
||||
use VM::CheckPortCollisions
|
||||
use VM::Resume
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
module Vagrant
|
||||
module Action
|
||||
module VM
|
||||
# Action that checks to make sure there are no forwarded port collisions,
|
||||
# and raises an exception if there is.
|
||||
class CheckPortCollisions
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
existing = env[:vm].driver.read_used_ports
|
||||
|
||||
env[:vm].config.vm.forwarded_ports.each do |name, options|
|
||||
if existing.include?(options[:hostport].to_i)
|
||||
# We have a collision!
|
||||
raise Errors::ForwardPortCollisionResume
|
||||
end
|
||||
end
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -188,6 +188,11 @@ module Vagrant
|
|||
error_key(:collision_error, "vagrant.actions.vm.forward_ports")
|
||||
end
|
||||
|
||||
class ForwardPortCollisionResume < VagrantError
|
||||
status_code(62)
|
||||
error_key(:port_collision_resume)
|
||||
end
|
||||
|
||||
class MultiVMEnvironmentRequired < VagrantError
|
||||
status_code(5)
|
||||
error_key(:multi_vm_required)
|
||||
|
|
|
@ -71,6 +71,12 @@ en:
|
|||
no_env: |-
|
||||
A Vagrant environment is required to run this command. Run `vagrant init`
|
||||
to set one up.
|
||||
port_collision_resume: |-
|
||||
This VM cannot be resumed, because the forwarded ports would collide with
|
||||
another running virtual machine. Normally, Vagrant will attempt to fix this
|
||||
for you but VirtualBox only allows forwarded ports to change if the VM is
|
||||
powered off. Therefore, please reload your VM or halt the other running
|
||||
VMs to continue.
|
||||
scp_unavailable: |-
|
||||
SSH server on the guest doesn't support SCP. Please install the necessary
|
||||
software to enable SCP on your guest operating system.
|
||||
|
|
Loading…
Reference in New Issue