mirror of
https://github.com/getcompanion-ai/computer-host.git
synced 2026-04-18 18:03:42 +00:00
feat: phase 1
This commit is contained in:
parent
4a9dc91ebf
commit
6489e270ce
9 changed files with 194 additions and 13 deletions
48
internal/daemon/exec_relay.go
Normal file
48
internal/daemon/exec_relay.go
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
package daemon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
contracthost "github.com/getcompanion-ai/computer-host/contract"
|
||||
)
|
||||
|
||||
func (d *Daemon) EnsureExecRelay(ctx context.Context, id contracthost.MachineID) (*contracthost.GetMachineResponse, error) {
|
||||
unlock := d.lockMachine(id)
|
||||
defer unlock()
|
||||
|
||||
record, err := d.store.GetMachine(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if record.Phase != contracthost.MachinePhaseRunning {
|
||||
return nil, fmt.Errorf("machine %q is not running", id)
|
||||
}
|
||||
if strings.TrimSpace(record.RuntimeHost) == "" {
|
||||
return nil, fmt.Errorf("machine %q runtime host is unavailable", id)
|
||||
}
|
||||
|
||||
d.relayAllocMu.Lock()
|
||||
execRelayPort, err := d.allocateMachineRelayProxy(
|
||||
ctx,
|
||||
*record,
|
||||
contracthost.MachinePortNameExec,
|
||||
record.RuntimeHost,
|
||||
defaultGuestdPort,
|
||||
minMachineExecRelayPort,
|
||||
maxMachineExecRelayPort,
|
||||
)
|
||||
d.relayAllocMu.Unlock()
|
||||
if err != nil {
|
||||
d.stopMachineRelayProxy(record.ID, contracthost.MachinePortNameExec)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
record.Ports = setMachineExecRelayPort(record.Ports, execRelayPort)
|
||||
if err := d.store.UpdateMachine(ctx, *record); err != nil {
|
||||
d.stopMachineRelayProxy(record.ID, contracthost.MachinePortNameExec)
|
||||
return nil, err
|
||||
}
|
||||
return &contracthost.GetMachineResponse{Machine: machineToContract(*record)}, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue