github.com/mwhudson/juju@v0.0.0-20160512215208-90ff01f3497f/instance/container.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package instance 5 6 import ( 7 "fmt" 8 ) 9 10 type ContainerType string 11 12 const ( 13 NONE = ContainerType("none") 14 LXC = ContainerType("lxc") 15 LXD = ContainerType("lxd") 16 KVM = ContainerType("kvm") 17 ) 18 19 // ContainerTypes is used to validate add-machine arguments. 20 var ContainerTypes []ContainerType = []ContainerType{ 21 LXC, 22 // LXD is also added under Go 1.3+. 23 LXD, 24 KVM, 25 } 26 27 // ParseContainerTypeOrNone converts the specified string into a supported 28 // ContainerType instance or returns an error if the container type is invalid. 29 // For this version of the function, 'none' is a valid value. 30 func ParseContainerTypeOrNone(ctype string) (ContainerType, error) { 31 if ContainerType(ctype) == NONE { 32 return NONE, nil 33 } 34 return ParseContainerType(ctype) 35 } 36 37 // ParseContainerType converts the specified string into a supported 38 // ContainerType instance or returns an error if the container type is invalid. 39 func ParseContainerType(ctype string) (ContainerType, error) { 40 for _, supportedType := range ContainerTypes { 41 if ContainerType(ctype) == supportedType { 42 return supportedType, nil 43 } 44 } 45 return "", fmt.Errorf("invalid container type %q", ctype) 46 }