github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/provider/local/prereqs.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package local 5 6 import ( 7 "errors" 8 "fmt" 9 "os/exec" 10 "runtime" 11 12 "github.com/juju/utils" 13 14 "github.com/juju/juju/container/kvm" 15 "github.com/juju/juju/instance" 16 ) 17 18 var notLinuxError = errors.New("The local provider is currently only available for Linux") 19 20 const aptAddRepositoryJujuStable = ` 21 sudo apt-add-repository ppa:juju/stable # required for MongoDB SSL support 22 sudo apt-get update` 23 24 const installLxcUbuntu = ` 25 Linux Containers (LXC) userspace tools must be 26 installed to enable the local provider: 27 28 sudo apt-get install lxc` 29 30 const installCloudImageUtils = ` 31 cloud-image-utils must be installed to enable the local provider: 32 33 sudo apt-get install cloud-image-utils` 34 35 const installJujuLocalUbuntu = ` 36 juju-local must be installed to enable the local provider: 37 38 sudo apt-get install juju-local` 39 40 const installLxcGeneric = ` 41 Linux Containers (LXC) userspace tools must be installed to enable the 42 local provider. Please consult your operating system distribution's 43 documentation for instructions on installing the LXC userspace tools.` 44 45 const errUnsupportedOS = `Unsupported operating system: %s 46 The local provider is currently only available for Linux` 47 48 // lxclsPath is the path to "lxc-ls", an LXC userspace tool 49 // we check the presence of to determine whether the 50 // tools are installed. This is a variable only to support 51 // unit testing. 52 var lxclsPath = "lxc-ls" 53 54 // The operating system the process is running in. 55 // This is a variable only to support unit testing. 56 var goos = runtime.GOOS 57 58 // VerifyPrerequisites verifies the prerequisites of 59 // the local machine (machine 0) for running the local 60 // provider. 61 var VerifyPrerequisites = func(containerType instance.ContainerType) error { 62 if goos != "linux" { 63 return fmt.Errorf(errUnsupportedOS, goos) 64 } 65 if err := verifyJujuLocal(); err != nil { 66 return err 67 } 68 switch containerType { 69 case instance.LXC: 70 return verifyLxc() 71 case instance.KVM: 72 return kvm.VerifyKVMEnabled() 73 } 74 return fmt.Errorf("Unknown container type specified in the config.") 75 } 76 77 func verifyLxc() error { 78 _, err := exec.LookPath(lxclsPath) 79 if err != nil { 80 return wrapLxcNotFound(err) 81 } 82 return verifyCloudImageUtils() 83 } 84 85 func verifyCloudImageUtils() error { 86 if isPackageInstalled("cloud-image-utils") { 87 return nil 88 } 89 return errors.New(installCloudImageUtils) 90 } 91 92 func verifyJujuLocal() error { 93 if isPackageInstalled("juju-local") { 94 return nil 95 } 96 return errors.New(installJujuLocalUbuntu) 97 } 98 99 func wrapLxcNotFound(err error) error { 100 if utils.IsUbuntu() { 101 return fmt.Errorf("%v\n%s", err, installLxcUbuntu) 102 } 103 return fmt.Errorf("%v\n%s", err, installLxcGeneric) 104 }