-
Notifications
You must be signed in to change notification settings - Fork 0
/
identity.go
44 lines (39 loc) · 924 Bytes
/
identity.go
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
package neco
import (
"bytes"
"errors"
"os"
"strconv"
"strings"
)
// MyLRN returns logical rack number of own node
func MyLRN() (int, error) {
data, err := os.ReadFile(RackFile)
if err != nil {
return 0, err
}
return strconv.Atoi(string(bytes.TrimSpace(data)))
}
// MyCluster returns cluster name of own node
func MyCluster() (string, error) {
data, err := os.ReadFile(ClusterFile)
if err != nil {
return "", err
}
return string(bytes.TrimSpace(data)), nil
}
// OSCodename returns the OS release codename of the host.
// See man os-release
// e.g. bionic, focal
func OSCodename() (string, error) {
data, err := os.ReadFile("/etc/os-release")
if err != nil {
return "", err
}
for _, l := range strings.Split(string(data), "\n") {
if strings.HasPrefix(l, "VERSION_CODENAME=") {
return l[len("VERSION_CODENAME="):], nil
}
}
return "", errors.New("no VERSION_CODENAME in /etc/os-release")
}