mirror of
https://github.com/getcompanion-ai/computer-host.git
synced 2026-04-15 06:04:38 +00:00
feat: firecracker mmds identity
This commit is contained in:
parent
500354cd9b
commit
3eb610b703
23 changed files with 1813 additions and 263 deletions
|
|
@ -30,15 +30,15 @@ func waitForGuestReady(ctx context.Context, host string, ports []contracthost.Ma
|
|||
|
||||
func waitForGuestPort(ctx context.Context, host string, port contracthost.MachinePort) error {
|
||||
address := net.JoinHostPort(host, strconv.Itoa(int(port.Port)))
|
||||
dialer := net.Dialer{Timeout: defaultGuestDialTimeout}
|
||||
ticker := time.NewTicker(defaultGuestReadyPollInterval)
|
||||
defer ticker.Stop()
|
||||
|
||||
var lastErr error
|
||||
for {
|
||||
connection, err := dialer.DialContext(ctx, string(port.Protocol), address)
|
||||
if err == nil {
|
||||
_ = connection.Close()
|
||||
probeCtx, cancel := context.WithTimeout(ctx, defaultGuestDialTimeout)
|
||||
ready, err := guestPortReady(probeCtx, host, port)
|
||||
cancel()
|
||||
if err == nil && ready {
|
||||
return nil
|
||||
}
|
||||
lastErr = err
|
||||
|
|
@ -50,3 +50,38 @@ func waitForGuestPort(ctx context.Context, host string, port contracthost.Machin
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func guestPortsReady(ctx context.Context, host string, ports []contracthost.MachinePort) (bool, error) {
|
||||
host = strings.TrimSpace(host)
|
||||
if host == "" {
|
||||
return false, fmt.Errorf("guest runtime host is required")
|
||||
}
|
||||
|
||||
for _, port := range ports {
|
||||
probeCtx, cancel := context.WithTimeout(ctx, defaultGuestDialTimeout)
|
||||
ready, err := guestPortReady(probeCtx, host, port)
|
||||
cancel()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if !ready {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func guestPortReady(ctx context.Context, host string, port contracthost.MachinePort) (bool, error) {
|
||||
address := net.JoinHostPort(host, strconv.Itoa(int(port.Port)))
|
||||
dialer := net.Dialer{Timeout: defaultGuestDialTimeout}
|
||||
|
||||
connection, err := dialer.DialContext(ctx, string(port.Protocol), address)
|
||||
if err == nil {
|
||||
_ = connection.Close()
|
||||
return true, nil
|
||||
}
|
||||
if ctx.Err() != nil {
|
||||
return false, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue