Skip to content

Commit

Permalink
[#240] client: Add SyncContainerWithNetwork func
Browse files Browse the repository at this point in the history
It requests network configuration and syncs it (changes if required) with
passed container.

Signed-off-by: Pavel Karpy <[email protected]>
  • Loading branch information
carpawell committed Jul 4, 2022
1 parent c74f36a commit 718b47e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions client/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,3 +816,23 @@ func (c *Client) ContainerAnnounceUsedSpace(ctx context.Context, prm PrmAnnounce

return &res, nil
}

// SyncContainerWithNetwork requests network configuration using passed client
// and applies it to the container.
//
// Note: if container does not match network configuration, SyncContainerWithNetwork
// changes it.
//
// Returns any network/parsing config errors.
//
// See also NetworkInfo, container.ApplyNetworkConfig.
func SyncContainerWithNetwork(ctx context.Context, cnr *container.Container, c *Client) error {
res, err := c.NetworkInfo(ctx, PrmNetworkInfo{})
if err != nil {
return fmt.Errorf("network info call: %w", err)
}

cnr.ApplyNetworkConfig(*res.Info())

return nil
}

0 comments on commit 718b47e

Please sign in to comment.