本文整理汇总了Golang中github.com/contiv/netplugin/plugin.NetPlugin.DeleteEndpoint方法的典型用法代码示例。如果您正苦于以下问题:Golang NetPlugin.DeleteEndpoint方法的具体用法?Golang NetPlugin.DeleteEndpoint怎么用?Golang NetPlugin.DeleteEndpoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/contiv/netplugin/plugin.NetPlugin
的用法示例。
在下文中一共展示了NetPlugin.DeleteEndpoint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleContainerStop
func handleContainerStop(netPlugin *plugin.NetPlugin, crt *crt.CRT, opts *cliOpts,
contID string) error {
// If CONTIV_DIND_HOST_GOPATH env variable is set we can assume we are in docker in docker testbed
// Here we need to set the network namespace of the ports created by netplugin back to NS of the docker host
hostGoPath := os.Getenv("CONTIV_DIND_HOST_GOPATH")
if hostGoPath != "" {
osCmd := exec.Command("github.com/contiv/netplugin/scripts/dockerhost/setlocalns.sh")
osCmd.Dir = os.Getenv("GOSRC")
output, err := osCmd.Output()
if err != nil {
log.Errorf("setlocalns failed. Error: %s Output: \n%s\n",
err, output)
return err
}
return err
}
if opts.forceDeleteEp {
log.Infof("deleting operEp for container with uuid %s \n", contID)
epIDs, err := getEpIDByContainerUUID(netPlugin, contID)
if err != nil {
log.Errorf("error obtaining container's epid for uuid %s: %v \n", contID, err)
return err
}
for _, epID := range epIDs {
err = netPlugin.DeleteEndpoint(epID)
if err != nil {
log.Errorf("error deleting an endpoint upon container stop: %v \n", err)
return err
}
}
}
return nil
}
示例2: processEpEvent
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 != "" {
}
//.........这里部分代码省略.........