This section is empty.


View Source
var (
	KvmObjectFactory ContainerFactory = &containerFactory{}

	// In order for Juju to be able to create the hardware characteristics of
	// the kvm machines it creates, we need to be explicit in our definition
	// of memory, cpu-cores and root-disk.  The defaults here have been
	// extracted from the uvt-kvm executable.
	DefaultMemory uint64 = 512 // MB
	DefaultCpu    uint64 = 1
	DefaultDisk   uint64 = 8 // GB

	// There are some values where it doesn't make sense to go below.
	MinMemory uint64 = 512 // MB
	MinCpu    uint64 = 1
	MinDisk   uint64 = 2 // GB
View Source
var IsKVMSupported = func() (bool, error) {

	// Prefer the user's $PATH first, but check /usr/sbin if we can't
	// find kvm-ok there
	var foundPath string
	const binName = "kvm-ok"
	if path, err := exec.LookPath(binName); err == nil {
		foundPath = path
	} else if path, err := exec.LookPath(filepath.Join(kvmPath, binName)); err == nil {
		foundPath = path
	} else {
		return false, errors.NotFoundf("%s executable", binName)

	command := exec.Command(foundPath)
	output, err := command.CombinedOutput()

	if err != nil {
		return false, errors.Annotate(err, string(output))
	logger.Debugf("%s output:\n%s", binName, output)
	return command.ProcessState.Success(), nil

    IsKVMSupported calls into the kvm-ok executable from the cpu-checkers package. It is a variable to allow us to overrid behaviour in the tests.


    func AutostartMachine

    func AutostartMachine(hostname string) error

      AutostartMachine indicates that the virtual machines should automatically restart when the host restarts.

      func CreateMachine

      func CreateMachine(params CreateMachineParams) error

        CreateMachine creates a virtual machine and starts it.

        func DestroyMachine

        func DestroyMachine(hostname string) error

          DestroyMachine destroys the virtual machine identified by hostname.

          func ListMachines

          func ListMachines() (map[string]string, error)

            ListMachines returns a map of machine name to state, where state is one of: running, idle, paused, shutdown, shut off, crashed, dying, pmsuspended.

            func NewContainerInitialiser

            func NewContainerInitialiser() container.Initialiser

              NewContainerInitialiser returns an instance used to perform the steps required to allow a host machine to run a KVM container.

              func NewContainerManager

              func NewContainerManager(conf container.ManagerConfig) (container.Manager, error)

                NewContainerManager returns a manager object that can start and stop kvm containers. The containers that are created are namespaced by the name parameter.

                func SyncImages

                func SyncImages(series, arch, source string) error

                  SyncImages updates the local cached images by reading the simplestreams data and downloading the cloud images to the uvtool pool (used by libvirt).

                  func WriteTemplate

                  func WriteTemplate(path string, params CreateMachineParams) (err error)


                  type Container

                  type Container interface {
                  	// Name returns the name of the container.
                  	Name() string
                  	// Start runs the container as a daemon.
                  	Start(params StartParams) error
                  	// Stop terminates the running container.
                  	Stop() error
                  	// IsRunning returns wheter or not the container is running and active.
                  	IsRunning() bool
                  	// String returns information about the container, like the name, state,
                  	// and process id.
                  	String() string

                    Container represents a virtualized container instance and provides operations to create, maintain and destroy the container.

                    type ContainerFactory

                    type ContainerFactory interface {
                    	// New returns a container instance which can then be used for operations
                    	// like Start() and Stop()
                    	New(string) Container
                    	// List returns all the existing containers on the system.
                    	List() ([]Container, error)

                      ContainerFactory represents the methods used to create Containers. This wraps the low level OS functions for dealing with the containers.

                      type CreateMachineParams

                      type CreateMachineParams struct {
                      	Hostname      string
                      	Series        string
                      	Arch          string
                      	UserDataFile  string
                      	NetworkBridge string
                      	Memory        uint64
                      	CpuCores      uint64
                      	RootDisk      uint64
                      	Interfaces    []network.InterfaceInfo

                      type StartParams

                      type StartParams struct {
                      	Series           string
                      	Arch             string
                      	UserDataFile     string
                      	Network          *container.NetworkConfig
                      	Memory           uint64 // MB
                      	CpuCores         uint64
                      	RootDisk         uint64 // GB
                      	ImageDownloadUrl string

                        StartParams is a simple parameter struct for Container.Start.

                        func ParseConstraintsToStartParams

                        func ParseConstraintsToStartParams(cons constraints.Value) StartParams

                          ParseConstraintsToStartParams takes a constrants object and returns a bare StartParams object that has Memory, Cpu, and Disk populated. If there are no defined values in the constraints for those fields, default values are used. Other constrains cause a warning to be emitted.


                          Path Synopsis