Expose Podman named pipe in Inspect output

Signed-off-by: Arthur Sengileyev <arthur.sengileyev@gmail.com>
This commit is contained in:
Arthur Sengileyev
2023-01-31 00:11:04 +02:00
parent 90b18d2d9c
commit a909e2f2d5
3 changed files with 35 additions and 27 deletions

View File

@ -373,4 +373,6 @@ type SSHConfig struct {
type ConnectionConfig struct {
// PodmanSocket is the exported podman service socket
PodmanSocket *VMFile `json:"PodmanSocket"`
// PodmanPipe is the exported podman service named pipe (Windows hosts only)
PodmanPipe *VMFile `json:"PodmanPipe"`
}

View File

@ -4,7 +4,9 @@
package machine
import (
"os"
"syscall"
"time"
)
func GetProcessState(pid int) (active bool, exitCode int) {
@ -18,3 +20,24 @@ func GetProcessState(pid int) (active bool, exitCode int) {
syscall.GetExitCodeProcess(handle, &code)
return code == 259, int(code)
}
func PipeNameAvailable(pipeName string) bool {
_, err := os.Stat(`\\.\pipe\` + pipeName)
return os.IsNotExist(err)
}
func WaitPipeExists(pipeName string, retries int, checkFailure func() error) error {
var err error
for i := 0; i < retries; i++ {
_, err = os.Stat(`\\.\pipe\` + pipeName)
if err == nil {
break
}
if fail := checkFailure(); fail != nil {
return fail
}
time.Sleep(250 * time.Millisecond)
}
return err
}

View File

@ -1053,12 +1053,12 @@ func (v *MachineVM) Start(name string, opts machine.StartOptions) error {
func launchWinProxy(v *MachineVM) (bool, string, error) {
machinePipe := toDist(v.Name)
if !pipeAvailable(machinePipe) {
if !machine.PipeNameAvailable(machinePipe) {
return false, "", fmt.Errorf("could not start api proxy since expected pipe is not available: %s", machinePipe)
}
globalName := false
if pipeAvailable(globalPipe) {
if machine.PipeNameAvailable(globalPipe) {
globalName = true
}
@ -1099,7 +1099,7 @@ func launchWinProxy(v *MachineVM) (bool, string, error) {
return globalName, "", err
}
return globalName, pipePrefix + waitPipe, waitPipeExists(waitPipe, 80, func() error {
return globalName, pipePrefix + waitPipe, machine.WaitPipeExists(waitPipe, 80, func() error {
active, exitCode := machine.GetProcessState(cmd.Process.Pid)
if !active {
return fmt.Errorf("win-sshproxy.exe failed to start, exit code: %d (see windows event logs)", exitCode)
@ -1122,27 +1122,6 @@ func getWinProxyStateDir(v *MachineVM) (string, error) {
return stateDir, nil
}
func pipeAvailable(pipeName string) bool {
_, err := os.Stat(`\\.\pipe\` + pipeName)
return os.IsNotExist(err)
}
func waitPipeExists(pipeName string, retries int, checkFailure func() error) error {
var err error
for i := 0; i < retries; i++ {
_, err = os.Stat(`\\.\pipe\` + pipeName)
if err == nil {
break
}
if fail := checkFailure(); fail != nil {
return fail
}
time.Sleep(250 * time.Millisecond)
}
return err
}
func IsWSLInstalled() bool {
cmd := SilentExecCmd("wsl", "--status")
out, err := cmd.StdoutPipe()
@ -1611,11 +1590,15 @@ func (v *MachineVM) Inspect() (*machine.InspectInfo, error) {
return nil, err
}
created, lastUp, _ := v.updateTimeStamps(state == machine.Running)
connInfo := new(machine.ConnectionConfig)
machinePipe := toDist(v.Name)
connInfo.PodmanPipe = &machine.VMFile{Path: `\\.\pipe\` + machinePipe}
created, lastUp, _ := v.updateTimeStamps(state == machine.Running)
return &machine.InspectInfo{
ConfigPath: machine.VMFile{Path: v.ConfigPath},
Created: created,
ConfigPath: machine.VMFile{Path: v.ConfigPath},
ConnectionInfo: *connInfo,
Created: created,
Image: machine.ImageConfig{
ImagePath: machine.VMFile{Path: v.ImagePath},
ImageStream: v.ImageStream,