diff --git a/lib/vagrant-zones/action.rb b/lib/vagrant-zones/action.rb index be20ba5..faf0d55 100644 --- a/lib/vagrant-zones/action.rb +++ b/lib/vagrant-zones/action.rb @@ -117,7 +117,21 @@ def self.action_package def self.action_destroy Vagrant::Action::Builder.new.tap do |b| b.use Call, IsCreated do |_env, b2| - b2.use Destroy + unless _env[:result] + b2.use MessageNotCreated + # Try to destroy anyways + b2.use Call, DestroyConfirm do |env2, b3| + if env2[:result] + b3.use Destroy + end + end + next + end + b2.use Call, DestroyConfirm do |env2, b3| + if env2[:result] + b3.use Destroy + end + end end end end @@ -187,6 +201,7 @@ def self.action_box_remove autoload :Network, action_root.join('network') autoload :Setup, action_root.join('setup') autoload :Start, action_root.join('start') + autoload :MessageNotCreated, action_root.join('message_not_created') autoload :NetworkingCleanup, action_root.join('network_cleanup') autoload :IsCreated, action_root.join('is_created') autoload :NotCreated, action_root.join('not_created') diff --git a/lib/vagrant-zones/action/message_not_created.rb b/lib/vagrant-zones/action/message_not_created.rb new file mode 100644 index 0000000..4fd7d11 --- /dev/null +++ b/lib/vagrant-zones/action/message_not_created.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'log4r' +module VagrantPlugins + module ProviderZone + module Action + # This can be used with 'Call' built-in to check if the machine + # is created and branch in the middleware. + class MessageNotCreated + def initialize(app, _env) + @app = app + @logger = Log4r::Logger.new('vagrant_zones::action') + end + + def call(env) + env[:ui].info I18n.t("vagrant_zones.vm_not_created") + @app.call(env) + end + end + end + end +end + \ No newline at end of file diff --git a/locales/en.yml b/locales/en.yml index dd9241e..59262ea 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -44,6 +44,8 @@ en: Zone failed to shutdown in alloted time ==> graceful_shutdown: |- Asking hypervisor to gracefully stop the zone + vm_not_created: |- + VM not created. Moving on... creating_vnic: |- - Creating VNIC: configure_interface_using_vnic: |-