Skip to content

Commit

Permalink
Add SessionClose to SessionProvisioner
Browse files Browse the repository at this point in the history
  • Loading branch information
xetorthio committed Aug 25, 2017
1 parent c44512f commit 3c6d87c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
23 changes: 23 additions & 0 deletions provisioner/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions provisioner/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type InstanceProvisionerApi interface {

type SessionProvisionerApi interface {
SessionNew(session *types.Session) error
SessionClose(session *types.Session) error
}

type InstanceProvisionerFactoryApi interface {
Expand Down
19 changes: 1 addition & 18 deletions pwd/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 3c6d87c

Please sign in to comment.