File: podman.go

package info (click to toggle)
golang-github-crc-org-crc 2.34.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,548 kB
  • sloc: sh: 398; makefile: 326; javascript: 40
file content (65 lines) | stat: -rw-r--r-- 1,831 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package podman

import (
	"fmt"
	"path/filepath"

	"github.com/crc-org/crc/v2/pkg/crc/constants"
	crcos "github.com/crc-org/crc/v2/pkg/os"
)

const (
	rootlessConn = "crc"
	rootfulConn  = "crc-root"
)

var podmanExecutablePath = filepath.Join(constants.CrcPodmanBinDir, constants.PodmanRemoteExecutableName)

func run(args ...string) (string, string, error) {
	return crcos.RunWithDefaultLocale(podmanExecutablePath, args...)
}

func addSystemConnection(name, identity, uri string) error {
	if _, stderr, err := run("system", "connection", "add", "--identity", identity, name, uri); err != nil {
		return fmt.Errorf("failed to add podman system connection %v: %s", err, stderr)
	}
	return nil
}

func AddRootlessSystemConnection(sshIdentity, uri string) error {
	return addSystemConnection(rootlessConn, sshIdentity, uri)
}

func AddRootfulSystemConnection(sshIdentity, uri string) error {
	return addSystemConnection(rootfulConn, sshIdentity, uri)
}

func removeSystemConnection(name string) error {
	if _, stderr, err := run("system", "connection", "remove", name); err != nil {
		return fmt.Errorf("failed to remove podman system connection %v: %s", err, stderr)
	}
	return nil
}

func RemoveRootlessSystemConnection() error {
	return removeSystemConnection(rootlessConn)
}

func RemoveRootfulSystemConnection() error {
	return removeSystemConnection(rootfulConn)
}

func makeSystemConnectionDefault(name string) error {
	if _, stderr, err := run("system", "connection", "default", name); err != nil {
		return fmt.Errorf("failed to make %s podman system connection as default %v: %s", name, err, stderr)
	}
	return nil
}

func MakeRootlessSystemConnectionDefault() error {
	return makeSystemConnectionDefault(rootlessConn)
}

func MakeRootfulSystemConnectionDefault() error {
	return makeSystemConnectionDefault(rootfulConn)
}