[#240] pool: Add SyncContainerWithNetwork

It is a helper function that uses a `Pool` to fetch network information and
apply it to the container (change the container if it does not fit the
network). Currently, only applies the homomorphic hashing parameter.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-07-05 13:20:10 +03:00 committed by LeL
parent a6ecf6b881
commit c6fee6d01a

View file

@ -1811,3 +1811,26 @@ func (p *Pool) Close() {
p.cancel() p.cancel()
<-p.closedCh <-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
}