diff --git a/pool/pool.go b/pool/pool.go index b51d21a..42caaf5 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -1811,3 +1811,26 @@ func (p *Pool) Close() { p.cancel() <-p.closedCh } + +// SyncContainerWithNetwork applies network configuration received via +// the Pool to the container. Changes the container if it does not satisfy +// network configuration. +// +// Pool and container MUST not be nil. +// +// Returns any error that does not allow reading configuration +// from the network. +func SyncContainerWithNetwork(ctx context.Context, cnr *container.Container, p *Pool) error { + ni, err := p.NetworkInfo(ctx) + if err != nil { + return fmt.Errorf("network info: %w", err) + } + + if ni == nil { + return errors.New("empty network info") + } + + container.ApplyNetworkConfig(cnr, *ni) + + return nil +}