podman
45 строк · 1.2 Кб
1//go:build amd64 || arm64
2
3package connection4
5import (6"fmt"7"strconv"8
9"github.com/containers/podman/v5/pkg/machine/define"10)
11
12// AddSSHConnectionsToPodmanSocket adds SSH connections to the podman socket if
13// no ignition path is provided
14func AddSSHConnectionsToPodmanSocket(uid, port int, identityPath, name, remoteUsername string, opts define.InitOptions) error {15if len(opts.IgnitionPath) > 0 {16fmt.Println("An ignition path was provided. No SSH connection was added to Podman")17return nil18}19
20cons := createConnections(name, uid, port, remoteUsername)21
22// The first connection defined when connections is empty will become the default23// regardless of IsDefault, so order according to rootful24if opts.Rootful {25cons[0], cons[1] = cons[1], cons[0]26}27
28return addConnection(cons, identityPath, opts.IsDefault)29}
30
31func createConnections(name string, uid, port int, remoteUsername string) []connection {32uri := makeSSHURL(LocalhostIP, fmt.Sprintf("/run/user/%d/podman/podman.sock", uid), strconv.Itoa(port), remoteUsername)33uriRoot := makeSSHURL(LocalhostIP, "/run/podman/podman.sock", strconv.Itoa(port), "root")34
35return []connection{36{37name: name,38uri: uri,39},40{41name: name + "-root",42uri: uriRoot,43},44}45}
46