mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00
Add default remote socket path if empty
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
package bindings
|
package bindings
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -210,6 +211,22 @@ func sshClient(_url *url.URL, uri string, identity string, machine bool) (Connec
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return connection, newConnectError(err)
|
return connection, newConnectError(err)
|
||||||
}
|
}
|
||||||
|
if _url.Path == "" {
|
||||||
|
session, err := conn.NewSession()
|
||||||
|
if err != nil {
|
||||||
|
return connection, err
|
||||||
|
}
|
||||||
|
defer session.Close()
|
||||||
|
|
||||||
|
var b bytes.Buffer
|
||||||
|
session.Stdout = &b
|
||||||
|
if err := session.Run(
|
||||||
|
"podman info --format '{{.Host.RemoteSocket.Path}}'"); err != nil {
|
||||||
|
return connection, err
|
||||||
|
}
|
||||||
|
val := strings.TrimSuffix(b.String(), "\n")
|
||||||
|
_url.Path = val
|
||||||
|
}
|
||||||
dialContext := func(ctx context.Context, _, _ string) (net.Conn, error) {
|
dialContext := func(ctx context.Context, _, _ string) (net.Conn, error) {
|
||||||
return ssh.DialNet(conn, "unix", _url)
|
return ssh.DialNet(conn, "unix", _url)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user