本文整理汇总了Golang中github.com/coreos/flannel/backend.Backend类的典型用法代码示例。如果您正苦于以下问题:Golang Backend类的具体用法?Golang Backend怎么用?Golang Backend使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Backend类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Init
func (n *Network) Init(ctx context.Context, iface *net.Interface, iaddr net.IP, eaddr net.IP) *backend.SubnetDef {
var be backend.Backend
var sn *backend.SubnetDef
steps := []func() error{
func() (err error) {
n.Config, err = n.sm.GetNetworkConfig(ctx, n.Name)
if err != nil {
log.Error("Failed to retrieve network config: ", err)
}
return
},
func() (err error) {
be, err = newBackend(n.sm, n.Name, n.Config)
if err != nil {
log.Error("Failed to create backend: ", err)
} else {
n.be = be
}
return
},
func() (err error) {
sn, err = be.Init(ctx, iface, iaddr, eaddr)
if err != nil {
log.Errorf("Failed to initialize network %v (type %v): %v", n.Name, n.Config.BackendType, err)
}
n.lease = sn.Lease
return
},
func() (err error) {
if n.ipMasq {
flannelNet := n.Config.Network
if err = setupIPMasq(flannelNet); err != nil {
log.Errorf("Failed to set up IP Masquerade for network %v: %v", n.Name, err)
}
}
return
},
}
for _, s := range steps {
for ; ; time.Sleep(time.Second) {
select {
case <-ctx.Done():
return nil
default:
}
err := s()
if err == nil {
break
}
}
}
return sn
}
示例2: run
func run(be backend.Backend, exit chan int) {
var err error
defer func() {
if err == nil || err == task.ErrCanceled {
exit <- 0
} else {
log.Error(err)
exit <- 1
}
}()
iface, ipaddr, err := lookupIface()
if err != nil {
return
}
if iface.MTU == 0 {
err = fmt.Errorf("Failed to determine MTU for %s interface", ipaddr)
return
}
log.Infof("Using %s as external interface", ipaddr)
sn, err := be.Init(iface, ipaddr, opts.ipMasq)
if err != nil {
log.Error("Could not init %v backend: %v", be.Name(), err)
return
}
writeSubnetFile(sn)
daemon.SdNotify("READY=1")
log.Infof("%s mode initialized", be.Name())
be.Run()
}