// hostnameReader, hostnamer created for mocking
761912
func init() {
	host, err := os.Hostname()
	if err != nil {
		log.WithFields(log.Fields{
			"_module": "control",
			"_file":   "metrics.go,",
			"_block":  "addStandardAndWorkflowTags",
			"error":   err.Error(),
		}).Error("Unable to determine hostname")
		host = "not_found"
	}
	hostnameReader = &hostnameReaderType{hostname: host, hostnameRefreshTTL: time.Hour, lastRefresh: time.Now()}
}
606131
func (f *Facade) GetReadHosts(ctx datastore.Context) ([]host.ReadHost, error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.GetReadHosts"))
	hosts, err := f.hostStore.GetN(ctx, 20000)
	if err != nil {
		return nil, err
	}

	return toReadHosts(hosts), nil
}
841833
func (f *Facade) FindReadHostsInPool(ctx datastore.Context, poolID string) ([]host.ReadHost, error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.FindReadHostsInPool"))
	hosts, err := f.hostStore.FindHostsWithPoolID(ctx, poolID)
	if err != nil {
		return nil, err
	}

	return toReadHosts(hosts), nil
}
95517
func ParseCSVSniffAttributeNamesFromReader(r io.ReadSeeker, hasHeaders bool) []string {

	r.Seek(0, 0)
	reader := csv.NewReader(r)
	headers, err := reader.Read()
	if err != nil {
		panic(err)
	}

	if hasHeaders {
		for i, h := range headers {
			headers[i] = strings.TrimSpace(h)
		}
		return headers
	}

	for i := range headers {
		headers[i] = fmt.Sprintf("%d", i)
	}
	return headers

}
278070
func (p *propHost) GetHostName() string {
	if p.Host == nil {
		return ""
	}
	return p.Host.GetName()
}
1305608
func (_class HostClass) SetHostnameLive(sessionID SessionRef, host HostRef, hostname string) (_err error) {
	_method := "host.set_hostname_live"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_hostArg, _err := convertHostRefToXen(fmt.Sprintf("%s(%s)", _method, "host"), host)
	if _err != nil {
		return
	}
	_hostnameArg, _err := convertStringToXen(fmt.Sprintf("%s(%s)", _method, "hostname"), hostname)
	if _err != nil {
		return
	}
	_, _err =  _class.client.APICall(_method, _sessionIDArg, _hostArg, _hostnameArg)
	return
}
1032946
func getAllHostnames() []string {
	res := []string{}
	for j := 0; j < 10; j++ {
		res = append(res, fmt.Sprintf("host%d", j))
	}
	return res
}
1312469
func (e TabletStats) GetHostNameLevel(level int) string {
	chunkedHostname := strings.Split(e.Tablet.Hostname, ".")

	if level < 0 {
		return chunkedHostname[0]
	} else if level >= len(chunkedHostname) {
		return chunkedHostname[len(chunkedHostname)-1]
	} else {
		return chunkedHostname[level]
	}
}
364792
func getNodeName(cloud cloudprovider.Interface, hostname string) (types.NodeName, error) {
	if cloud == nil {
		return types.NodeName(hostname), nil
	}

	instances, ok := cloud.Instances()
	if !ok {
		return "", fmt.Errorf("failed to get instances from cloud provider")
	}

	nodeName, err := instances.CurrentNodeName(context.TODO(), hostname)
	if err != nil {
		return "", fmt.Errorf("error fetching current node name from cloud provider: %v", err)
	}

	klog.V(2).Infof("cloud provider determined current node name to be %s", nodeName)

	return nodeName, nil
}
800988
func HostnameFromAddr(addr string) (string, error) {
	p, err := url.Parse(addr)
	if err != nil {
		return "", err
	}
	h := p.Host

	// copied from https://golang.org/src/net/http/transport.go
	if hasPort(h) {
		h = h[:strings.LastIndex(h, ":")]
	}

	return h, nil
}
762301
func ForHostname(proc *process.Process, hostname string, bindingAddress net.IP, port uint16, publishedAddress net.IP) (Messenger, error) {
	upid := upid.UPID{
		ID:   proc.Label(),
		Port: strconv.Itoa(int(port)),
	}
	host, err := UPIDBindingAddress(hostname, bindingAddress)
	if err != nil {
		return nil, err
	}

	var publishedHost string
	if publishedAddress != nil {
		publishedHost, err = UPIDBindingAddress(hostname, publishedAddress)
		if err != nil {
			return nil, err
		}
	}

	if publishedHost != "" {
		upid.Host = publishedHost
	} else {
		upid.Host = host
	}

	return NewHttpWithBindingAddress(upid, bindingAddress), nil
}
786584
func WithHostname(name string) SpecOpts {
	return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
		s.Hostname = name
		return nil
	}
}
1092464
func Hostname() string {
	hostname := os.Getenv("HOSTNAME")
	if len(hostname) > 0 {
		return hostname
	}
	hostname, err := os.Hostname()
	if err == nil {
		return hostname
	}
	return "localhost"
}
398323
func CheckHostnameIPMismatch(local string, hostsMap map[string][]string) ([]string, error) {
	var message string

	test := func(message string, filter func(string) bool) ([]string, error) {
		var mismatched []string

		for _, hostports := range hostsMap {
			for _, hostport := range hostports {
				if filter(hostport) {
					mismatched = append(mismatched, hostport)
				}
			}
		}

		if len(mismatched) > 0 {
			return mismatched, errors.New(message)
		}

		return nil, nil
	}

	if HostportPattern.MatchString(local) {
		message = "Your host identifier looks like an IP address and there are bootstrap " +
			"hosts that appear to be specified with hostnames. These inconsistencies may " +
			"lead to subtle node communication issues."
		return test(message, func(hostport string) bool {
			return !HostportPattern.MatchString(hostport)
		})
	}

	message = "Your host identifier looks like a hostname and there are bootstrap hosts " +
		"that appear to be specified with IP addresses. These inconsistencies may lead " +
		"to subtle node communication issues"

	return test(message, func(hostport string) bool {
		return HostportPattern.MatchString(hostport)
	})
}
1330733
func (m *MockProvisioner_ProvisionResourceServer) SetHeader(arg0 metadata.MD) error {
	m.ctrl.T.Helper()
	ret := m.ctrl.Call(m, "SetHeader", arg0)
	ret0, _ := ret[0].(error)
	return ret0
}
713185
func NameFromEnv() string {
	n := os.Getenv(EnvName)
	if n == "" {
		return os.Getenv("HOSTNAME")
	}
	return n
}
725032
func (network *network) hostnameToIP(rname string) net.IP {
	var matchedIP net.IP

	match := network.RegexMatchIP.FindStringSubmatch(rname)
	if len(match) != 2 {
		return nil
	}

	if network.IPnet.IP.To4() != nil {
		matchedIP = net.ParseIP(match[1])
	} else {
		// TODO: can probably just allocate a []byte and use that.
		var buf bytes.Buffer
		// convert back to an valid ipv6 string with colons
		for i := 0; i < 8*4; i += 4 {
			buf.WriteString(match[1][i : i+4])
			if i < 28 {
				buf.WriteString(":")
			}
		}
		matchedIP = net.ParseIP(buf.String())
	}

	// No valid ip or it does not belong to this network
	if matchedIP == nil || !network.IPnet.Contains(matchedIP) {
		return nil
	}

	return matchedIP
}