本文整理汇总了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)
}
}
}