Class: VagrantPlugins::OrbStack::Action::Halt

Inherits:
Object
  • Object
show all
Includes:
MachineValidation
Defined in:
lib/vagrant-orbstack/action/halt.rb

Overview

Action middleware for halting (stopping) OrbStack machines

This middleware handles stopping a running OrbStack machine gracefully. It calls the OrbStack CLI to stop the machine and invalidates the provider's state cache to ensure subsequent state queries are fresh.

Examples:

Usage in action builder

Vagrant::Action::Builder.new.tap do |b|
  b.use VagrantPlugins::OrbStack::Action::Halt
end

Instance Method Summary collapse

Methods included from MachineValidation

#validate_machine_id!

Constructor Details

#initialize(app, _env) ⇒ Halt

Initialize the middleware.

Parameters:

  • app (Object)

    The next middleware in the chain

  • env (Hash)

    The environment hash containing :machine, :ui, etc.



29
30
31
# File 'lib/vagrant-orbstack/action/halt.rb', line 29

def initialize(app, _env)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

Execute the middleware.

Halts the machine by calling OrbStack CLI stop command, then invalidates the state cache to ensure fresh state queries.

Parameters:

  • env (Hash)

    The environment hash

Returns:

  • (Object)

    Result from next middleware

Raises:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/vagrant-orbstack/action/halt.rb', line 43

def call(env)
  machine = env[:machine]
  ui = env[:ui]

  # Validate machine ID exists
  machine_id = validate_machine_id!(machine, 'halt')

  ui.info("Halting machine '#{machine_id}'...")

  # Call OrbStack CLI to stop the machine
  Util::OrbStackCLI.stop_machine(machine_id)

  # Invalidate state cache to ensure fresh state on next query
  machine.provider.invalidate_state_cache

  # Continue middleware chain
  @app.call(env)
end