Documentation ¶
Index ¶
- Variables
- func AutostartMachine(hostname string) error
- func CreateMachine(params CreateMachineParams) error
- func DestroyMachine(hostname string) error
- func ListMachines() (map[string]string, error)
- func NewContainerInitialiser() container.Initialiser
- func NewContainerManager(conf container.ManagerConfig) (container.Manager, error)
- func SyncImages(series, arch, source string) error
- func VerifyKVMEnabled() error
- type Container
- type ContainerFactory
- type CreateMachineParams
- type StartParams
Constants ¶
This section is empty.
Variables ¶
var ( KvmObjectFactory ContainerFactory = &containerFactory{} DefaultKvmBridge = "virbr0" // 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 )
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.
Functions ¶
func AutostartMachine ¶
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 ¶
DestroyMachine destroys the virtual machine identified by hostname.
func ListMachines ¶
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 ¶
SyncImages updates the local cached images by reading the simplestreams data and downloading the cloud images to the uvtool pool (used by libvirt).
func VerifyKVMEnabled ¶
func VerifyKVMEnabled() error
VerifyKVMEnabled makes sure that the host OS is Ubuntu, and that the required packages are installed, and that the host CPU is able to support KVM.
Types ¶
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 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.