Mitchell Hashimoto 8c7ab333a0 Squash the f-docker-hostmachine branch.
Initial work

commands/up: make sure all names to with_target_vms are strings

providers/docker: create a docker host VM if needed

providers/docker: executor abstraction for driver to eventually support remote

providers/docker: vagrant executor

providers/docker: support creating the machine

providers/docker: status works if host VM is gone

providers/docker: use start fence to get real docker output

core: Call preserves stack ordering

core: support Message post option

providers/docker: Guard some features with HasSSH checks

providers/docker: much better messaging around create/destroy

providers/docker: output the container ID on create

providers/docker: copy the hostmachine Vagrantfile to the data dir

providers/docker: should make host machine before any up action

providers/docker: HandleBox before the host machine

providers/virtualbox: functional_vboxsf to disable vboxsf

providers/virtualbox: synced folder usable method should take 2 args

providers/docker: default machine name to :default
2014-04-21 13:54:33 -07:00

69 lines
1.9 KiB
Ruby

module VagrantPlugins
module DockerProvider
module Action
class Create
def initialize(app, env)
@app = app
@@mutex ||= Mutex.new
end
def call(env)
@env = env
@machine = env[:machine]
@provider_config = @machine.provider_config
@machine_config = @machine.config
@driver = @machine.provider.driver
guard_cmd_configured!
params = create_params
cid = ''
@@mutex.synchronize do
env[:ui].output(I18n.t("docker_provider.creating"))
env[:ui].detail(" Name: #{params[:name]}")
env[:ui].detail("Image: #{params[:image]}")
cid = @driver.create(params)
end
env[:ui].detail(" \n"+I18n.t(
"docker_provider.created", id: cid[0...16]))
@machine.id = cid
@app.call(env)
end
def create_params
container_name = "#{@env[:root_path].basename.to_s}_#{@machine.name}"
container_name.gsub!(/[^-a-z0-9_]/i, "")
container_name << "_#{Time.now.to_i}"
{
cmd: @provider_config.cmd,
extra_args: @provider_config.create_args,
hostname: @machine_config.vm.hostname,
image: @provider_config.image,
name: container_name,
ports: forwarded_ports,
privileged: @provider_config.privileged,
volumes: @provider_config.volumes,
}
end
def forwarded_ports
@env[:forwarded_ports].map do |fp|
# TODO: Support for the protocol argument
"#{fp[:host]}:#{fp[:guest]}"
end.compact
end
def guard_cmd_configured!
if ! @provider_config.image
raise Errors::ImageNotConfiguredError, name: @machine.name
end
end
end
end
end
end