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

59 lines
1.7 KiB
Ruby

require "vagrant/util/shell_quote"
module VagrantPlugins
module DockerProvider
module Executor
# The Vagrant executor runs Docker over SSH against the given
# Vagrant-managed machine.
class Vagrant
def initialize(host_machine)
@host_machine = host_machine
end
def execute(*cmd, &block)
quote = '"'
cmd = cmd.map do |a|
"#{quote}#{::Vagrant::Util::ShellQuote.escape(a, quote)}#{quote}"
end.join(" ")
# Add a start fence so we know when to start reading output.
# We have to do this because boot2docker outputs a login shell
# boot2docker version that we get otherwise and messes up output.
start_fence = "========== VAGRANT DOCKER BEGIN =========="
ssh_cmd = "echo \"#{start_fence}\"; #{cmd}"
stderr = ""
stdout = ""
fenced = false
comm = @host_machine.communicate
code = comm.execute(ssh_cmd, error_check: false) do |type, data|
next if ![:stdout, :stderr].include?(type)
stderr << data if type == :stderr
stdout << data if type == :stdout
if !fenced
index = stdout.index(start_fence)
if index
index += start_fence.length
stdout = stdout[index..-1]
stdout.chomp!
end
end
block.call(type, data) if block && fenced
end
if code != 0
raise Errors::ExecuteError,
command: cmd,
stderr: stderr.chomp,
stdout: stdout.chomp
end
stdout.chomp
end
end
end
end
end