func (a *Agent) reservePortsForClient(conf *clientconfig.Config) error {
	// finding the device name for loopback
	deviceName, addr, mask, err := a.findLoopbackDevice()
	if err != nil {
		return fmt.Errorf("error finding the device name for loopback: %v", err)
	}

	// seeing if the user has already reserved some resources on this device
	var nr *structs.NetworkResource
	if conf.Node.Reserved == nil {
		conf.Node.Reserved = &structs.Resources{}
	}
	for _, n := range conf.Node.Reserved.Networks {
		if n.Device == deviceName {
			nr = n
		}
	}
	// If the user hasn't already created the device, we create it
	if nr == nil {
		nr = &structs.NetworkResource{
			Device:        deviceName,
			IP:            addr,
			CIDR:          mask,
			ReservedPorts: make([]structs.Port, 0),
		}
	}
	// appending the port ranges we want to use for the client to the list of
	// reserved ports for this device
	for i := conf.ClientMinPort; i <= conf.ClientMaxPort; i++ {
		nr.ReservedPorts = append(nr.ReservedPorts, structs.Port{Label: fmt.Sprintf("plugin-%d", i), Value: int(i)})
	}
	conf.Node.Reserved.Networks = append(conf.Node.Reserved.Networks, nr)
	return nil
}
// reservePortsForClient reserves a range of ports for the client to use when
// it creates various plugins for log collection, executors, drivers, etc
reservePortsForClient reserves a range of ports for the client to use when
it creates various plugins for log collection, executors, drivers, etc
// reservePortsForClient reserves a range of ports for the client to use when // it creates various plugins for log collection executors drivers etc
func (a *Agent) reservePortsForClient(conf *clientconfig.Config) error {
	deviceName, addr, mask, err := a.findLoopbackDevice()
	if err != nil {
		return fmt.Errorf("error finding the device name for loopback: %v", err)
	}
	var nr *structs.NetworkResource
	if conf.Node.Reserved == nil {
		conf.Node.Reserved = &structs.Resources{}
	}
	for _, n := range conf.Node.Reserved.Networks {
		if n.Device == deviceName {
			nr = n
		}
	}
	if nr == nil {
		nr = &structs.NetworkResource{
			Device:        deviceName,
			IP:            addr,
			CIDR:          mask,
			ReservedPorts: make([]structs.Port, 0),
		}
	}
	for i := conf.ClientMinPort; i <= conf.ClientMaxPort; i++ {
		nr.ReservedPorts = append(nr.ReservedPorts, structs.Port{Label: fmt.Sprintf("plugin-%d", i), Value: int(i)})
	}
	conf.Node.Reserved.Networks = append(conf.Node.Reserved.Networks, nr)
	return nil
}
func ( a * Agent ) reservePortsForClient ( conf * clientconfig . Config ) error { deviceName , addr , mask , err := a . findLoopbackDevice ( ) if err != nil { return fmt . Errorf ( " " , err ) } var nr * structs . NetworkResource if conf . Node . Reserved == nil { conf . Node . Reserved = & structs . Resources { } } for _ , n := range conf . Node . Reserved . Networks { if n . Device == deviceName { nr = n } } if nr == nil { nr = & structs . NetworkResource { Device : deviceName , IP : addr , CIDR : mask , ReservedPorts : make ( [ ] structs . Port , 0 ) , } } for i := conf . ClientMinPort ; i <= conf . ClientMaxPort ; i ++ { nr . ReservedPorts = append ( nr . ReservedPorts , structs . Port { Label : fmt . Sprintf ( " " , i ) , Value : int ( i ) } ) } conf . Node . Reserved . Networks = append ( conf . Node . Reserved . Networks , nr ) return nil }
reservePortsForClient reserves a range of ports for the client to use when
it creates various plugins for log collection, executors, drivers, etc
reservePortsForClient reserves a range of ports for the client to use when it creates various plugins for log collection executors drivers etc
// finding the device name for loopback // seeing if the user has already reserved some resources on this device // If the user hasn't already created the device, we create it // appending the port ranges we want to use for the client to the list of // reserved ports for this device