本文整理汇总了Golang中github.com/contiv/netplugin/netmaster/mastercfg.CfgEndpointState类的典型用法代码示例。如果您正苦于以下问题:Golang CfgEndpointState类的具体用法?Golang CfgEndpointState怎么用?Golang CfgEndpointState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CfgEndpointState类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: allocSetEpAddress
func allocSetEpAddress(ep *intent.ConfigEP, epCfg *mastercfg.CfgEndpointState,
nwCfg *mastercfg.CfgNetworkState) (err error) {
ipAddress, err := networkAllocAddress(nwCfg, ep.IPAddress, false)
if err != nil {
log.Errorf("Error allocating IP address. Err: %v", err)
return
}
epCfg.IPAddress = ipAddress
// Set mac address which is derived from IP address
ipAddr := net.ParseIP(ipAddress)
macAddr := fmt.Sprintf("02:02:%02x:%02x:%02x:%02x", ipAddr[12], ipAddr[13], ipAddr[14], ipAddr[15])
epCfg.MacAddress = macAddr
if nwCfg.IPv6Subnet != "" {
var ipv6Address string
ipv6Address, err = networkAllocAddress(nwCfg, ep.IPv6Address, true)
if err != nil {
log.Errorf("Error allocating IP address. Err: %v", err)
return
}
epCfg.IPv6Address = ipv6Address
}
return
}
示例2: handleEndpointEvents
func handleEndpointEvents(netPlugin *plugin.NetPlugin, crt *crt.CRT,
opts cliOpts, retErr chan error) {
rsps := make(chan core.WatchState)
go processStateEvent(netPlugin, crt, opts, rsps)
cfg := mastercfg.CfgEndpointState{}
cfg.StateDriver = netPlugin.StateDriver
retErr <- cfg.WatchAll(rsps)
return
}
示例3: TestOvsDriverCreateEndpointStatefulStateMismatch
func TestOvsDriverCreateEndpointStatefulStateMismatch(t *testing.T) {
driver := initOvsDriver(t)
defer func() { driver.Deinit() }()
id := createEpIDStatefulMismatch
// create network
err := driver.CreateNetwork(testOvsNwID)
if err != nil {
t.Fatalf("network creation failed. Error: %s", err)
}
defer func() { driver.DeleteNetwork(testOvsNwID, "", "", testPktTag, testExtPktTag, testGateway, testTenant) }()
// create second network
err = driver.CreateNetwork(testOvsNwIDStateful)
if err != nil {
t.Fatalf("network creation failed. Error: %s", err)
}
defer func() {
driver.DeleteNetwork(testOvsNwIDStateful, "", "", testPktTagStateful, testExtPktTag, testGateway, testTenant)
}()
// create endpoint
err = driver.CreateEndpoint(id)
if err != nil {
t.Fatalf("endpoint creation failed. Error: %s", err)
}
cfgEp := mastercfg.CfgEndpointState{}
cfgEp.StateDriver = driver.oper.StateDriver
err = cfgEp.Read(id)
if err != nil {
t.Fatalf("failed to read ep config. Error: %s", err)
}
cfgEp.NetID = testOvsNwIDStateful
err = cfgEp.Write()
if err != nil {
t.Fatalf("failed to write ep config. Error: %s", err)
}
err = driver.CreateEndpoint(id)
if err != nil {
t.Fatalf("stateful endpoint creation failed. Error: %s", err)
}
defer func() { driver.DeleteEndpoint(id) }()
output, err := exec.Command("ovs-vsctl", "list", "Port").CombinedOutput()
expectedPortName := fmt.Sprintf("port%d", driver.oper.CurrPortNum)
if err != nil || !strings.Contains(string(output), expectedPortName) {
t.Fatalf("port lookup failed. Error: %s expected port: %s Output: %s",
err, expectedPortName, output)
}
output, err = exec.Command("ovs-vsctl", "list", "Interface").CombinedOutput()
if err != nil || !strings.Contains(string(output), expectedPortName) {
t.Fatalf("interface lookup failed. Error: %s expected port: %s Output: %s",
err, expectedPortName, output)
}
}
示例4: RestoreServiceProviderLBDb
//RestoreServiceProviderLBDb restores provider and servicelb db
func RestoreServiceProviderLBDb() {
log.Infof("Restoring ProviderDb and ServiceDB cache")
svcLBState := &mastercfg.CfgServiceLBState{}
stateDriver, err := utils.GetStateDriver()
if err != nil {
log.Errorf("Error Restoring Service and ProviderDb Err:%s", err)
return
}
svcLBState.StateDriver = stateDriver
svcLBCfgs, err := svcLBState.ReadAll()
if err == nil {
mastercfg.SvcMutex.Lock()
for _, svcLBCfg := range svcLBCfgs {
svcLB := svcLBCfg.(*mastercfg.CfgServiceLBState)
//mastercfg.ServiceLBDb = make(map[string]*mastercfg.ServiceLBInfo)
serviceID := GetServiceID(svcLB.ServiceName, svcLB.Tenant)
mastercfg.ServiceLBDb[serviceID] = &mastercfg.ServiceLBInfo{
IPAddress: svcLB.IPAddress,
Tenant: svcLB.Tenant,
ServiceName: svcLB.ServiceName,
Network: svcLB.Network,
}
mastercfg.ServiceLBDb[serviceID].Ports = append(mastercfg.ServiceLBDb[serviceID].Ports, svcLB.Ports...)
mastercfg.ServiceLBDb[serviceID].Selectors = make(map[string]string)
mastercfg.ServiceLBDb[serviceID].Providers = make(map[string]*mastercfg.Provider)
for k, v := range svcLB.Selectors {
mastercfg.ServiceLBDb[serviceID].Selectors[k] = v
}
for providerID, providerInfo := range svcLB.Providers {
mastercfg.ServiceLBDb[serviceID].Providers[providerID] = providerInfo
providerDBId := providerInfo.ContainerID
mastercfg.ProviderDb[providerDBId] = providerInfo
}
}
mastercfg.SvcMutex.Unlock()
}
//Recover from endpoint state as well .
epCfgState := mastercfg.CfgEndpointState{}
epCfgState.StateDriver = stateDriver
epCfgs, err := epCfgState.ReadAll()
if err == nil {
for _, epCfg := range epCfgs {
ep := epCfg.(*mastercfg.CfgEndpointState)
providerDBId := ep.ContainerID
if ep.Labels != nil && mastercfg.ProviderDb[providerDBId] == nil {
//Create provider info and store it in provider db
providerInfo := &mastercfg.Provider{}
providerInfo.ContainerID = ep.ContainerID
providerInfo.Network = strings.Split(ep.NetID, ".")[0]
providerInfo.Tenant = strings.Split(ep.NetID, ".")[1]
providerInfo.Labels = make(map[string]string)
providerInfo.IPAddress = ep.IPAddress
for k, v := range ep.Labels {
providerInfo.Labels[k] = v
}
mastercfg.SvcMutex.Lock()
mastercfg.ProviderDb[providerDBId] = providerInfo
mastercfg.SvcMutex.Unlock()
}
}
}
}