Example #1
0
func processNetEvent(netPlugin *plugin.NetPlugin, netID string,
	isDelete bool) (err error) {
	// take a lock to ensure we are programming one event at a time.
	// Also network create events need to be processed before endpoint creates
	// and reverse shall happen for deletes. That order is ensured by netmaster,
	// so we don't need to worry about that here
	netPlugin.Lock()
	defer func() { netPlugin.Unlock() }()

	operStr := ""
	if isDelete {
		err = netPlugin.DeleteNetwork(netID)
		operStr = "delete"
	} else {
		err = netPlugin.CreateNetwork(netID)
		operStr = "create"
	}
	if err != nil {
		log.Errorf("Network operation %s failed. Error: %s", operStr, err)
	} else {
		log.Infof("Network operation %s succeeded", operStr)
	}

	return
}
Example #2
0
func processPeerEvent(netPlugin *plugin.NetPlugin, opts cliOpts, peerID string, isDelete bool) (err error) {
	// if this is our own peer info coming back to us, ignore it
	if peerID == opts.hostLabel {
		return nil
	}

	// take a lock to ensure we are programming one event at a time.
	netPlugin.Lock()
	defer func() { netPlugin.Unlock() }()

	operStr := ""
	if isDelete {
		err = netPlugin.DeletePeerHost(peerID)
		operStr = "delete"
	} else {
		err = netPlugin.CreatePeerHost(peerID)
		operStr = "create"
	}
	if err != nil {
		log.Errorf("PeerHost operation %s failed. Error: %s", operStr, err)
	} else {
		log.Infof("PeerHost operation %s succeeded", operStr)
	}

	return
}
Example #3
0
func processPeerEvent(netPlugin *plugin.NetPlugin, opts cliOpts,
	peerInfo *drivers.PeerHostState, isDelete bool) (err error) {

	// if this is our own peer info coming back to us, ignore it
	if peerInfo.ID == opts.hostLabel {
		return nil
	}

	nodeInfo := core.ServiceInfo{
		HostAddr: peerInfo.HostAddr,
		Port:     0,
	}

	// take a lock to ensure we are programming one event at a time.
	netPlugin.Lock()
	defer func() { netPlugin.Unlock() }()

	operStr := ""
	if isDelete {
		err = netPlugin.DeletePeerHost(nodeInfo)
		operStr = "delete"
	} else {
		err = netPlugin.AddPeerHost(nodeInfo)
		operStr = "create"
	}
	if err != nil {
		log.Errorf("PeerHost operation %s failed. Error: %s", operStr, err)
	} else {
		log.Infof("PeerHost operation %s succeeded", operStr)
	}

	return
}
Example #4
0
func processEpEvent(netPlugin *plugin.NetPlugin, crt *crt.CRT, opts cliOpts,
	epID string, isDelete bool) (err error) {
	// take a lock to ensure we are programming one event at a time.
	// Also network create events need to be processed before endpoint creates
	// and reverse shall happen for deletes. That order is ensured by netmaster,
	// so we don't need to worry about that here
	netPlugin.Lock()
	defer func() { netPlugin.Unlock() }()

	homingHost := ""
	vtepIP := ""

	if !isDelete {
		epCfg := &drivers.OvsCfgEndpointState{}
		epCfg.StateDriver = netPlugin.StateDriver
		err = epCfg.Read(epID)
		if err != nil {
			log.Errorf("Failed to read config for ep '%s' \n", epID)
			return
		}
		homingHost = epCfg.HomingHost
		vtepIP = epCfg.VtepIP
	} else {
		epOper := &drivers.OvsOperEndpointState{}
		epOper.StateDriver = netPlugin.StateDriver
		err = epOper.Read(epID)
		if err != nil {
			log.Errorf("Failed to read oper for ep %s, err '%s' \n", epID, err)
			return
		}
		homingHost = epOper.HomingHost
		vtepIP = epOper.VtepIP
	}
	if skipHost(vtepIP, homingHost, opts.hostLabel) {
		log.Infof("skipping mismatching host for ep %s. EP's host %s (my host: %s)",
			epID, homingHost, opts.hostLabel)
		return
	}

	// read the context before to be compared with what changed after
	contEpContext, err := getEndpointContainerContext(
		netPlugin.StateDriver, epID)
	if err != nil {
		log.Errorf("Failed to obtain the container context for ep '%s' \n",
			epID)
		return
	}

	log.Debugf("read endpoint context: %s \n", contEpContext)

	operStr := ""
	if isDelete {
		err = netPlugin.DeleteEndpoint(epID)
		operStr = "delete"
	} else {
		err = netPlugin.CreateEndpoint(epID)
		operStr = "create"
	}
	if err != nil {
		log.Errorf("Endpoint operation %s failed. Error: %s",
			operStr, err)
		return
	}

	log.Infof("Endpoint operation %s succeeded", operStr)

	// attach or detach an endpoint to a container
	if isDelete || contAttachPointDeleted(contEpContext) {
		err = crt.ContainerIf.DetachEndpoint(contEpContext)
		if err != nil {
			log.Errorf("Endpoint detach container '%s' from ep '%s' failed . "+
				"Error: %s", contEpContext.CurrContName, epID, err)
		} else {
			log.Infof("Endpoint detach container '%s' from ep '%s' succeeded",
				contEpContext.CurrContName, epID)
		}
	}
	if !isDelete && contAttachPointAdded(contEpContext) {
		// re-read post ep updated state
		newContEpContext, err1 := getEndpointContainerContext(
			netPlugin.StateDriver, epID)
		if err1 != nil {
			log.Errorf("Failed to obtain the container context for ep '%s' \n", epID)
			return
		}
		contEpContext.InterfaceID = newContEpContext.InterfaceID
		contEpContext.IPAddress = newContEpContext.IPAddress
		contEpContext.SubnetLen = newContEpContext.SubnetLen

		err = crt.ContainerIf.AttachEndpoint(contEpContext)
		if err != nil {
			log.Errorf("Endpoint attach container '%s' to ep '%s' failed . "+
				"Error: %s", contEpContext.NewContName, epID, err)
		} else {
			log.Infof("Endpoint attach container '%s' to ep '%s' succeeded",
				contEpContext.NewContName, epID)
		}
		contID := crt.ContainerIf.GetContainerID(contEpContext.NewContName)
		if contID != "" {
		}
	}

	return
}