github.com/vieux/docker@v0.6.3-0.20161004191708-e097c2a938c7/daemon/cluster/executor/container/attachment.go (about) 1 package container 2 3 import ( 4 executorpkg "github.com/docker/docker/daemon/cluster/executor" 5 "github.com/docker/swarmkit/api" 6 "golang.org/x/net/context" 7 ) 8 9 // networkAttacherController implements agent.Controller against docker's API. 10 // 11 // networkAttacherController manages the lifecycle of network 12 // attachment of a docker unmanaged container managed as a task from 13 // agent point of view. It provides network attachment information to 14 // the unmanaged container for it to attach to the network and run. 15 type networkAttacherController struct { 16 backend executorpkg.Backend 17 task *api.Task 18 adapter *containerAdapter 19 closed chan struct{} 20 } 21 22 func newNetworkAttacherController(b executorpkg.Backend, task *api.Task) (*networkAttacherController, error) { 23 adapter, err := newContainerAdapter(b, task) 24 if err != nil { 25 return nil, err 26 } 27 28 return &networkAttacherController{ 29 backend: b, 30 task: task, 31 adapter: adapter, 32 closed: make(chan struct{}), 33 }, nil 34 } 35 36 func (nc *networkAttacherController) Update(ctx context.Context, t *api.Task) error { 37 return nil 38 } 39 40 func (nc *networkAttacherController) Prepare(ctx context.Context) error { 41 // Make sure all the networks that the task needs are created. 42 if err := nc.adapter.createNetworks(ctx); err != nil { 43 return err 44 } 45 46 return nil 47 } 48 49 func (nc *networkAttacherController) Start(ctx context.Context) error { 50 return nc.adapter.networkAttach(ctx) 51 } 52 53 func (nc *networkAttacherController) Wait(pctx context.Context) error { 54 ctx, cancel := context.WithCancel(pctx) 55 defer cancel() 56 57 return nc.adapter.waitForDetach(ctx) 58 } 59 60 func (nc *networkAttacherController) Shutdown(ctx context.Context) error { 61 return nil 62 } 63 64 func (nc *networkAttacherController) Terminate(ctx context.Context) error { 65 return nil 66 } 67 68 func (nc *networkAttacherController) Remove(ctx context.Context) error { 69 // Try removing the network referenced in this task in case this 70 // task is the last one referencing it 71 if err := nc.adapter.removeNetworks(ctx); err != nil { 72 return err 73 } 74 75 return nil 76 } 77 78 func (nc *networkAttacherController) Close() error { 79 return nil 80 }