From ff2f035f27f058fe204208b9e66b3472f58407cd Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 5 May 2014 21:37:02 -0700 Subject: [PATCH] providers/docker: less hack way to clear ID if not created --- plugins/providers/docker/action.rb | 1 - plugins/providers/docker/action/destroy.rb | 25 +++++++++------------- plugins/providers/docker/provider.rb | 3 +++ 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/plugins/providers/docker/action.rb b/plugins/providers/docker/action.rb index e0ed042a3..3c84e9951 100644 --- a/plugins/providers/docker/action.rb +++ b/plugins/providers/docker/action.rb @@ -143,7 +143,6 @@ module VagrantPlugins b.use Call, IsState, :not_created do |env, b2| if env[:result] b2.use Message, I18n.t("docker_provider.messages.not_created") - b2.use Destroy next end diff --git a/plugins/providers/docker/action/destroy.rb b/plugins/providers/docker/action/destroy.rb index a33c629cd..37ae14df8 100644 --- a/plugins/providers/docker/action/destroy.rb +++ b/plugins/providers/docker/action/destroy.rb @@ -7,25 +7,20 @@ module VagrantPlugins end def call(env) + env[:ui].info I18n.t("docker_provider.messages.destroying") + machine = env[:machine] + driver = machine.provider.driver - # If the container actually exists, destroy it - if machine.state.id != :not_created - driver = machine.provider.driver - - # If we have a build image, store that - image_file = machine.data_dir.join("docker_build_image") - image = nil - if image_file.file? - image = image_file.read.chomp - end - env[:build_image] = image - - env[:ui].info I18n.t("docker_provider.messages.destroying") - driver.rm(machine.id) + # If we have a build image, store that + image_file = machine.data_dir.join("docker_build_image") + image = nil + if image_file.file? + image = image_file.read.chomp end + env[:build_image] = image - # Otherwise, always make sure we remove the ID + driver.rm(machine.id) machine.id = nil @app.call(env) diff --git a/plugins/providers/docker/provider.rb b/plugins/providers/docker/provider.rb index babc3765f..b2c1f2fe2 100644 --- a/plugins/providers/docker/provider.rb +++ b/plugins/providers/docker/provider.rb @@ -146,6 +146,9 @@ module VagrantPlugins state_id = driver.state(@machine.id) if @machine.id && !state_id state_id = :unknown if !state_id + # If the machine is not created, make sure to clear out machine ID + @machine.id = nil if state_id == :not_created + short = state_id.to_s.gsub("_", " ") long = I18n.t("docker_provider.status.#{state_id}")