podterminal/pods/manager.go

57 lines
1.0 KiB
Go
Raw Normal View History

2024-01-27 11:20:40 +01:00
package pods
import (
"context"
"log"
"github.com/containers/podman/v4/pkg/bindings"
"github.com/containers/podman/v4/pkg/bindings/containers"
"github.com/containers/podman/v4/pkg/bindings/images"
)
var Socket context.Context
func socketConnection() context.Context {
uri := "unix:///run/podman/podman.sock"
conn, err := bindings.NewConnection(context.Background(), uri)
if err != nil {
log.Fatal(err)
}
return conn
}
func TestPodman() {
_ = socketConnection()
}
func ConnectSocket() {
Socket = socketConnection()
}
func PullImage() {
image := "docker.io/linuxserver/webtop"
conn := Socket
_, err := images.Pull(conn, image, nil)
if err != nil {
log.Println(err)
}
}
func Cleanup() {
containerList, err := containers.List(Socket, nil)
if err != nil {
log.Println(err)
}
for _, container := range containerList {
err = containers.Kill(Socket, container.ID, nil)
if err != nil {
log.Println(err)
}
_, err := containers.Remove(Socket, container.ID, nil)
if err != nil {
log.Println(err)
}
}
}