github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/container/factory/factory.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  // This package exists solely to avoid circular imports.
     5  
     6  package factory
     7  
     8  import (
     9  	"github.com/juju/errors"
    10  
    11  	"github.com/juju/juju/container"
    12  	"github.com/juju/juju/container/kvm"
    13  	"github.com/juju/juju/container/lxd"
    14  	"github.com/juju/juju/core/instance"
    15  )
    16  
    17  // NewContainerManager creates the appropriate container.Manager for the
    18  // specified container type.
    19  var NewContainerManager = func(forType instance.ContainerType, conf container.ManagerConfig) (container.Manager, error) {
    20  	switch forType {
    21  	case instance.LXD:
    22  		svr, err := lxd.MaybeNewLocalServer()
    23  		if err != nil {
    24  			return nil, errors.Annotate(err, "creating LXD container manager")
    25  		}
    26  		return lxd.NewContainerManager(conf, svr)
    27  	case instance.KVM:
    28  		return kvm.NewContainerManager(conf)
    29  	}
    30  	return nil, errors.Errorf("unknown container type: %q", forType)
    31  }