Example #1
0
func (p *LinuxResourcePool) acquirePoolResources(spec garden.ContainerSpec, id string, logger lager.Logger) (*linux_backend.Resources, error) {
	resources := linux_backend.NewResources(0, nil, "", nil, p.externalIP)

	subnet, ip, err := parseNetworkSpec(spec.Network)
	if err != nil {
		return nil, fmt.Errorf("create container: invalid network spec: %v", err)
	}

	if err := p.acquireUID(resources, spec.Privileged); err != nil {
		return nil, err
	}

	if resources.Network, err = p.subnetPool.Acquire(subnet, ip, logger.Session("subnet-pool")); err != nil {
		p.releasePoolResources(resources, logger)
		return nil, err
	}

	return resources, nil
}
Example #2
0
		fakeCgroups = fake_cgroups_manager.New("/cgroups", "some-id")

		fakeQuotaManager = new(fake_quota_manager.FakeQuotaManager)
		fakeBandwidthManager = fake_bandwidth_manager.New()
		fakeOomWatcher = new(fake_watcher.FakeWatcher)

		var err error
		containerDir, err = ioutil.TempDir("", "depot")
		Expect(err).ToNot(HaveOccurred())

		_, subnet, _ := net.ParseCIDR("2.3.4.0/30")
		containerResources = linux_backend.NewResources(
			1235,
			&linux_backend.Network{
				IP:     net.ParseIP("1.2.3.4"),
				Subnet: subnet,
			},
			"some-bridge",
			[]uint32{},
			nil,
		)
	})

	JustBeforeEach(func() {
		container = linux_container.NewLinuxContainer(
			linux_backend.LinuxContainerSpec{
				ID:                  "some-id",
				ContainerPath:       containerDir,
				ContainerRootFSPath: "some-volume-path",
				Resources:           containerResources,
				ContainerSpec: garden.ContainerSpec{
					Handle:    "some-handle",
Example #3
0
func (p *LinuxResourcePool) Restore(snapshot io.Reader) (linux_backend.LinuxContainerSpec, error) {
	var containerSnapshot linux_container.ContainerSnapshot

	err := json.NewDecoder(snapshot).Decode(&containerSnapshot)
	if err != nil {
		return linux_backend.LinuxContainerSpec{}, err
	}

	id := containerSnapshot.ID
	rLog := p.logger.Session("restore", lager.Data{
		"id": id,
	})

	rLog.Debug("restoring")

	resources := containerSnapshot.Resources
	subnetLogger := rLog.Session("subnet-pool")

	if err = p.subnetPool.Remove(resources.Network, subnetLogger); err != nil {
		return linux_backend.LinuxContainerSpec{}, err
	}

	if err = p.bridges.Rereserve(resources.Bridge, resources.Network.Subnet, id); err != nil {
		p.subnetPool.Release(resources.Network, subnetLogger)
		return linux_backend.LinuxContainerSpec{}, err
	}

	for _, port := range resources.Ports {
		err = p.portPool.Remove(port)
		if err != nil {
			p.subnetPool.Release(resources.Network, subnetLogger)

			for _, port := range resources.Ports {
				p.portPool.Release(port)
			}

			return linux_backend.LinuxContainerSpec{}, err
		}
	}

	version, err := p.restoreContainerVersion(id)
	if err != nil {
		return linux_backend.LinuxContainerSpec{}, err
	}

	spec := linux_backend.LinuxContainerSpec{
		ID:                  id,
		ContainerPath:       path.Join(p.depotPath, id),
		ContainerRootFSPath: containerSnapshot.RootFSPath,

		State:  linux_backend.State(containerSnapshot.State),
		Events: containerSnapshot.Events,
		ContainerSpec: garden.ContainerSpec{
			Handle:     containerSnapshot.Handle,
			GraceTime:  containerSnapshot.GraceTime,
			Properties: containerSnapshot.Properties,
		},

		Resources: linux_backend.NewResources(
			resources.RootUID,
			resources.Network,
			resources.Bridge,
			resources.Ports,
			p.externalIP,
		),

		Limits:    containerSnapshot.Limits,
		NetIns:    containerSnapshot.NetIns,
		NetOuts:   containerSnapshot.NetOuts,
		Processes: containerSnapshot.Processes,
		Version:   version,
	}

	return spec, nil
}