2014-04-11 01:26:19 +00:00
|
|
|
require "log4r"
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module DockerProvider
|
|
|
|
module Action
|
|
|
|
# This action is responsible for creating the host machine if
|
|
|
|
# we need to. The host machine is where Docker containers will
|
|
|
|
# live.
|
|
|
|
class HostMachine
|
|
|
|
def initialize(app, env)
|
|
|
|
@app = app
|
|
|
|
@logger = Log4r::Logger.new("vagrant::docker::hostmachine")
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
if !env[:machine].provider.host_vm?
|
|
|
|
@logger.info("No host machine needed.")
|
|
|
|
return @app.call(env)
|
|
|
|
end
|
|
|
|
|
|
|
|
env[:machine].ui.output(I18n.t(
|
|
|
|
"docker_provider.host_machine_needed"))
|
|
|
|
|
|
|
|
host_machine = env[:machine].provider.host_vm
|
|
|
|
|
2014-04-16 17:35:50 +00:00
|
|
|
begin
|
2014-04-16 21:46:37 +00:00
|
|
|
env[:machine].provider.host_vm_lock do
|
2014-04-16 17:35:50 +00:00
|
|
|
setup_host_machine(host_machine, env)
|
|
|
|
end
|
|
|
|
rescue Vagrant::Errors::EnvironmentLockedError
|
|
|
|
sleep 1
|
|
|
|
retry
|
|
|
|
end
|
|
|
|
|
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def setup_host_machine(host_machine, env)
|
2014-04-11 01:26:19 +00:00
|
|
|
# Create a UI for this machine that stays at the detail level
|
|
|
|
proxy_ui = host_machine.ui.dup
|
|
|
|
proxy_ui.opts[:bold] = false
|
|
|
|
proxy_ui.opts[:prefix_spaces] = true
|
|
|
|
proxy_ui.opts[:target] = env[:machine].name.to_s
|
|
|
|
|
2014-04-16 18:59:08 +00:00
|
|
|
# See if the machine is ready already. If not, start it.
|
|
|
|
if host_machine.communicate.ready?
|
|
|
|
env[:machine].ui.detail(I18n.t("docker_provider.host_machine_ready"))
|
|
|
|
else
|
|
|
|
env[:machine].ui.detail(
|
|
|
|
I18n.t("docker_provider.host_machine_starting"))
|
|
|
|
env[:machine].ui.detail(" ")
|
|
|
|
host_machine.with_ui(proxy_ui) do
|
|
|
|
host_machine.action(:up)
|
|
|
|
end
|
2014-05-21 03:41:48 +00:00
|
|
|
|
|
|
|
# Verify communication is ready. If not, we have a problem.
|
|
|
|
if !host_machine.communicate.ready?
|
|
|
|
raise Errors::HostVMCommunicatorNotReady,
|
|
|
|
id: host_machine.id
|
|
|
|
end
|
2014-04-11 01:26:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|