github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/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  // ContainerType defines different container technologies known to juju.
    11  type ContainerType string
    12  
    13  // Known container types.
    14  const (
    15  	NONE ContainerType = "none"
    16  	LXD  ContainerType = "lxd"
    17  	KVM  ContainerType = "kvm"
    18  )
    19  
    20  // ContainerTypes is used to validate add-machine arguments.
    21  var ContainerTypes = []ContainerType{
    22  	LXD,
    23  	KVM,
    24  }
    25  
    26  // ParseContainerTypeOrNone converts the specified string into a supported
    27  // ContainerType instance or returns an error if the container type is invalid.
    28  // For this version of the function, 'none' is a valid value.
    29  func ParseContainerTypeOrNone(ctype string) (ContainerType, error) {
    30  	if ContainerType(ctype) == NONE {
    31  		return NONE, nil
    32  	}
    33  	return ParseContainerType(ctype)
    34  }
    35  
    36  // ParseContainerType converts the specified string into a supported
    37  // ContainerType instance or returns an error if the container type is invalid.
    38  func ParseContainerType(ctype string) (ContainerType, error) {
    39  	for _, supportedType := range ContainerTypes {
    40  		if ContainerType(ctype) == supportedType {
    41  			return supportedType, nil
    42  		}
    43  	}
    44  	return "", fmt.Errorf("invalid container type %q", ctype)
    45  }