summaryrefslogtreecommitdiff
path: root/snippets/hyperstack/hyperstack.rb
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-20 23:16:47 +0200
committerPaul Buetow <paul@buetow.org>2026-03-20 23:16:47 +0200
commit3f6ef419f52c3361c8914a27c7949c2c8f2be1c8 (patch)
tree9328d280023c186265e37d849fa8a4de545e05a4 /snippets/hyperstack/hyperstack.rb
parent864da4f8a42d1474810396746dc5a097c573f1d9 (diff)
Parallelize delete-both VM teardown
Diffstat (limited to 'snippets/hyperstack/hyperstack.rb')
-rwxr-xr-xsnippets/hyperstack/hyperstack.rb15
1 files changed, 8 insertions, 7 deletions
diff --git a/snippets/hyperstack/hyperstack.rb b/snippets/hyperstack/hyperstack.rb
index a18bcf7..7cd817d 100755
--- a/snippets/hyperstack/hyperstack.rb
+++ b/snippets/hyperstack/hyperstack.rb
@@ -1514,11 +1514,11 @@ module HyperstackVM
continue_create(state)
end
- def delete(vm_id: nil, preserve_state_on_failure: false, dry_run: false)
+ def delete(vm_id: nil, preserve_state_on_failure: false, dry_run: false, skip_local_cleanup: false)
state = @state_store.load
target_vm_id = vm_id || state&.dig('vm_id')
raise Error, "No VM ID provided and no state file found at #{@state_store.path}." if target_vm_id.nil?
- cleanup_local = state && target_vm_id == state['vm_id']
+ cleanup_local = !skip_local_cleanup && state && target_vm_id == state['vm_id']
if dry_run
print_delete_dry_run(target_vm_id, state, preserve_state_on_failure: preserve_state_on_failure)
@@ -2688,20 +2688,21 @@ module HyperstackVM
def run_delete_both(dry_run:)
out_mutex = Mutex.new
+ errors_mutex = Mutex.new
errors = {}
loaders = pair_config_loaders
local_wg_out = PrefixedOutput.new('[local-wireguard] ', $stdout, out_mutex)
-
- loaders.each_with_index do |loader, index|
+ threads = loaders.each_with_index.map do |loader, index|
label = "vm#{index + 1}"
manager = build_manager(loader.config, out: PrefixedOutput.new("[#{label}] ", $stdout, out_mutex))
- begin
- manager.delete(dry_run: dry_run)
+ Thread.new do
+ manager.delete(dry_run: dry_run, skip_local_cleanup: true)
rescue Error => e
- errors[label.to_sym] = e.message
+ errors_mutex.synchronize { errors[label.to_sym] = e.message }
end
end
+ threads.each(&:join)
if errors.empty?
allowed_ips = loaders.map { |loader| "#{loader.config.wireguard_gateway_ip}/32" }