当前位置: 首页>>代码示例>>Golang>>正文


Golang IP.AF方法代码示例

本文整理汇总了Golang中github.com/google/seesaw/common/seesaw.IP.AF方法的典型用法代码示例。如果您正苦于以下问题:Golang IP.AF方法的具体用法?Golang IP.AF怎么用?Golang IP.AF使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/google/seesaw/common/seesaw.IP的用法示例。


在下文中一共展示了IP.AF方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: down

// down takes down an IP address for a vserver, then takes down all services
// for that IP address.
func (v *vserver) down(ip seesaw.IP) {
	ncc := v.engine.ncc
	if err := ncc.Dial(); err != nil {
		log.Fatalf("%v: failed to connect to NCC: %v", v, err)
	}
	defer ncc.Close()

	// If this is an anycast VIP, withdraw the BGP route.
	nip := ip.IP()
	if seesaw.IsAnycast(nip) {
		if v.engine.config.AnycastEnabled {
			log.Infof("%v: withdrawing BGP route for %v", v, ip)
			if err := ncc.BGPWithdrawVIP(nip); err != nil {
				log.Fatalf("%v: failed to withdraw VIP %v: %v", v, ip, err)
			}
		}
		vip := seesaw.NewVIP(nip, nil)
		if err := v.engine.lbInterface.DeleteVIP(vip); err != nil {
			log.Fatalf("%v: failed to remove VIP %v: %v", v, ip, err)
		}
		if err := v.engine.lbInterface.DeleteVserver(v.lbVservers[ip], ip.AF()); err != nil {
			log.Fatalf("%v: failed to delete Vserver: %v", v, err)
		}
	}
	// TODO(jsing): Should we delay while the BGP routes propagate?

	delete(v.active, ip)
	v.updateServices(ip)
	log.Infof("%v: VIP %v down", v, ip)
}
开发者ID:bluemutedwisdom,项目名称:seesaw,代码行数:32,代码来源:vserver.go

示例2: markBackend

// markBackend returns a mark for the specified backend and sets up the IPVS
// service entry if it does not exist.
func (h *healthcheckManager) markBackend(backend seesaw.IP) uint32 {
	mark, ok := h.marks[backend]
	if ok {
		return mark
	}

	mark, err := h.markAlloc.get()
	if err != nil {
		log.Fatalf("Failed to get mark: %v", err)
	}
	h.marks[backend] = mark

	ip := net.IPv6zero
	if backend.AF() == seesaw.IPv4 {
		ip = net.IPv4zero
	}

	ipvsSvc := &ipvs.Service{
		Address:      ip,
		Protocol:     ipvs.IPProto(0),
		Port:         0,
		Scheduler:    "rr",
		FirewallMark: mark,
		Destinations: []*ipvs.Destination{
			{
				Address: backend.IP(),
				Port:    0,
				Weight:  1,
				Flags:   ipvs.DFForwardRoute,
			},
		},
	}

	if err := h.ncc.Dial(); err != nil {
		log.Fatalf("Failed to connect to NCC: %v", err)
	}
	defer h.ncc.Close()

	log.Infof("Adding DSR IPVS service for %s (mark %d)", backend, mark)
	if err := h.ncc.IPVSAddService(ipvsSvc); err != nil {
		log.Fatalf("Failed to add IPVS service for DSR: %v", err)
	}

	return mark
}
开发者ID:Cepave,项目名称:lvs-metrics,代码行数:47,代码来源:healthcheck.go

示例3: up

// up brings up all healthy services for an IP address for a vserver, then
// brings up the IP address.
func (v *vserver) up(ip seesaw.IP) {
	ncc := v.engine.ncc
	if err := ncc.Dial(); err != nil {
		log.Fatalf("%v: failed to connect to NCC: %v", v, err)
	}
	defer ncc.Close()

	v.active[ip] = true
	v.updateServices(ip)

	// If this is an anycast VIP, start advertising a BGP route.
	nip := ip.IP()
	if seesaw.IsAnycast(nip) {
		// TODO(jsing): Create an LBVserver that only encapsulates
		// the necessary state, rather than storing a full vserver
		// snapshot.
		lbVserver := v.snapshot()
		lbVserver.Services = nil
		lbVserver.Warnings = nil
		if err := v.engine.lbInterface.AddVserver(lbVserver, ip.AF()); err != nil {
			log.Fatalf("%v: failed to add Vserver: %v", v, err)
		}
		v.lbVservers[ip] = lbVserver

		vip := seesaw.NewVIP(nip, nil)
		if err := v.engine.lbInterface.AddVIP(vip); err != nil {
			log.Fatalf("%v: failed to add VIP %v: %v", v, ip, err)
		}
		// TODO(angusc): Filter out anycast VIPs for non-anycast clusters further
		// upstream.
		if v.engine.config.AnycastEnabled {
			log.Infof("%v: advertising BGP route for %v", v, ip)
			if err := ncc.BGPAdvertiseVIP(nip); err != nil {
				log.Fatalf("%v: failed to advertise VIP %v: %v", v, ip, err)
			}
		} else {
			log.Warningf("%v: %v is an anycast VIP, but anycast is not enabled", v, ip)
		}
	}

	log.Infof("%v: VIP %v up", v, ip)
}
开发者ID:bluemutedwisdom,项目名称:seesaw,代码行数:44,代码来源:vserver.go

示例4: unmarkBackend

// unmarkBackend removes the mark for a given backend and removes the IPVS
// service entry if it exists.
func (h *healthcheckManager) unmarkBackend(backend seesaw.IP) {
	mark, ok := h.marks[backend]
	if !ok {
		return
	}

	ip := net.IPv6zero
	if backend.AF() == seesaw.IPv4 {
		ip = net.IPv4zero
	}

	ipvsSvc := &ipvs.Service{
		Address:      ip,
		Protocol:     ipvs.IPProto(0),
		Port:         0,
		Scheduler:    "rr",
		FirewallMark: mark,
		Destinations: []*ipvs.Destination{
			{
				Address: backend.IP(),
				Port:    0,
				Weight:  1,
				Flags:   ipvs.DFForwardRoute,
			},
		},
	}

	if err := h.ncc.Dial(); err != nil {
		log.Fatalf("Failed to connect to NCC: %v", err)
	}
	defer h.ncc.Close()

	log.Infof("Removing DSR IPVS service for %s (mark %d)", backend, mark)
	if err := h.ncc.IPVSDeleteService(ipvsSvc); err != nil {
		log.Fatalf("Failed to remove DSR IPVS service: %v", err)
	}

	delete(h.marks, backend)
	h.markAlloc.put(mark)
}
开发者ID:Cepave,项目名称:lvs-metrics,代码行数:42,代码来源:healthcheck.go


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