From edcdf13a9b3b07b96420f1380af4929c51ffbd23 Mon Sep 17 00:00:00 2001 From: Stanislas Lange Date: Mon, 5 Oct 2020 00:37:17 +0200 Subject: [PATCH] fix: destroy attached volumes after a server destroy Fixes https://github.com/kaorimatz/vagrant-scaleway/issues/15. A `vagrant destroy` when the server is running will call `server.terminate`, which destroys attached volumes. A `vagrant destroy` when the server is halted will call `server.destroy`, which does not destroy attached volumes. This commit addresses the second case and delete each volume seperately. --- lib/vagrant-scaleway/action/destroy_server.rb | 3 +++ locales/en.yml | 2 ++ 2 files changed, 5 insertions(+) diff --git a/lib/vagrant-scaleway/action/destroy_server.rb b/lib/vagrant-scaleway/action/destroy_server.rb index 009f300..4b450e7 100644 --- a/lib/vagrant-scaleway/action/destroy_server.rb +++ b/lib/vagrant-scaleway/action/destroy_server.rb @@ -9,12 +9,15 @@ def initialize(app, _env) def call(env) server = env[:scaleway_compute].servers.get(env[:machine].id) + volumes = env[:scaleway_compute].servers.get(env[:machine].id).volumes # Destroy the server and remove the tracking ID env[:ui].info(I18n.t('vagrant_scaleway.destroying')) begin server.destroy + env[:ui].info(I18n.t('vagrant_scaleway.destroying_volume')) + volumes.each_value(&:destroy) rescue Fog::Scaleway::Compute::InvalidRequestError => e if e.message =~ /server should be stopped/ server.terminate(false) diff --git a/locales/en.yml b/locales/en.yml index 15e0921..ad01b31 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -15,6 +15,8 @@ en: Stopping the server... destroying: |- Destroying the server... + destroying_volume: |- + Destroying orphan attached volume... waiting_for_ready: |- Waiting for server to become "ready"... waiting_for_ssh: |-