Ejemplo n.º 1
0
func (ctx *VmContext) ConfigureInterface(index int, pciAddr int, name string, config pod.UserInterface) {
	var err error
	var inf *network.Settings
	var maps []pod.UserContainerPort

	if index == 0 {
		for _, c := range ctx.userSpec.Containers {
			for _, m := range c.Ports {
				maps = append(maps, m)
			}
		}
	}

	if HDriver.BuildinNetwork() {
		/* VBox doesn't support join to bridge */
		inf, err = ctx.DCtx.ConfigureNetwork(ctx.Id, "", maps, config)
	} else {
		inf, err = network.Configure(ctx.Id, "", false, maps, config)
	}

	if err != nil {
		glog.Error("interface creating failed: ", err.Error())
		session := &InterfaceCreated{Index: index, PCIAddr: pciAddr, DeviceName: name}
		ctx.Hub <- &DeviceFailed{Session: session}
		return
	}

	session, err := interfaceGot(index, pciAddr, name, inf)
	if err != nil {
		ctx.Hub <- &DeviceFailed{Session: session}
		return
	}

	ctx.Hub <- session
}
Ejemplo n.º 2
0
func (nc *NetworkContext) configureInterface(index, pciAddr int, name string, inf *api.InterfaceDescription, result chan<- VmEvent) {
	var (
		err      error
		settings *network.Settings
	)

	if HDriver.BuildinNetwork() {
		/* VBox doesn't support join to bridge */
		settings, err = nc.sandbox.DCtx.ConfigureNetwork(nc.sandbox.Id, "", inf)
	} else {
		settings, err = network.Configure(nc.sandbox.Id, "", false, inf)
	}

	if err != nil {
		nc.sandbox.Log(ERROR, "interface creating failed: %v", err.Error())
		session := &InterfaceCreated{Id: inf.Id, Index: index, PCIAddr: pciAddr, DeviceName: name}
		result <- &DeviceFailed{Session: session}
		return
	}

	created, err := interfaceGot(inf.Id, index, pciAddr, name, settings)
	if err != nil {
		result <- &DeviceFailed{Session: created}
		return
	}

	h := &HostNicInfo{
		Id:      created.Id,
		Fd:      uint64(created.Fd.Fd()),
		Device:  created.HostDevice,
		Mac:     created.MacAddr,
		Bridge:  created.Bridge,
		Gateway: created.Bridge,
	}
	g := &GuestNicInfo{
		Device:  created.DeviceName,
		Ipaddr:  created.IpAddr,
		Index:   created.Index,
		Busaddr: created.PCIAddr,
	}

	nc.eth[index] = created
	nc.idMap[created.Id] = created
	nc.sandbox.DCtx.AddNic(nc.sandbox, h, g, result)
}
Ejemplo n.º 3
0
func (lc *LibvirtContext) ConfigureNetwork(vmId, requestedIP string,
	maps []pod.UserContainerPort, config pod.UserInterface) (*network.Settings, error) {
	return network.Configure(vmId, requestedIP, true, maps, config)
}
Ejemplo n.º 4
0
func (lc *LibvirtContext) ConfigureNetwork(vmId, requestedIP string, config *api.InterfaceDescription) (*network.Settings, error) {
	return network.Configure(vmId, requestedIP, true, config)
}