本文整理匯總了Golang中github.com/docker/swarmkit/api.Node.Attachment方法的典型用法代碼示例。如果您正苦於以下問題:Golang Node.Attachment方法的具體用法?Golang Node.Attachment怎麽用?Golang Node.Attachment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/docker/swarmkit/api.Node
的用法示例。
在下文中一共展示了Node.Attachment方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: doNodeAlloc
func (a *Allocator) doNodeAlloc(ctx context.Context, ev events.Event) {
var (
isDelete bool
node *api.Node
)
switch v := ev.(type) {
case state.EventCreateNode:
node = v.Node.Copy()
case state.EventUpdateNode:
node = v.Node.Copy()
case state.EventDeleteNode:
isDelete = true
node = v.Node.Copy()
}
nc := a.netCtx
if isDelete {
if nc.nwkAllocator.IsNodeAllocated(node) {
if err := nc.nwkAllocator.DeallocateNode(node); err != nil {
log.G(ctx).WithError(err).Errorf("Failed freeing network resources for node %s", node.ID)
}
}
return
}
if !nc.nwkAllocator.IsNodeAllocated(node) {
if node.Attachment == nil {
node.Attachment = &api.NetworkAttachment{}
}
node.Attachment.Network = nc.ingressNetwork.Copy()
if err := a.allocateNode(ctx, node); err != nil {
log.G(ctx).WithError(err).Errorf("Failed to allocate network resources for node %s", node.ID)
return
}
if _, err := a.store.Batch(func(batch *store.Batch) error {
return a.commitAllocatedNode(ctx, batch, node)
}); err != nil {
log.G(ctx).WithError(err).Errorf("Failed to commit allocation of network resources for node %s", node.ID)
}
}
}
示例2: doNodeAlloc
func (a *Allocator) doNodeAlloc(ctx context.Context, nc *networkContext, ev events.Event) {
var (
isDelete bool
node *api.Node
)
switch v := ev.(type) {
case state.EventCreateNode:
node = v.Node.Copy()
case state.EventUpdateNode:
node = v.Node.Copy()
case state.EventDeleteNode:
isDelete = true
node = v.Node.Copy()
}
if isDelete {
if nc.nwkAllocator.IsNodeAllocated(node) {
if err := nc.nwkAllocator.DeallocateNode(node); err != nil {
log.G(ctx).Errorf("Failed freeing network resources for node %s: %v", node.ID, err)
}
}
return
}
if !nc.nwkAllocator.IsNodeAllocated(node) {
if node.Attachment == nil {
node.Attachment = &api.NetworkAttachment{}
}
node.Attachment.Network = nc.ingressNetwork.Copy()
if err := a.allocateNode(ctx, nc, node); err != nil {
log.G(ctx).Errorf("Failed to allocate network resources for node %s: %v", node.ID, err)
}
}
}