File: node.go

package info (click to toggle)
golang-github-mesos-mesos-go 0.0.6%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 11,724 kB
  • sloc: makefile: 163
file content (29 lines) | stat: -rw-r--r-- 734 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
package mesosutil

import (
	"os"
	"os/exec"
	"strings"

	log "github.com/golang/glog"
)

//TODO(jdef) copied from kubernetes/pkg/util/node.go
func GetHostname(hostnameOverride string) string {
	hostname := hostnameOverride
	if hostname == "" {
		// Note: We use exec here instead of os.Hostname() because we
		// want the FQDN, and this is the easiest way to get it.
		fqdn, err := exec.Command("hostname", "-f").Output()
		if err != nil || len(fqdn) == 0 {
			log.Errorf("Couldn't determine hostname fqdn, failing back to hostname: %v", err)
			hostname, err = os.Hostname()
			if err != nil {
				log.Fatalf("Error getting hostname: %v", err)
			}
		} else {
			hostname = string(fqdn)
		}
	}
	return strings.TrimSpace(hostname)
}