Add SessionClose to SessionProvisioner

This commit is contained in:
Jonathan Leibiusky @xetorthio
2017-08-25 11:14:49 -03:00
parent c44512f159
commit 3c6d87cb14
3 changed files with 25 additions and 18 deletions

View File

@@ -50,3 +50,26 @@ func (p *overlaySessionProvisioner) SessionNew(s *types.Session) error {
log.Printf("Connected %s to network [%s]\n", config.PWDContainerName, s.Id)
return nil
}
func (p *overlaySessionProvisioner) SessionClose(s *types.Session) error {
// Disconnect L2 router from the network
dockerClient, err := p.dockerFactory.GetForSession(s.Id)
if err != nil {
log.Println(err)
return err
}
if err := dockerClient.DisconnectNetwork(config.L2ContainerName, s.Id); err != nil {
if !strings.Contains(err.Error(), "is not connected to the network") {
log.Println("ERROR NETWORKING", err)
return err
}
}
log.Printf("Disconnected l2 from network [%s]\n", s.Id)
if err := dockerClient.DeleteNetwork(s.Id); err != nil {
if !strings.Contains(err.Error(), "not found") {
log.Println(err)
return err
}
}
return nil
}

View File

@@ -20,6 +20,7 @@ type InstanceProvisionerApi interface {
type SessionProvisionerApi interface {
SessionNew(session *types.Session) error
SessionClose(session *types.Session) error
}
type InstanceProvisionerFactoryApi interface {

View File

@@ -7,13 +7,11 @@ import (
"math"
"path"
"path/filepath"
"strings"
"sync"
"time"
"golang.org/x/sync/errgroup"
"github.com/play-with-docker/play-with-docker/config"
"github.com/play-with-docker/play-with-docker/docker"
"github.com/play-with-docker/play-with-docker/event"
"github.com/play-with-docker/play-with-docker/pwd/types"
@@ -109,25 +107,10 @@ func (p *pwd) SessionClose(s *types.Session) error {
return err
}
// Disconnect PWD daemon from the network
dockerClient, err := p.dockerFactory.GetForSession(s.Id)
if err != nil {
if err := p.sessionProvisioner.SessionClose(s); err != nil {
log.Println(err)
return err
}
if err := dockerClient.DisconnectNetwork(config.L2ContainerName, s.Id); err != nil {
if !strings.Contains(err.Error(), "is not connected to the network") {
log.Println("ERROR NETWORKING", err)
return err
}
}
log.Printf("Disconnected l2 from network [%s]\n", s.Id)
if err := dockerClient.DeleteNetwork(s.Id); err != nil {
if !strings.Contains(err.Error(), "not found") {
log.Println(err)
return err
}
}
err = p.storage.SessionDelete(s.Id)
if err != nil {