@@ -18,6 +18,7 @@ import (
1818 "sync/atomic"
1919 "time"
2020
21+ "github.com/docker/docker/api/types"
2122 "github.com/docker/docker/client"
2223 "github.com/pkg/errors"
2324
@@ -31,6 +32,7 @@ import (
3132 "gitlab.com/postgres-ai/database-lab/v3/pkg/log"
3233 "gitlab.com/postgres-ai/database-lab/v3/pkg/models"
3334 "gitlab.com/postgres-ai/database-lab/v3/pkg/util"
35+ "gitlab.com/postgres-ai/database-lab/v3/pkg/util/networks"
3436 "gitlab.com/postgres-ai/database-lab/v3/pkg/util/pglog"
3537)
3638
@@ -67,11 +69,12 @@ type Provisioner struct {
6769 portChecker portChecker
6870 pm * pool.Manager
6971 networkID string
72+ instanceID string
7073}
7174
7275// New creates a new Provisioner instance.
7376func New (ctx context.Context , cfg * Config , dbCfg * resources.DB , docker * client.Client , pm * pool.Manager ,
74- networkID string ) (* Provisioner , error ) {
77+ instanceID , networkID string ) (* Provisioner , error ) {
7578 if err := IsValidConfig (* cfg ); err != nil {
7679 return nil , errors .Wrap (err , "configuration is not valid" )
7780 }
@@ -86,6 +89,7 @@ func New(ctx context.Context, cfg *Config, dbCfg *resources.DB, docker *client.C
8689 portChecker : & localPortChecker {},
8790 pm : pm ,
8891 networkID : networkID ,
92+ instanceID : instanceID ,
8993 ports : make ([]bool , cfg .PortPool .To - cfg .PortPool .From ),
9094 }
9195
@@ -699,14 +703,24 @@ func (p *Provisioner) prepareDB(pgConf *resources.AppConfig, user resources.Ephe
699703
700704// IsCloneRunning checks if clone is running.
701705func (p * Provisioner ) IsCloneRunning (ctx context.Context , cloneName string ) bool {
702- isRunning , err := docker .IsContainerExist (ctx , p .dockerClient , cloneName )
706+ isRunning , err := docker .IsContainerRunning (ctx , p .dockerClient , cloneName )
703707 if err != nil {
704708 log .Err (err )
705709 }
706710
707711 return isRunning
708712}
709713
714+ // ReconnectClone disconnects clone from the old instance network and connect to the actual one.
715+ func (p * Provisioner ) ReconnectClone (ctx context.Context , cloneName string ) error {
716+ return networks .Reconnect (ctx , p .dockerClient , p .instanceID , cloneName )
717+ }
718+
719+ // StartCloneContainer starts clone container.
720+ func (p * Provisioner ) StartCloneContainer (ctx context.Context , containerName string ) error {
721+ return p .dockerClient .ContainerStart (ctx , containerName , types.ContainerStartOptions {})
722+ }
723+
710724// DetectDBVersion detects version of the database.
711725func (p * Provisioner ) DetectDBVersion () string {
712726 pgVersion , err := tools .DetectPGVersion (p .pm .First ().Pool ().DataDir ())
0 commit comments