本文整理匯總了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
}