providers/docker: implement port checker for remote machine
This commit is contained in:
parent
623386f13c
commit
e578e91e3a
|
@ -0,0 +1,11 @@
|
||||||
|
module VagrantPlugins
|
||||||
|
module GuestLinux
|
||||||
|
module Cap
|
||||||
|
class Port
|
||||||
|
def self.port_open_check(machine, port)
|
||||||
|
machine.communicate.test("nc -z 127.0.0.1 #{port}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -51,6 +51,12 @@ module VagrantPlugins
|
||||||
Cap::NFSClient
|
Cap::NFSClient
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# For the Docker provider
|
||||||
|
guest_capability("linux", "port_open_check") do
|
||||||
|
require_relative "cap/port"
|
||||||
|
Cap::Port
|
||||||
|
end
|
||||||
|
|
||||||
guest_capability("linux", "read_ip_address") do
|
guest_capability("linux", "read_ip_address") do
|
||||||
require_relative "cap/read_ip_address"
|
require_relative "cap/read_ip_address"
|
||||||
Cap::ReadIPAddress
|
Cap::ReadIPAddress
|
||||||
|
|
|
@ -15,7 +15,7 @@ module VagrantPlugins
|
||||||
b.use Call, IsState, :not_created do |env, b2|
|
b.use Call, IsState, :not_created do |env, b2|
|
||||||
# If the VM is NOT created yet, then do the setup steps
|
# If the VM is NOT created yet, then do the setup steps
|
||||||
if env[:result]
|
if env[:result]
|
||||||
b2.use EnvSet, :port_collision_repair => true
|
b2.use EnvSet, port_collision_repair: true
|
||||||
|
|
||||||
b2.use Call, HasSSH do |env2, b3|
|
b2.use Call, HasSSH do |env2, b3|
|
||||||
if env2[:result]
|
if env2[:result]
|
||||||
|
@ -27,14 +27,8 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
b2.use Call, HostMachineRequired do |env2, b3|
|
b2.use HostMachinePortChecker
|
||||||
if !env[:result]
|
b2.use HandleForwardedPortCollisions
|
||||||
# We're not using a proxy host VM, so just handle
|
|
||||||
# port collisions like we would any other system.
|
|
||||||
b3.use HandleForwardedPortCollisions
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
b2.use PrepareNFSValidIds
|
b2.use PrepareNFSValidIds
|
||||||
b2.use SyncedFolderCleanup
|
b2.use SyncedFolderCleanup
|
||||||
b2.use SyncedFolders
|
b2.use SyncedFolders
|
||||||
|
@ -225,6 +219,7 @@ module VagrantPlugins
|
||||||
autoload :Destroy, action_root.join("destroy")
|
autoload :Destroy, action_root.join("destroy")
|
||||||
autoload :HasSSH, action_root.join("has_ssh")
|
autoload :HasSSH, action_root.join("has_ssh")
|
||||||
autoload :HostMachine, action_root.join("host_machine")
|
autoload :HostMachine, action_root.join("host_machine")
|
||||||
|
autoload :HostMachinePortChecker, action_root.join("host_machine_port_checker")
|
||||||
autoload :HostMachineRequired, action_root.join("host_machine_required")
|
autoload :HostMachineRequired, action_root.join("host_machine_required")
|
||||||
autoload :HostMachineSyncFolders, action_root.join("host_machine_sync_folders")
|
autoload :HostMachineSyncFolders, action_root.join("host_machine_sync_folders")
|
||||||
autoload :HostMachineSyncFoldersDisable, action_root.join("host_machine_sync_folders_disable")
|
autoload :HostMachineSyncFoldersDisable, action_root.join("host_machine_sync_folders_disable")
|
||||||
|
|
|
@ -59,7 +59,7 @@ module VagrantPlugins
|
||||||
def forwarded_ports
|
def forwarded_ports
|
||||||
mappings = {}
|
mappings = {}
|
||||||
@machine.config.vm.networks.each do |type, options|
|
@machine.config.vm.networks.each do |type, options|
|
||||||
if type == :forwarded_port && options[:id] != 'ssh'
|
if type == :forwarded_port
|
||||||
mappings[options[:host]] = options
|
mappings[options[:host]] = options
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
require "log4r"
|
||||||
|
|
||||||
|
module VagrantPlugins
|
||||||
|
module DockerProvider
|
||||||
|
module Action
|
||||||
|
# This sets up the middleware env var to check for ports in use.
|
||||||
|
class HostMachinePortChecker
|
||||||
|
def initialize(app, env)
|
||||||
|
@app = app
|
||||||
|
@logger = Log4r::Logger.new("vagrant::docker::hostmachineportchecker")
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
return @app.call(env) if !env[:machine].provider.host_vm?
|
||||||
|
|
||||||
|
@machine = env[:machine]
|
||||||
|
env[:port_collision_port_check] = method(:port_check)
|
||||||
|
|
||||||
|
@app.call(env)
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def port_check(port)
|
||||||
|
host_machine = @machine.provider.host_vm
|
||||||
|
host_machine.guest.capability(:port_open_check, port)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue