Ejemplo n.º 1
0
func (a *Adapter) Init(config *client.Config) error {
	var snapshot string = config.Snapshot.ID
	if snapshot != "" {
		if s3Bucket == "" {
			log.Print("[lxc] WARNING: s3bucket is not defined, snapshot ignored")
			snapshot = ""
		} else {
			snapshot = adapter.FormatUUID(snapshot)
		}
	}

	// In reality our goal is to make a switch completely to lz4, but we need to retain
	// compatibility with mesos builds for now, so we default to "xz" and also try
	// to not uncleanly die if its set to a weird value, also setting it to "xz."
	if compression != "xz" && compression != "lz4" {
		compression = "xz"
		log.Printf("[lxc] Warning: invalid compression %s, defaulting to lzma", compression)
	}
	executor := &Executor{
		Name:      executorName,
		Directory: executorPath,
	}

	var mounts []*BindMount
	mounts = nil
	if bindMounts != "" {
		mountStrings := strings.Split(bindMounts, ",")
		mounts = make([]*BindMount, len(mountStrings))
		for ind, ms := range mountStrings {
			var err error
			mounts[ind], err = ParseBindMount(ms)
			if err != nil {
				return err
			}
		}
	}

	container := &Container{
		Name:       config.JobstepID,
		Arch:       arch,
		Dist:       dist,
		Release:    release,
		PreLaunch:  preLaunch,
		PostLaunch: postLaunch,
		Snapshot:   snapshot,
		// TODO(dcramer):  Move S3 logic into core engine
		S3Bucket:    s3Bucket,
		MemoryLimit: memory,
		CpuLimit:    cpus,
		Compression: compression,
		Executor:    executor,
		BindMounts:  mounts,
	}

	a.config = config
	a.container = container

	return nil
}
Ejemplo n.º 2
0
func (a *Adapter) CaptureSnapshot(outputSnapshot string, clientLog *client.Log) error {
	outputSnapshot = adapter.FormatUUID(outputSnapshot)

	err := a.container.CreateImage(outputSnapshot, clientLog)
	if err != nil {
		return err
	}

	if a.container.S3Bucket != "" {
		err = a.container.UploadImage(outputSnapshot, clientLog)
		if err != nil {
			return err
		}
	} else {
		log.Printf("[lxc] warning: cannot upload snapshot, no s3 bucket specified")
	}
	return nil
}