github.com/cloudbase/juju-core@v0.0.0-20140504232958-a7271ac7912f/container/kvm/initialisation.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package kvm 5 6 import ( 7 "fmt" 8 "strings" 9 10 "launchpad.net/juju-core/container" 11 "launchpad.net/juju-core/utils" 12 ) 13 14 var requiredPackages = []string{ 15 "uvtool-libvirt", 16 "uvtool", 17 } 18 19 type containerInitialiser struct{} 20 21 // containerInitialiser implements container.Initialiser. 22 var _ container.Initialiser = (*containerInitialiser)(nil) 23 24 // NewContainerInitialiser returns an instance used to perform the steps 25 // required to allow a host machine to run a KVM container. 26 func NewContainerInitialiser() container.Initialiser { 27 return &containerInitialiser{} 28 } 29 30 // Initialise is specified on the container.Initialiser interface. 31 func (ci *containerInitialiser) Initialise() error { 32 return ensureDependencies() 33 } 34 35 func ensureDependencies() error { 36 return utils.AptGetInstall(requiredPackages...) 37 } 38 39 const kvmNeedsUbuntu = `Sorry, KVM support with the local provider is only supported 40 on the Ubuntu OS.` 41 42 const kvmNotSupported = `KVM is not currently supported with the current settings. 43 You could try running 'kvm-ok' yourself as root to get the full rationale as to 44 why it isn't supported, or potentially some BIOS settings to change to enable 45 KVM support.` 46 47 const neetToInstallKVMOk = `kvm-ok is not installed. Please install the cpu-checker package. 48 sudo apt-get install cpu-checker` 49 50 const missingKVMDeps = `Some required packages are missing for KVM to work: 51 52 sudo apt-get install %s 53 ` 54 55 // VerifyKVMEnabled makes sure that the host OS is Ubuntu, and that the required 56 // packages are installed, and that the host CPU is able to support KVM. 57 func VerifyKVMEnabled() error { 58 if !utils.IsUbuntu() { 59 return fmt.Errorf(kvmNeedsUbuntu) 60 } 61 supported, err := IsKVMSupported() 62 if err != nil { 63 // Missing the kvm-ok package. 64 return fmt.Errorf(neetToInstallKVMOk) 65 } 66 if !supported { 67 return fmt.Errorf(kvmNotSupported) 68 } 69 // Check for other packages needed. 70 toInstall := []string{} 71 for _, pkg := range requiredPackages { 72 if !utils.IsPackageInstalled(pkg) { 73 toInstall = append(toInstall, pkg) 74 } 75 } 76 if len(toInstall) > 0 { 77 return fmt.Errorf(missingKVMDeps, strings.Join(toInstall, " ")) 78 } 79 return nil 80 }