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