本文整理汇总了Golang中github.com/contiv/netplugin/netplugin/plugin.NetPlugin.CreateEndpoint方法的典型用法代码示例。如果您正苦于以下问题:Golang NetPlugin.CreateEndpoint方法的具体用法?Golang NetPlugin.CreateEndpoint怎么用?Golang NetPlugin.CreateEndpoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/contiv/netplugin/netplugin/plugin.NetPlugin
的用法示例。
在下文中一共展示了NetPlugin.CreateEndpoint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: processEpState
// processEpState restores endpoint state
func processEpState(netPlugin *plugin.NetPlugin, opts cliOpts, epID string) 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() }()
// read endpoint config
epCfg := &mastercfg.CfgEndpointState{}
epCfg.StateDriver = netPlugin.StateDriver
err := epCfg.Read(epID)
if err != nil {
log.Errorf("Failed to read config for ep '%s' \n", epID)
return err
}
// if the endpoint is not for this host, ignore it
if skipHost(epCfg.VtepIP, epCfg.HomingHost, opts.hostLabel) {
log.Infof("skipping mismatching host for ep %s. EP's host %s (my host: %s)",
epID, epCfg.HomingHost, opts.hostLabel)
return nil
}
// Create the endpoint
err = netPlugin.CreateEndpoint(epID)
if err != nil {
log.Errorf("Endpoint operation create failed. Error: %s", err)
return err
}
log.Infof("Endpoint operation create succeeded")
return err
}
示例2: processInfraNwCreate
// Process Infra Nw Create
// Auto allocate an endpoint for this node
func processInfraNwCreate(netPlugin *plugin.NetPlugin, nwCfg *mastercfg.CfgNetworkState, opts cliOpts) (err error) {
pluginHost := opts.hostLabel
// Build endpoint request
mreq := master.CreateEndpointRequest{
TenantName: nwCfg.Tenant,
NetworkName: nwCfg.NetworkName,
EndpointID: pluginHost,
ConfigEP: intent.ConfigEP{
Container: pluginHost,
Host: pluginHost,
},
}
var mresp master.CreateEndpointResponse
err = cluster.MasterPostReq("/plugin/createEndpoint", &mreq, &mresp)
if err != nil {
log.Errorf("master failed to create endpoint %s", err)
return err
}
log.Infof("Got endpoint create resp from master: %+v", mresp)
// Take lock to ensure netPlugin processes only one cmd at a time
netPlugin.Lock()
defer func() { netPlugin.Unlock() }()
// Ask netplugin to create the endpoint
netID := nwCfg.NetworkName + "." + nwCfg.Tenant
err = netPlugin.CreateEndpoint(netID + "-" + pluginHost)
if err != nil {
log.Errorf("Endpoint creation failed. Error: %s", err)
return err
}
// Assign IP to interface
ipCIDR := fmt.Sprintf("%s/%d", mresp.EndpointConfig.IPAddress, nwCfg.SubnetLen)
err = netutils.SetInterfaceIP(nwCfg.NetworkName, ipCIDR)
if err != nil {
log.Errorf("Could not assign ip: %s", err)
return err
}
return nil
}