Esempio n. 1
0
func (v *Validator) getEndpoint(ctx context.Context, conf *config.VirtualContainerHostConfigSpec, network data.NetworkConfig, epName, contNetName string, def bool, ns []net.IP) (*executor.NetworkEndpoint, error) {
	defer trace.End(trace.Begin(""))
	var gw net.IPNet
	var staticIP *net.IPNet

	if !network.Empty() {
		log.Debugf("Setting static IP for %q on port group %q", contNetName, network.Name)
		gw = network.Gateway
		staticIP = &network.IP
	}

	moid, err := v.networkHelper(ctx, network.Name)
	if err != nil {
		return nil, err
	}

	e := &executor.NetworkEndpoint{
		Common: executor.Common{
			Name: epName,
		},
		Network: executor.ContainerNetwork{
			Common: executor.Common{
				Name: contNetName,
				ID:   moid,
			},
			Default:     def,
			Gateway:     gw,
			Nameservers: ns,
		},
		IP: staticIP,
	}
	if staticIP != nil {
		e.Static = true
	}
	log.Debugf("NetworkEndpoint: %v", e)

	return e, nil
}