File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed
Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,26 @@ class VMManager: NSObject, ObservableObject {
8282 } . value
8383 }
8484
85+ private func fetchIP( macAddress: String ) async throws -> String {
86+ var leaseTries = 0
87+
88+ while true {
89+ let ipResult = Result {
90+ try LeaseParser . leaseForMacAddress ( mac: macAddress) . ipAddress
91+ }
92+ switch ipResult {
93+ case let . success( ip) :
94+ return ip
95+ case let . failure( err) :
96+ if leaseTries >= 5 {
97+ throw err
98+ }
99+ try await Task . sleep ( for: . seconds( 5 ) )
100+ leaseTries += 1
101+ }
102+ }
103+ }
104+
85105 @MainActor
86106 private func setupAndRunVirtualMachine( ) async throws {
87107 try await cloneBundle ( )
@@ -93,7 +113,7 @@ class VMManager: NSObject, ObservableObject {
93113 SSHLogger . shared. log ( string: " ---------- Starting Up ---------- \n " )
94114 try await virtualMachine. start ( )
95115 vmState = . running( virtualMachine)
96- self . ip = try LeaseParser . leaseForMacAddress ( mac : masterBundle . configuration. macAddress. string) . ipAddress
116+ self . ip = try await fetchIP ( macAddress : clonedBundle . configuration. macAddress. string)
97117
98118 let client = try await SSHClient . connect (
99119 host: ip,
You can’t perform that action at this time.
0 commit comments