// AddHost creates the host if it doesn't already exist. (uses a pool-based
// connection)
426502
func AddHost(conn client.Connection, h host.Host) error {
	pth := path.Join("/hosts", h.ID)

	logger := plog.WithFields(log.Fields{
		"poolid": h.PoolID,
		"hostid": h.ID,
		"zkpath": pth,
	})

	// create the /hosts path if it doesn't exist
	if err := conn.CreateIfExists("/hosts", &client.Dir{}); err != nil && err != client.ErrNodeExists {
		logger.WithError(err).Debug("Could not initialize hosts path in zookeeper")
		return err
	}

	if err := conn.CreateIfExists(pth, &HostNode{Host: &h}); err != nil {
		logger.WithError(err).Debug("Could not create host entry in zookeeper")
		return err
	}

	logger.Debug("Created entry for host in zookeeper")
	return nil
}
1021456
func lookupHost(hostname string) (string, error) {
	addrs, err := net.LookupHost(hostname)

	if err != nil {
		return "", err
	}
	return addrs[0], nil
}
141062
func (s *HostService) AddHost(p *AddHostParams) (*AddHostResponse, error) {
	resp, err := s.cs.newRequest("addHost", p.toURLValues())
	if err != nil {
		return nil, err
	}

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

	return &r, nil
}
506409
func (self *ConnectionString) Host(defaults ...string) string {
	if host := self.URI.Host; host != `` {
		return host
	} else if len(defaults) > 0 {
		return defaults[0]
	} else {
		return ``
	}
}
512366
func removeHost(conn client.Connection, poolID, hostID string) error {
	basepth := ""
	if poolID != "" {
		basepth = path.Join("/pools", poolID)
	}
	pth := path.Join(basepth, "/hosts", hostID)

	t := conn.NewTransaction()
	if err := rmr(conn, t, pth); err != nil {
		return err
	}
	if err := t.Commit(); err != nil {
		return err
	}
	return nil
}
1018516
func (s *LoadBalancerSetting) AddServer(server *LoadBalancerServer) {
	if s.Servers == nil {
		s.Servers = []*LoadBalancerServer{}
	}
	s.Servers = append(s.Servers, server)
}
1245955
func (c *Cluster) CreateNewHost(serial string) (*Host, error) {
	serial = strings.ToLower(serial)
	hostDir := path.Join(c.baseDir, strings.ToLower(serial))
	newHost, err := createHost(serial, hostDir)
	if err != nil {
		return nil, microerror.Mask(err)
	}

	if predef, exists := c.predefinedVals[serial]; exists {
		c.logger.Log("level", "info", "message", fmt.Sprintf("found predefined values for '%s'", serial))

		if s, exists := predef["ipmiaddr"]; exists {
			newHost.IPMIAddr = net.ParseIP(s)
			c.logger.Log("level", "info", "message", fmt.Sprintf("setting IPMIAdddress for '%s': %s", serial, newHost.IPMIAddr.String()))

		}
		if s, exists := predef["internaladdr"]; exists {
			newHost.InternalAddr = net.ParseIP(s)
			c.logger.Log("level", "info", "message", fmt.Sprintf("setting internal address for '%s': %s", serial, newHost.InternalAddr.String()))

			newHost.Hostname = strings.Replace(newHost.InternalAddr.String(), ".", "-", 4)
		}
		if s, exists := predef["etcdclustertoken"]; exists {
			newHost.EtcdClusterToken = s
		}
	} else {
		c.logger.Log("level", "info", "message", fmt.Sprintf("no predefined values for '%s'", serial))
	}

	machineID := genMachineID()
	newHost.MachineID = machineID
	if newHost.InternalAddr != nil {
		newHost.Hostname = strings.Replace(newHost.InternalAddr.String(), ".", "-", 4)
	}
	c.logger.Log("level", "info", "message", fmt.Sprintf("hostname for  '%s' is %s", newHost.InternalAddr.String(), newHost.Hostname))
	newHost.Commit("updated with predefined settings")

	err = c.reindex()
	if err != nil {
		return nil, microerror.Mask(err)
	}
	return newHost, nil
}
400714
func addHost(alias string, hostCfgV9 hostConfigV9) {
	mcCfgV9, err := loadMcConfig()
	fatalIf(err.Trace(globalMCConfigVersion), "Unable to load config `"+mustGetMcConfigPath()+"`.")

	// Add new host.
	mcCfgV9.Hosts[alias] = hostCfgV9

	err = saveMcConfig(mcCfgV9)
	fatalIf(err.Trace(alias), "Unable to update hosts in config version `"+mustGetMcConfigPath()+"`.")

	printMsg(hostMessage{
		op:        "add",
		Alias:     alias,
		URL:       hostCfgV9.URL,
		AccessKey: hostCfgV9.AccessKey,
		SecretKey: hostCfgV9.SecretKey,
		API:       hostCfgV9.API,
		Lookup:    hostCfgV9.Lookup,
	})
}
1251041
func (s *ServerConfig) AddHostKey(key Signer) {
	for i, k := range s.hostKeys {
		if k.PublicKey().Type() == key.PublicKey().Type() {
			s.hostKeys[i] = key
			return
		}
	}

	s.hostKeys = append(s.hostKeys, key)
}
1174208
func (b *BackendConfig) addHeadersAndHost(req *http.Request) *http.Request {
	if b.Options.Hostname != "" {
		req.Host = b.Options.Hostname
	}

	for k, v := range b.Options.Headers {
		req.Header.Set(k, v)
	}
	return req
}
585683
func AddHostsEntry(filename string, ip string, hostname string) error {
	fp, err := os.OpenFile(filename, os.O_RDWR, 0644)
	if err != nil {
		return err
	}
	defer fp.Close()

	out := ""
	found := false

	scanner := bufio.NewScanner(fp)
	for scanner.Scan() {
		line := scanner.Text()
		words := strings.Fields(line)
		if !found && len(words) > 0 && words[0] == ip {
			found = true
			out += fmt.Sprintf("%s %s\n", line, hostname)
		} else {
			out += line
			out += "\n"
		}
	}
	if err := scanner.Err(); err != nil {
		return err
	}

	// If that IP was not found, add a new line
	if !found {
		out += fmt.Sprintf("%s\t%s\n", ip, hostname)
	}

	// Seek to the beginning, truncate, and write again
	if _, err := fp.Seek(0, 0); err != nil {
		return err
	}
	if err := fp.Truncate(0); err != nil {
		return err
	}
	if _, err := fp.Write([]byte(out)); err != nil {
		return err
	}

	return nil
}
584459
func Host(host string) ConnectOption {
	return func(c *httpclient.HttpClient) {
		c.Host = host
	}
}
1058269
func (ri *ReindexRemoteInfo) Host(host string) *ReindexRemoteInfo {
	ri.host = host
	return ri
}
753972
func (c *Client) UpdateHost(host host.Host) error {
	return c.call("UpdateHost", host, nil)
}
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)
	}
}
595668
func (nd *Node) addAlias(aliasToAdd *Host) {
	// Aliases are only referenced in the cluster tend goroutine,
	// so synchronization is not necessary.
	aliases := nd.GetAliases()
	if aliases == nil {
		aliases = []*Host{}
	}

	aliases = append(aliases, aliasToAdd)
	nd.setAliases(aliases)
}
504879
func (s *ProxyLBSetting) AddServer(ip string, port int, enabled bool) {
	var record ProxyLBServer
	var isExist = false
	for i := range s.Servers {
		if s.Servers[i].IPAddress == ip && s.Servers[i].Port == port {
			isExist = true
			s.Servers[i].Enabled = enabled
		}
	}

	if !isExist {
		record = ProxyLBServer{
			IPAddress: ip,
			Port:      port,
			Enabled:   enabled,
		}
		s.Servers = append(s.Servers, record)
	}
}