forked from TrueCloudLab/frostfs-sdk-go
[#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:
parent
a6ecf6b881
commit
c6fee6d01a
1 changed files with 23 additions and 0 deletions
23
pool/pool.go
23
pool/pool.go
|
@ -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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue