github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/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 "github.com/juju/utils/packaging/manager" 8 "github.com/juju/utils/series" 9 10 "github.com/juju/juju/container" 11 ) 12 13 var requiredPackages = []string{ 14 "uvtool-libvirt", 15 "uvtool", 16 } 17 18 type containerInitialiser struct{} 19 20 // containerInitialiser implements container.Initialiser. 21 var _ container.Initialiser = (*containerInitialiser)(nil) 22 23 // NewContainerInitialiser returns an instance used to perform the steps 24 // required to allow a host machine to run a KVM container. 25 func NewContainerInitialiser() container.Initialiser { 26 return &containerInitialiser{} 27 } 28 29 // Initialise is specified on the container.Initialiser interface. 30 func (ci *containerInitialiser) Initialise() error { 31 return ensureDependencies() 32 } 33 34 // getPackageManager is a helper function which returns the 35 // package manager implementation for the current system. 36 func getPackageManager() (manager.PackageManager, error) { 37 return manager.NewPackageManager(series.HostSeries()) 38 } 39 40 func ensureDependencies() error { 41 pacman, err := getPackageManager() 42 if err != nil { 43 return err 44 } 45 46 for _, pack := range requiredPackages { 47 if err := pacman.Install(pack); err != nil { 48 return err 49 } 50 } 51 52 return nil 53 }