pkg/podman: Add functions to check if a container/image is a Toolbox
https://github.com/containers/toolbox/pull/318
This commit is contained in:
parent
c75404c056
commit
08e8a80d4c
|
|
@ -19,6 +19,7 @@ package podman
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/HarryMichal/go-version"
|
"github.com/HarryMichal/go-version"
|
||||||
"github.com/containers/toolbox/pkg/shell"
|
"github.com/containers/toolbox/pkg/shell"
|
||||||
|
|
@ -147,6 +148,40 @@ func Inspect(typearg string, target string) (map[string]interface{}, error) {
|
||||||
return info[0], nil
|
return info[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsToolboxContainer(container string) (bool, error) {
|
||||||
|
info, err := Inspect("container", container)
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("failed to inspect container %s", container)
|
||||||
|
}
|
||||||
|
|
||||||
|
labels, _ := info["Config"].(map[string]interface{})["Labels"].(map[string]interface{})
|
||||||
|
if labels["com.redhat.component"] != "fedora-toolbox" &&
|
||||||
|
labels["com.github.debarshiray.toolbox"] != "true" {
|
||||||
|
return false, fmt.Errorf("%s is not a toolbox container", container)
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsToolboxImage(image string) (bool, error) {
|
||||||
|
info, err := Inspect("image", image)
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("failed to inspect image %s", image)
|
||||||
|
}
|
||||||
|
|
||||||
|
if info["Labels"] == nil {
|
||||||
|
return false, fmt.Errorf("%s is not a toolbox image", image)
|
||||||
|
}
|
||||||
|
|
||||||
|
labels := info["Labels"].(map[string]interface{})
|
||||||
|
if labels["com.redhat.component"] != "fedora-toolbox" &&
|
||||||
|
labels["com.github.debarshiray.toolbox"] != "true" {
|
||||||
|
return false, fmt.Errorf("%s is not a toolbox image", image)
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
func SetLogLevel(logLevel logrus.Level) {
|
func SetLogLevel(logLevel logrus.Level) {
|
||||||
LogLevel = logLevel
|
LogLevel = logLevel
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue