1
0
mirror of https://github.com/rancher/os.git synced 2025-09-01 23:04:41 +00:00

First class consoles

This commit is contained in:
Josh Curl
2016-06-06 15:13:15 -07:00
parent b83f0ec092
commit 719d255636
16 changed files with 302 additions and 103 deletions

View File

@@ -1,7 +1,9 @@
package util
import (
"bufio"
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
@@ -13,6 +15,10 @@ import (
log "github.com/Sirupsen/logrus"
)
const (
DOCKER_CGROUPS_FILE = "/proc/self/cgroup"
)
type AnyMap map[interface{}]interface{}
func Contains(values []string, value string) bool {
@@ -187,3 +193,35 @@ func TrimSplitN(str, sep string, count int) []string {
func TrimSplit(str, sep string) []string {
return TrimSplitN(str, sep, -1)
}
func GetCurrentContainerId() (string, error) {
file, err := os.Open(DOCKER_CGROUPS_FILE)
if err != nil {
return "", err
}
fileReader := bufio.NewScanner(file)
if !fileReader.Scan() {
return "", errors.New("Empty file /proc/self/cgroup")
}
line := fileReader.Text()
parts := strings.Split(line, "/")
for len(parts) != 3 {
if !fileReader.Scan() {
return "", errors.New("Found no docker cgroups")
}
line = fileReader.Text()
parts = strings.Split(line, "/")
if len(parts) == 3 {
if strings.HasSuffix(parts[1], "docker") {
break
} else {
parts = nil
}
}
}
return parts[len(parts)-1:][0], nil
}