// OptionExtraHost function returns an option setter for extra /etc/hosts options
// which is a name and IP as strings.
17375
func OptionExtraHost(name string, IP string) SandboxOption {
	return func(sb *sandbox) {
		sb.config.extraHosts = append(sb.config.extraHosts, extraHost{name: name, IP: IP})
	}
}
1088153
func SplitHostPort(hostname string) (string, string, error) {
	host, port, err := net.SplitHostPort(hostname)
	if err != nil {
		return "", "", trace.Wrap(err)
	}
	if host == "" {
		return "", "", trace.BadParameter("empty hostname")
	}
	return host, port, nil
}
844561
func ExtractExtraURLParams(opts ...interface{}) *opt.ExtraURLParamsOption {
	merged := make(map[string]string)

	for _, o := range opts {
		if v, ok := o.(*opt.ExtraURLParamsOption); ok {
			for key, value := range v.Get() {
				merged[key] = value
			}
		}
	}

	if len(merged) == 0 {
		return nil
	}

	return opt.ExtraURLParams(merged)
}
1132136
func (c *Client) RemoveHost(hostID string) error {
	return c.call("RemoveHost", hostID, nil)
}
396614
func (f *Facade) RemoveHost(ctx datastore.Context, hostID string) (err error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.RemoveHost"))
	alog := f.auditLogger.Message(ctx, "Removing Host").Action(audit.Remove).ID(hostID).Type(host.GetType())
	glog.V(2).Infof("Facade.RemoveHost: %s", hostID)
	if err := f.DFSLock(ctx).LockWithTimeout("remove host", userLockTimeout); err != nil {
		glog.Warningf("Cannot remove host: %s", err)
		return alog.Error(err)
	}
	defer f.DFSLock(ctx).Unlock()

	//assert valid host
	var _host *host.Host
	if _host, err = f.GetHost(ctx, hostID); err != nil {
		return alog.Error(err)
	} else if _host == nil {
		return alog.Error(fmt.Errorf("HostID %s does not exist", hostID))
	}

	ec := newEventCtx()
	defer f.afterEvent(afterHostDelete, ec, hostID, err)
	if err = f.beforeEvent(beforeHostDelete, ec, hostID); err != nil {
		return alog.Error(err)
	}

	//remove host from zookeeper
	if err = f.zzk.RemoveHost(_host); err != nil {
		return alog.Error(err)
	}

	// remove host from hostkey datastore
	if err = f.hostkeyStore.Delete(ctx, _host.ID); err != nil {
		return alog.Error(err)
	}

	//remove host from datastore
	if err = f.hostStore.Delete(ctx, host.HostKey(hostID)); err != nil {
		return alog.Error(err)
	}

	//grab all services that are address assigned the host's IPs
	var services []service.Service
	for _, ip := range _host.IPs {
		query := []string{fmt.Sprintf("Endpoints.AddressAssignment.IPAddr:%s", ip.IPAddress)}
		svcs, err := f.GetTaggedServices(ctx, query)
		if err != nil {
			glog.Errorf("Failed to grab services with endpoints assigned to ip %s on host %s: %s", ip.IPAddress, _host.Name, err)
			return alog.Error(err)
		}
		services = append(services, svcs...)
	}

	// update address assignments
	for _, svc := range services {
		request := addressassignment.AssignmentRequest{
			ServiceID:      svc.ID,
			IPAddress:      "",
			AutoAssignment: true,
		}
		if err = f.AssignIPs(ctx, request); err != nil {
			glog.Warningf("Failed assigning another ip to service %s: %s", svc.ID, err)
		}
	}

	// unregister host as dfs client
	err = f.zzk.UnregisterDfsClients(*_host)
	if err != nil {
		glog.Warningf("Could not disable dfs for deleted host %s: %s", _host.ID, err)
	}

	f.poolCache.SetDirty()

	alog.Succeeded()
	return nil
}
415391
func toBuildkitExtraHosts(inp []string) (string, error) {
	if len(inp) == 0 {
		return "", nil
	}
	hosts := make([]string, 0, len(inp))
	for _, h := range inp {
		parts := strings.Split(h, ":")

		if len(parts) != 2 || parts[0] == "" || net.ParseIP(parts[1]) == nil {
			return "", errors.Errorf("invalid host %s", h)
		}
		hosts = append(hosts, parts[0]+"="+parts[1])
	}
	return strings.Join(hosts, ","), nil
}
954019
func OptionHostsPath(path string) SandboxOption {
	return func(sb *sandbox) {
		sb.config.hostsPath = path
	}
}
320360
func WithExtraFlags(f func(flags *FlagSet)) Option {
	return func(o *options) {
		f(o.flagSet)
	}
}
1046317
func (c *Client) CancelHostMaintenance(p *CancelHostMaintenanceParameter) (*Host, error) {
	obj, err := c.Request("cancelHostMaintenance", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*Host), err
}
1298523
func OptionHostname(name string) SandboxOption {
	return func(sb *sandbox) {
		sb.config.hostName = name
	}
}
1110506
func parseHost(host string) (string, error) {
	if strings.HasPrefix(host, "[") {
		// Parse an IP-Literal in RFC 3986 and RFC 6874.
		// E.g., "[fe80::1]", "[fe80::1%25en0]", "[fe80::1]:80".
		i := strings.LastIndex(host, "]")
		if i < 0 {
			return "", errors.New("missing ']' in host")
		}
		colonPort := host[i+1:]
		if !validOptionalPort(colonPort) {
			return "", fmt.Errorf("invalid port %q after host", colonPort)
		}

		// RFC 6874 defines that %25 (%-encoded percent) introduces
		// the zone identifier, and the zone identifier can use basically
		// any %-encoding it likes. That's different from the host, which
		// can only %-encode non-ASCII bytes.
		// We do impose some restrictions on the zone, to avoid stupidity
		// like newlines.
		zone := strings.Index(host[:i], "%25")
		if zone >= 0 {
			host1, err := unescape(host[:zone], encodeHost)
			if err != nil {
				return "", err
			}
			host2, err := unescape(host[zone:i], encodeZone)
			if err != nil {
				return "", err
			}
			host3, err := unescape(host[i:], encodeHost)
			if err != nil {
				return "", err
			}
			return host1 + host2 + host3, nil
		}
	}

	var err error
	if host, err = unescape(host, encodeHost); err != nil {
		return "", err
	}
	return host, nil
}
33792
func convertExtraHosts(extraHosts composetypes.HostsList) []string {
	hosts := []string{}
	for _, hostIP := range extraHosts {
		if v := strings.SplitN(hostIP, ":", 2); len(v) == 2 {
			// Convert to SwarmKit notation: IP-address hostname(s)
			hosts = append(hosts, fmt.Sprintf("%s %s", v[1], v[0]))
		}
	}
	return hosts
}
515739
func ExcludeHosts(endpoints ...string) ExclusionFilter {
	m := make(map[string]struct{})
	for _, endpoint := range endpoints {
		m[endpoint] = struct{}{}
	}
	return ExcludeByHost(func(host string) bool {
		_, excluded := m[host]
		return excluded
	})
}
1206845
func (o *Options) processHostnameOverrideFlag() error {
	// Check if hostname-override flag is set and use value since configFile always overrides
	if len(o.hostnameOverride) > 0 {
		hostName := strings.TrimSpace(o.hostnameOverride)
		if len(hostName) == 0 {
			return fmt.Errorf("empty hostname-override is invalid")
		}
		o.config.HostnameOverride = strings.ToLower(hostName)
	}

	return nil
}
1171529
func (s *HostService) GetHostTagID(keyword string, opts ...OptionFunc) (string, int, error) {
	p := &ListHostTagsParams{}
	p.p = make(map[string]interface{})

	p.p["keyword"] = keyword

	for _, fn := range append(s.cs.options, opts...) {
		if err := fn(s.cs, p); err != nil {
			return "", -1, err
		}
	}

	l, err := s.ListHostTags(p)
	if err != nil {
		return "", -1, err
	}

	if l.Count == 0 {
		return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l)
	}

	if l.Count == 1 {
		return l.HostTags[0].Id, l.Count, nil
	}

	if l.Count > 1 {
		for _, v := range l.HostTags {
			if v.Name == keyword {
				return v.Id, l.Count, nil
			}
		}
	}
	return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l)
}
563689
func (_m *FacadeInterface) RemoveHostExpiration(ctx datastore.Context, hostID string) {
	_m.Called(ctx, hostID)
}
832322
func extractHost(header string) (host string) {
	host, _, err := net.SplitHostPort(header)
	if err != nil {
		host = header
	}
	return host
}