Skip to content

Commit

Permalink
fix: add destroy confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkProminic authored Aug 17, 2024
1 parent 47a3ddb commit f04e30a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/vagrant-zones/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down
23 changes: 23 additions & 0 deletions lib/vagrant-zones/action/message_not_created.rb
Original file line number Diff line number Diff line change
@@ -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

2 changes: 2 additions & 0 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |-
Expand Down

0 comments on commit f04e30a

Please sign in to comment.