func (container *Container) disconnectFromNetwork(n libnetwork.Network) error { var ( ep libnetwork.Endpoint sbox libnetwork.Sandbox ) s := func(current libnetwork.Endpoint) bool { if sb := current.Info().Sandbox(); sb != nil { if sb.ContainerID() == container.ID { ep = current sbox = sb return true } } return false } n.WalkEndpoints(s) if ep == nil { return fmt.Errorf("container %s is not connected to the network", container.ID) } if err := ep.Leave(sbox); err != nil { return fmt.Errorf("container %s failed to leave network %s: %v", container.ID, n.Name(), err) } if err := ep.Delete(); err != nil { return fmt.Errorf("endpoint delete failed for container %s on network %s: %v", container.ID, n.Name(), err) } delete(container.NetworkSettings.Networks, n.Name()) return nil }
func (daemon *Daemon) disconnectFromNetwork(container *container.Container, n libnetwork.Network, force bool) error { var ( ep libnetwork.Endpoint sbox libnetwork.Sandbox ) s := func(current libnetwork.Endpoint) bool { epInfo := current.Info() if epInfo == nil { return false } if sb := epInfo.Sandbox(); sb != nil { if sb.ContainerID() == container.ID { ep = current sbox = sb return true } } return false } n.WalkEndpoints(s) if ep == nil && force { epName := strings.TrimPrefix(container.Name, "/") ep, err := n.EndpointByName(epName) if err != nil { return err } return ep.Delete(force) } if ep == nil { return fmt.Errorf("container %s is not connected to the network", container.ID) } if err := ep.Leave(sbox); err != nil { return fmt.Errorf("container %s failed to leave network %s: %v", container.ID, n.Name(), err) } container.NetworkSettings.Ports = getPortMapInfo(sbox) if err := ep.Delete(false); err != nil { return fmt.Errorf("endpoint delete failed for container %s on network %s: %v", container.ID, n.Name(), err) } delete(container.NetworkSettings.Networks, n.Name()) if daemon.clusterProvider != nil && n.Info().Dynamic() && !container.Managed { if err := daemon.clusterProvider.DetachNetwork(n.Name(), container.ID); err != nil { logrus.Warnf("error detaching from network %s: %v", n.Name(), err) if err := daemon.clusterProvider.DetachNetwork(n.ID(), container.ID); err != nil { logrus.Warnf("error detaching from network %s: %v", n.ID(), err) } } } return nil }
func disconnectFromNetwork(container *container.Container, n libnetwork.Network, force bool) error { var ( ep libnetwork.Endpoint sbox libnetwork.Sandbox ) s := func(current libnetwork.Endpoint) bool { epInfo := current.Info() if epInfo == nil { return false } if sb := epInfo.Sandbox(); sb != nil { if sb.ContainerID() == container.ID { ep = current sbox = sb return true } } return false } n.WalkEndpoints(s) if ep == nil && force { epName := strings.TrimPrefix(container.Name, "/") ep, err := n.EndpointByName(epName) if err != nil { return err } return ep.Delete(force) } if ep == nil { return fmt.Errorf("container %s is not connected to the network", container.ID) } if err := ep.Leave(sbox); err != nil { return fmt.Errorf("container %s failed to leave network %s: %v", container.ID, n.Name(), err) } if err := ep.Delete(false); err != nil { return fmt.Errorf("endpoint delete failed for container %s on network %s: %v", container.ID, n.Name(), err) } delete(container.NetworkSettings.Networks, n.Name()) return nil }
func (container *Container) disconnectFromNetwork(n libnetwork.Network, updateSettings bool) error { var ( ep libnetwork.Endpoint sbox libnetwork.Sandbox ) s := func(current libnetwork.Endpoint) bool { if sb := current.Info().Sandbox(); sb != nil { if sb.ContainerID() == container.ID { ep = current sbox = sb return true } } return false } n.WalkEndpoints(s) if ep == nil { return fmt.Errorf("could not locate network endpoint for container %s", container.ID) } if err := ep.Leave(sbox); err != nil { return fmt.Errorf("container %s failed to leave network %s: %v", container.ID, n.Name(), err) } if err := ep.Delete(); err != nil { return fmt.Errorf("endpoint delete failed for container %s on network %s: %v", container.ID, n.Name(), err) } if updateSettings { networks := container.NetworkSettings.Networks for i, s := range networks { sn, err := container.daemon.FindNetwork(s) if err != nil { continue } if sn.Name() == n.Name() { networks = append(networks[:i], networks[i+1:]...) container.NetworkSettings.Networks = networks break } } } return nil }
func runParallelTests(t *testing.T, thrNumber int) { var ( ep libnetwork.Endpoint sb libnetwork.Sandbox err error ) t.Parallel() pTest := flag.Lookup("test.parallel") if pTest == nil { t.Skip("Skipped because test.parallel flag not set;") } numParallel, err := strconv.Atoi(pTest.Value.String()) if err != nil { t.Fatal(err) } if numParallel < numThreads { t.Skip("Skipped because t.parallel was less than ", numThreads) } runtime.LockOSThread() defer runtime.UnlockOSThread() if thrNumber == first { createGlobalInstance(t) } if thrNumber != first { select { case <-start: } thrdone := make(chan struct{}) done <- thrdone defer close(thrdone) if thrNumber == last { defer close(done) } err = netns.Set(testns) if err != nil { t.Fatal(err) } } defer netns.Set(origns) net1, err := controller.NetworkByName("testhost") if err != nil { t.Fatal(err) } if net1 == nil { t.Fatal("Could not find testhost") } net2, err := controller.NetworkByName("network2") if err != nil { t.Fatal(err) } if net2 == nil { t.Fatal("Could not find network2") } epName := fmt.Sprintf("pep%d", thrNumber) if thrNumber == first { ep, err = net1.EndpointByName(epName) } else { ep, err = net2.EndpointByName(epName) } if err != nil { t.Fatal(err) } if ep == nil { t.Fatal("Got nil ep with no error") } cid := fmt.Sprintf("%drace", thrNumber) controller.WalkSandboxes(libnetwork.SandboxContainerWalker(&sb, cid)) if sb == nil { t.Fatalf("Got nil sandbox for container: %s", cid) } for i := 0; i < iterCnt; i++ { parallelJoin(t, sb, ep, thrNumber) parallelLeave(t, sb, ep, thrNumber) } debugf("\n") err = ep.Delete() if err != nil { t.Fatal(err) } if thrNumber == first { for thrdone := range done { select { case <-thrdone: } } testns.Close() err = sb.Delete() if err != nil { t.Fatal(err) } ep.Delete() if err != nil { t.Fatal(err) } if err := net2.Delete(); err != nil { t.Fatal(err) } } }