// RestHost handles HTTP requests of DNS A records of the given host.
420998
func (res *Resolver) RestHost(req *restful.Request, resp *restful.Response) {
	host := req.PathParameter("host")
	// clean up host name
	dom := strings.ToLower(cleanWild(host))
	if dom[len(dom)-1] != '.' {
		dom += "."
	}
	rs := res.records()

	type record struct {
		Host string `json:"host"`
		IP   string `json:"ip"`
	}

	aRRs := rs.As[dom]
	aaaaRRs := rs.AAAAs[dom]
	records := make([]record, 0, len(aRRs)+len(aaaaRRs))
	for ip := range aRRs {
		records = append(records, record{dom, ip})
	}
	for ip := range aaaaRRs {
		records = append(records, record{dom, ip})
	}

	if len(records) == 0 {
		records = append(records, record{})
	}

	if err := resp.WriteAsJson(records); err != nil {
		logging.Error.Println(err)
	}

	stats(dom, res.config.Domain+".", len(aRRs) > 0)
}
254474
func restAddHost(w *rest.ResponseWriter, r *rest.Request, ctx *requestContext) {
	var payload addHostRequest
	err := r.DecodeJsonPayload(&payload)
	if err != nil {
		glog.V(1).Infof("Could not decode host payload: %v", err)
		restBadRequest(w, err)
		return
	}
	ipAddr := payload.IPAddr
	parts := strings.Split(ipAddr, ":")
	hostIPAddr, err := net.ResolveIPAddr("ip", parts[0])
	if err != nil {
		glog.Errorf("%s could not be resolved", parts[0])
		restBadRequest(w, err)
		return
	}
	hostIP := hostIPAddr.IP.String()

	if len(parts) < 2 {
		glog.Errorf("rpcport needs to be specified")
		restBadRequest(w, err)
		return
	}

	rpcPort, err := strconv.Atoi(parts[1])
	if err != nil {
		glog.Errorf("could not convert rpcport %s to int", parts[1])
		restBadRequest(w, err)
		return
	}

	natIpAddr := payload.NatAddr
	var natHostIP string
	var natHostPort int
	if payload.UseNat {
		natParts := strings.Split(natIpAddr, ":")
		natHostIPAddr, err := net.ResolveIPAddr("ip", natParts[0])
		if err != nil {
			glog.Errorf("NAT host %s could not be resolved", natParts[0])
			restBadRequest(w, err)
			return
		}
		natHostIP = natHostIPAddr.IP.String()
		if len(natParts) < 2 {
			glog.Errorf("NAT port needs to be specified")
			restBadRequest(w, err)
			return
		}
		natHostPort, err = strconv.Atoi(natParts[1])
		if err != nil {
			glog.Errorf("could not convert NAT port %s to int", natParts[1])
			restBadRequest(w, err)
			return
		}
	}

	nat := utils.URL{
		Host: natHostIP,
		Port: natHostPort,
	}

	// Check to see if the nat address is set.
	var rpcAddress string
	if len(nat.Host) > 0 {
		// connect via rpc using that address.
		rpcAddress = nat.String()
	} else {
		// connect via rpc using the host address.
		rpcAddress = payload.IPAddr
	}

	agentClient, err := agent.NewClient(rpcAddress)
	if err != nil {
		glog.Errorf("Could not create connection to host %s: %v", payload.IPAddr, err)
		restServerError(w, err)
		return
	}

	buildRequest := agent.BuildHostRequest{
		IP:     hostIP,
		Port:   rpcPort,
		PoolID: payload.PoolID,
		Memory: payload.RAMLimit,
	}
	host, err := agentClient.BuildHost(buildRequest)
	if err != nil {
		glog.Errorf("Unable to get remote host info: %v", err)
		restBadRequest(w, err)
		return
	}

	facade := ctx.getFacade()
	dataCtx := ctx.getDatastoreContext()
	privateKey, err := facade.AddHost(dataCtx, host)
	if err != nil {
		glog.Errorf("Unable to add host: %v", err)
		restServerError(w, err)
		return
	}
	glog.V(0).Info("Added host ", host.ID)
	var registered bool
	if err := facade.RegisterHostKeys(dataCtx, host, nat, privateKey[:], false); err != nil {
		glog.V(2).Infof("Unable to register keys for host %s automatically (%s)", host.ID, err)
	} else {
		registered = true
	}
	w.WriteJson(&addHostResponse{simpleResponse{"Added host", hostLinks(host.ID)}, string(privateKey[:]), registered})
}
158297
func (_m *ClientInterface) GetHost(hostID string) (*host.Host, error) {
	ret := _m.Called(hostID)

	var r0 *host.Host
	if rf, ok := ret.Get(0).(func(string) *host.Host); ok {
		r0 = rf(hostID)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).(*host.Host)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(string) error); ok {
		r1 = rf(hostID)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
1164217
func host(in string) string {
	out, err := utils.Host(in)
	if err != nil {
		return in
	}
	return out
}
1237614
func ParseHost(defaultToTLS bool, val string) (string, error) {
	host := strings.TrimSpace(val)
	if host == "" {
		if defaultToTLS {
			host = DefaultTLSHost
		} else {
			host = DefaultHost
		}
	} else {
		var err error
		host, err = parseDockerDaemonHost(host)
		if err != nil {
			return val, err
		}
	}
	return host, nil
}
238202
func (k *TupleKey6Global) ToHost() TupleKey {
	return &TupleKey6Global{
		TupleKey6: *k.TupleKey6.ToHost().(*TupleKey6),
	}
}
737261
func (s *HostService) DedicateHost(p *DedicateHostParams) (*DedicateHostResponse, error) {
	resp, err := s.cs.newRequest("dedicateHost", p.toURLValues())
	if err != nil {
		return nil, err
	}

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

	// If we have a async client, we need to wait for the async result
	if s.cs.async {
		b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
		if err != nil {
			if err == AsyncTimeoutErr {
				return &r, err
			}
			return nil, err
		}

		b, err = getRawValue(b)
		if err != nil {
			return nil, err
		}

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

	return &r, nil
}
953465
func (s *ServeMux) MiddlewareHost(host, path string, middleware Middleware) {
	s.RouteHost(host, path).Middleware(middleware)
}
220727
func (c *Client) UpdateHost(p *UpdateHostParameter) (*Host, error) {
	obj, err := c.Request("updateHost", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*Host), err
}
621095
func (h *Host) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	suffix := httputil.PathSuffix(r)
	seg := strings.Split(suffix, "/")
	if suffix == "" || len(seg) == 0 {
		h.serveImportersRoot(w, r)
		return
	}
	impName := seg[0]

	imp, ok := h.imp[impName]
	if !ok {
		http.NotFound(w, r)
		return
	}

	if len(seg) == 1 || seg[1] == "" {
		h.serveImporter(w, r, imp)
		return
	}
	if seg[1] == "callback" {
		h.serveImporterAcctCallback(w, r, imp)
		return
	}
	acctRef, ok := blob.Parse(seg[1])
	if !ok {
		http.NotFound(w, r)
		return
	}
	h.serveImporterAccount(w, r, imp, acctRef)
}
102016
func (k *Service6Key) ToHost() ServiceKey {
	n := *k
	n.Port = byteorder.NetworkToHost(n.Port).(uint16)
	return &n
}
991383
func ProxyHost(proxyHost string) string {
	host, _, err := net.SplitHostPort(proxyHost)
	if err != nil {
		return proxyHost
	}
	return host
}
652414
func (c *Client) AddHost(p *AddHostParameter) (*Host, error) {
	obj, err := c.Request("addHost", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*Host), err
}
382078
func (c *Client) SetServerHost(host string, port int) {
	c.serverAddr = net.JoinHostPort(host, strconv.Itoa(port))
}
93007
func WithHost(host string) Opt {
	return func(c *Client) error {
		hostURL, err := ParseHostURL(host)
		if err != nil {
			return err
		}
		c.host = host
		c.proto = hostURL.Scheme
		c.addr = hostURL.Host
		c.basePath = hostURL.Path
		if transport, ok := c.client.Transport.(*http.Transport); ok {
			return sockets.ConfigureTransport(transport, c.proto, c.addr)
		}
		return errors.Errorf("cannot apply host to transport: %T", c.client.Transport)
	}
}
123111
func (cm *connectMethod) tlsHost() string {
	h := cm.targetAddr
	if hasPort(h) {
		h = h[:strings.LastIndex(h, ":")]
	}
	return h
}
170580
func (_class FeatureClass) GetHost(sessionID SessionRef, self FeatureRef) (_retval HostRef, _err error) {
	_method := "Feature.get_host"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_selfArg, _err := convertFeatureRefToXen(fmt.Sprintf("%s(%s)", _method, "self"), self)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg, _selfArg)
	if _err != nil {
		return
	}
	_retval, _err = convertHostRefToGo(_method + " -> ", _result.Value)
	return
}