Skip to content

Commit 0f47b49

Browse files
committed
add wait_time in config
time to wait after started before running * remove this after UTM exposes running state
1 parent 2029863 commit 0f47b49

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
3+
module VagrantPlugins
4+
module Utm
5+
module Action
6+
# This action waits for a given amount of seconds.
7+
# This is a workaround for the UTM provider, which does not
8+
# report when the VM is running. As soon as UTM reports the
9+
# state as 'running', this action can and will be removed.
10+
# Then we use the state 'running', rather than 'started'
11+
class WaitForRunning
12+
def initialize(app, _env)
13+
@app = app
14+
end
15+
16+
def call(env)
17+
# set the wait time to use configures time or
18+
# default to 10 seconds.
19+
wait_time = env[:machine].provider_config.wait_time
20+
env[:ui].info I18n.t("vagrant.boot_waiting")
21+
sleep(wait_time)
22+
23+
@app.call(env)
24+
end
25+
end
26+
end
27+
end
28+
end

lib/vagrant_utm/config.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,19 @@ class Config < Vagrant.plugin("2", :config)
2828
# @return [Array]
2929
attr_reader :customizations
3030

31+
# The time to wait for the VM to be 'running' after 'started'.
32+
#
33+
# @return [Integer]
34+
attr_accessor :wait_time
35+
3136
# Initialize the configuration with unset values.
3237
def initialize
3338
super
3439
@check_guest_additions = UNSET_VALUE
3540
@customizations = []
3641
@name = UNSET_VALUE
3742
@utm_file_url = UNSET_VALUE
43+
@wait_time = UNSET_VALUE
3844
end
3945

4046
# Customize the VM by calling 'osascript' with the given
@@ -71,8 +77,11 @@ def cpus=(count)
7177
# This is the hook that is called to finalize the object before it
7278
# is put into use.
7379
def finalize!
80+
@check_guest_additions = true if @check_guest_additions == UNSET_VALUE
81+
# The default name is just nothing, and we default it
7482
@name = nil if @name == UNSET_VALUE
7583
@utm_file_url = nil if @utm_file_url == UNSET_VALUE
84+
@wait_time = 10 if @wait_time == UNSET_VALUE
7685
end
7786
end
7887
end

lib/vagrant_utm/provider.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ def initialize(machine)
4343
machine_id_changed
4444
end
4545

46+
# Execute the action with the given name.
47+
def action(name)
48+
action_method = "action_#{name}"
49+
return Action.send(action_method) if Action.respond_to?(action_method)
50+
51+
nil
52+
end
53+
4654
# If the machine ID changed, then we need to rebuild our underlying
4755
# driver.
4856
def machine_id_changed
@@ -63,6 +71,8 @@ def machine_id_changed
6371
# Returns the SSH info for accessing the UTM VM.
6472
def ssh_info
6573
# If the VM is not running (utm, started) that we can't possibly SSH into it
74+
# TODO: We should use the state 'running', rather than 'started'
75+
# This is a workaround for the UTM provider, which does not expose 'running' state
6676
return nil if state.id != :started
6777

6878
# If there is port forwarding, GuestPort 22 to HostPort XXXX,
@@ -81,14 +91,6 @@ def ssh_info
8191
}
8292
end
8393

84-
# Execute the action with the given name.
85-
def action(name)
86-
action_method = "action_#{name}"
87-
return Action.send(action_method) if Action.respond_to?(action_method)
88-
89-
nil
90-
end
91-
9294
# Return the state of UTM virtual machine by actually
9395
# querying utmctl.
9496
#

0 commit comments

Comments
 (0)