Esempio n. 1
0
func (p *FakeNetworkPool) Remove(network *network.Network) error {
	if p.RemoveError != nil {
		return p.RemoveError
	}

	p.Removed = append(p.Removed, network.String())

	return nil
}
Esempio n. 2
0
func (p *RealNetworkPool) Release(network *network.Network) {
	if !p.ipNet.Contains(network.IP()) {
		return
	}

	p.poolMutex.Lock()
	defer p.poolMutex.Unlock()

	p.pool = append(p.pool, network)
}
Esempio n. 3
0
func (p *RealNetworkPool) Remove(network *network.Network) error {
	idx := 0
	found := false

	p.poolMutex.Lock()
	defer p.poolMutex.Unlock()

	for i, existingNetwork := range p.pool {
		if existingNetwork.String() == network.String() {
			idx = i
			found = true
			break
		}
	}

	if !found {
		return NetworkTakenError{network}
	}

	p.pool = append(p.pool[:idx], p.pool[idx+1:]...)

	return nil
}
Esempio n. 4
0
			})

			It("returns the error and releases the uid and network", func() {
				_, err := pool.Create(warden.ContainerSpec{})
				Expect(err).To(Equal(nastyError))

				Expect(fakeUIDPool.Released).To(ContainElement(uint32(10000)))
				Expect(fakeNetworkPool.Released).To(ContainElement("1.2.0.0/30"))
			})
		})
	})

	Describe("restoring", func() {
		var snapshot io.Reader

		var restoredNetwork *network.Network

		BeforeEach(func() {
			buf := new(bytes.Buffer)

			snapshot = buf

			_, ipNet, err := net.ParseCIDR("10.244.0.0/30")
			Expect(err).ToNot(HaveOccurred())

			restoredNetwork = network.New(ipNet)

			err = json.NewEncoder(buf).Encode(
				linux_backend.ContainerSnapshot{
					ID:     "some-restored-id",
					Handle: "some-restored-handle",
Esempio n. 5
0
func (p *FakeNetworkPool) Release(network *network.Network) {
	p.Released = append(p.Released, network.String())
}