// LookupStaticHostV6 looks up the IPv6 addresses for the given host from the hosts file.
172771
func (h *Hostsfile) LookupStaticHostV6(host string) []net.IP {
	return h.lookupStaticHost(h.hmap.byNameV6, host)
}
1361219
func (c *Client) FindHostsForMigration(p *FindHostsForMigrationParameter) (*Host, error) {
	obj, err := c.Request("findHostsForMigration", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*Host), err
}
346334
func (f *Facade) GetHostStatuses(ctx datastore.Context, hostIDs []string, since time.Time) ([]host.HostStatus, error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.GetHostStatuses"))
	if hostIDs == nil {
		return []host.HostStatus{}, nil
	}

	statuses := []host.HostStatus{}
	for _, id := range hostIDs {
		h, err := f.GetHost(ctx, id)
		if err != nil {
			continue
		}

		status := host.HostStatus{HostID: id, HostName: h.Name, MemoryUsage: service.Usage{}}
		active, err := f.zzk.IsHostActive(h.PoolID, h.ID)
		if err != nil {
			continue
		}
		status.Active = active

		expired, _ := f.hostRegistry.IsExpired(h.ID)
		status.Authenticated = !expired

		instances, err := f.GetHostInstances(ctx, since, id)
		if err != nil {
			continue
		}

		for _, i := range instances {
			status.MemoryUsage.Cur += i.MemoryUsage.Cur
			status.MemoryUsage.Max += i.MemoryUsage.Max
			status.MemoryUsage.Avg += i.MemoryUsage.Avg
		}

		statuses = append(statuses, status)
	}

	return statuses, nil
}
859621
func (api *InfraHostsAPI) GetHosts() (result *Hosts, err error) {
	uri := api.client.Endpoint + InfraHostsUrl
	res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
	if err != nil {
		return
	}

	result = &Hosts{}
	err = json.Unmarshal(res, result)
	return
}
1344823
func HostAddress(hostname string) (network.Address, error) {
	if ip := net.ParseIP(hostname); ip != nil {
		addr := network.Address{
			Value: ip.String(),
			Type:  network.DeriveAddressType(ip.String()),
			Scope: network.ScopePublic,
		}
		return addr, nil
	}
	// Only a resolvable hostname may be used as a public address.
	if _, err := netLookupHost(hostname); err != nil {
		return network.Address{}, err
	}
	addr := network.Address{
		Value: hostname,
		Type:  network.HostName,
		Scope: network.ScopePublic,
	}
	return addr, nil
}
286428
func SSHHost(pubilcIp bool) func(multistep.StateBag) (string, error) {
	return func(state multistep.StateBag) (string, error) {
		instance := state.Get("instance").(*cvm.Instance)
		if pubilcIp {
			return *instance.PublicIpAddresses[0], nil
		} else {
			return *instance.PrivateIpAddresses[0], nil
		}
	}
}
62561
func (r *ClearNet) LookupHost(host string) ([]string, error) {
	return net.LookupHost(host)
}
85735
func (s *VPCRouterSetting) FindStaticNAT(globalAddress string, privateAddress string) (int, *VPCRouterStaticNATConfig) {
	for i, c := range s.StaticNAT.Config {
		if c.GlobalAddress == globalAddress && c.PrivateAddress == privateAddress {
			return i, c
		}
	}
	return -1, nil
}
536635
func LookupCNAME(host string, server string, c *dns.Client, m *dns.Msg) (addrs []string, err error) {
	m.SetQuestion(dns.Fqdn(host), dns.TypeCNAME)
	r, _, err := c.Exchange(m, net.JoinHostPort(server, "53"))
	if err != nil {
		return nil, err
	}

	for _, ans := range r.Answer {
		if t, ok := ans.(*dns.CNAME); ok {
			addrs = append(addrs, t.Target)
		}
	}

	return
}
1098934
func (h *Hostsfile) LookupStaticAddr(addr string) []string {
	h.RLock()
	defer h.RUnlock()
	addr = parseLiteralIP(addr).String()
	if addr == "" {
		return nil
	}
	if len(h.hmap.byAddr) != 0 {
		if hosts, ok := h.hmap.byAddr[addr]; ok {
			hostsCp := make([]string, len(hosts))
			copy(hostsCp, hosts)
			return hostsCp
		}
	}
	return nil
}
555232
func (s *HostService) FindHostsForMigration(p *FindHostsForMigrationParams) (*FindHostsForMigrationResponse, error) {
	resp, err := s.cs.newRequest("findHostsForMigration", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r FindHostsForMigrationResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
424843
func (s *Stat) HostInfos() *HostInfos {
	s.Lock()
	stats := C.sg_get_host_info(nil)
	s.Unlock()

	hi := &HostInfos{
		OSName:    C.GoString(stats.os_name),
		OSRelease: C.GoString(stats.os_release),
		OSVersion: C.GoString(stats.os_version),
		Platform:  C.GoString(stats.platform),
		HostName:  C.GoString(stats.hostname),
		NCPUs:     int(stats.ncpus),
		MaxCPUs:   int(stats.maxcpus),
		BitWidth:  int(stats.bitwidth),
		//TODO: uptime
	}

	return hi
}
1193251
func HostsWithoutPort(hps []HostPort) []Address {
	addrs := make([]Address, len(hps))
	for i, hp := range hps {
		addrs[i] = hp.Address
	}
	return addrs
}
1337629
func initAPIHostPorts(c agent.ConfigSetter, st *state.State, addrs []network.Address, apiPort int) error {
	hostPorts := network.AddressesWithPort(addrs, apiPort)
	return st.SetAPIHostPorts([][]network.HostPort{hostPorts})
}
1163475
func (r *ClearNet) LookupSRV(service, proto, name string) (string, []*net.SRV, error) {
	return net.LookupSRV(service, proto, name)
}
885225
func getHostStatuses(w *rest.ResponseWriter, r *rest.Request, ctx *requestContext) {
	facade := ctx.getFacade()
	dataCtx := ctx.getDatastoreContext()

	values := r.URL.Query()

	var hostIDs []string
	if _, ok := values["hostId"]; ok {
		hostIDs = values["hostId"]
	} else {
		hosts, err := facade.GetReadHosts(dataCtx)
		if err != nil {
			restServerError(w, err)
			return
		}

		hostIDs = make([]string, len(hosts))
		for i, host := range hosts {
			hostIDs[i] = host.ID
		}
	}

	since := values.Get("since")
	var duration time.Duration
	if since == "" {
		duration = time.Hour
	} else {
		tint, err := strconv.ParseInt(since, 10, 64)
		if err != nil {
			restServerError(w, err)
			return
		}
		duration = time.Duration(tint) * time.Millisecond
	}

	statuses, err := facade.GetHostStatuses(dataCtx, hostIDs, time.Now().Add(-duration))
	if err != nil {
		restServerError(w, err)
		return
	}

	w.WriteJson(statuses)
}
436899
func (ipl *IPList) Lookup(ip net.IP) (r Range, ok bool) {
	if ipl == nil {
		return
	}
	// TODO: Perhaps all addresses should be converted to IPv6, if the future
	// of IP is to always be backwards compatible. But this will cost 4x the
	// memory for IPv4 addresses?
	v4 := ip.To4()
	if v4 != nil {
		r, ok = ipl.lookup(v4)
		if ok {
			return
		}
	}
	v6 := ip.To16()
	if v6 != nil {
		return ipl.lookup(v6)
	}
	if v4 == nil && v6 == nil {
		r = Range{
			Description: "bad IP",
		}
		ok = true
	}
	return
}