Class: VagrantPlugins::OrbStack::Action::Destroy
- Inherits:
-
Object
- Object
- VagrantPlugins::OrbStack::Action::Destroy
- Includes:
- MachineValidation
- Defined in:
- lib/vagrant-orbstack/action/destroy.rb
Overview
Action middleware for destroying (deleting) OrbStack machines
This middleware handles permanent removal of OrbStack machines, including deletion from OrbStack and cleanup of local metadata files. The operation is idempotent and uses a best-effort cleanup strategy: if the OrbStack CLI deletion fails (e.g., machine already deleted or daemon offline), local cleanup continues anyway to ensure Vagrant state remains consistent.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Execute the middleware.
-
#initialize(app, _env) ⇒ Destroy
constructor
Initialize the middleware.
Methods included from MachineValidation
Constructor Details
#initialize(app, _env) ⇒ Destroy
Initialize the middleware.
32 33 34 |
# File 'lib/vagrant-orbstack/action/destroy.rb', line 32 def initialize(app, _env) @app = app end |
Instance Method Details
#call(env) ⇒ Object
Execute the middleware.
Destroys the machine by:
- Calling OrbStack CLI delete command (best-effort)
- Removing id and metadata.json files from data directory
- Invalidating state cache
- Continuing middleware chain
If the OrbStack CLI delete fails, a warning is logged and cleanup continues. This ensures Vagrant can clean up its local state even if the machine was already deleted manually or OrbStack is offline.
rubocop:disable Metrics/MethodLength, Metrics/AbcSize
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/vagrant-orbstack/action/destroy.rb', line 53 def call(env) machine = env[:machine] ui = env[:ui] # Handle already-destroyed machines gracefully (idempotency) if machine.id.nil? ui.info('Machine is already destroyed or was never created.') return @app.call(env) end # Validate machine ID exists machine_id = validate_machine_id!(machine, 'destroy') ui.info("Destroying machine '#{machine_id}'...") # Call OrbStack CLI to delete the machine (best-effort) begin Util::OrbStackCLI.delete_machine(machine_id) rescue Errors::CommandExecutionError => e ui.warn("Error deleting machine from OrbStack: #{e.}") ui.warn('Continuing with local cleanup...') end # Clean up metadata files from data_dir (idempotent) FileUtils.rm_f(machine.provider.id_file_path) FileUtils.rm_f(machine.provider.) # Invalidate state cache to ensure fresh state on next query machine.provider.invalidate_state_cache # Continue middleware chain @app.call(env) end |