• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang mastercfg.CfgEndpointState类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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
}
开发者ID:jojimt,项目名称:netplugin,代码行数:29,代码来源:endpoint.go


示例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
}
开发者ID:ChengTiesheng,项目名称:netplugin,代码行数:9,代码来源:netd.go


示例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)
	}
}
开发者ID:karamsivia,项目名称:netplugin,代码行数:60,代码来源:ovsdriver_test.go


示例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()
			}
		}
	}
}
开发者ID:jojimt,项目名称:netplugin,代码行数:71,代码来源:servicelb.go



注:本文中的github.com/contiv/netplugin/netmaster/mastercfg.CfgEndpointState类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang mastercfg.CfgNetworkState类代码示例发布时间:2022-05-23
下一篇:
Golang mastercfg.CfgBgpState类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap