provisioners/docker: Extract container lookup method

This commit is contained in:
Fabio Rehm 2013-12-04 22:13:17 -02:00
parent c7a5592b96
commit 7e0b0a5a3c
1 changed files with 14 additions and 14 deletions

View File

@ -52,13 +52,7 @@ module VagrantPlugins
end
def container_exists?(id)
@machine.communicate.tap do |comm|
# Docker < 0.7.0 stores container IDs using its short version while
# recent versions use the full container ID
# See https://github.com/dotcloud/docker/pull/2140 for more information
return comm.test("sudo docker ps -a -q | grep -wFq #{id}") ||
comm.test("sudo docker ps -a -q -notrunc | grep -wFq #{id}")
end
lookup_container(id, true)
end
def start_container(id)
@ -68,13 +62,7 @@ module VagrantPlugins
end
def container_running?(id)
@machine.communicate.tap do |comm|
# Docker < 0.7.0 stores container IDs using its short version while
# recent versions use the full container ID
# See https://github.com/dotcloud/docker/pull/2140 for more information
return comm.test("sudo docker ps -q | grep -wFq #{id}") ||
comm.test("sudo docker ps -q -notrunc | grep -wFq #{id}")
end
lookup_container(id)
end
def create_container(config)
@ -85,6 +73,18 @@ module VagrantPlugins
docker run #{args} #{config[:image]} #{config[:cmd]}
]
end
def lookup_container(id, list_all = false)
docker_ps = "sudo docker ps -q"
docker_ps << " -a" if list_all
@machine.communicate.tap do |comm|
# Docker < 0.7.0 stores container IDs using its short version while
# recent versions use the full container ID
# See https://github.com/dotcloud/docker/pull/2140 for more information
return comm.test("#{docker_ps} | grep -wFq #{id}") ||
comm.test("#{docker_ps} -notrunc | grep -wFq #{id}")
end
end
end
end
end