grim/convey

Parents 30c421b637ed
Children 6e00306e2c4a
Forgot to remove the docker network code when we removed the network
--- a/docker/network.go Sat Oct 26 14:37:40 2019 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,97 +0,0 @@
-// Convey
-// Copyright 2016-2018 Gary Kramlich <grim@reaperworld.com>
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-package docker
-
-import (
- "time"
-
- log "github.com/sirupsen/logrus"
-
- "bitbucket.org/rw_grim/convey/logging"
- "bitbucket.org/rw_grim/convey/runtime"
- "bitbucket.org/rw_grim/convey/util"
-)
-
-// Network represents a docker network.
-type Network struct {
- name string
-
- logger *log.Entry
- rt *runtime.Runtime
-}
-
-// NewNetwork creates a new docker network.
-func NewNetwork(rt *runtime.Runtime) (*Network, error) {
- network := &Network{
- name: util.ID(),
- logger: logging.NewAdapter("network"),
- rt: rt,
- }
-
- cmdv := []string{"network", "create", network.name}
-
- _, _, err := DockerOutput("create network", cmdv, rt)
- if err != nil {
- return nil, err
- }
-
- network.logger.Debugf("created network: %#v", network.name)
-
- return network, nil
-}
-
-// Name returns the name of the network.
-func (network *Network) Name() string {
- return network.name
-}
-
-// Destroy tears down the docker network.
-func (network *Network) Destroy() error {
- for _, name := range network.rt.Containers.GetRunning() {
- cmdv := []string{
- "network",
- "disconnect",
- "--force",
- network.name,
- name,
- }
-
- network.logger.Infof("disconnecting container %s from network %s", name, network.Name())
-
- err := Docker("disconnect container", cmdv, network.rt)
- if err != nil {
- msgFmt := "failed to disconnect container %s from network %s"
- network.logger.Warningf(msgFmt, name, network.Name())
-
- continue
- }
-
- msgFmt := "disconnected container %s from network %s"
- network.logger.Infof(msgFmt, name, network.Name())
- }
-
- // monkey with the timeout so our cleanup always runs
- oldTimeout := network.rt.State.PlanTimeout
- defer func() {
- network.rt.State.PlanTimeout = oldTimeout
- }()
- network.rt.State.PlanTimeout = 15 * time.Minute
-
- cmdv := []string{"network", "rm", network.name}
-
- return Docker("remove network", cmdv, network.rt)
-}