github.com/mwhudson/juju@v0.0.0-20160512215208-90ff01f3497f/environs/tags/tags.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package tags
     5  
     6  import "github.com/juju/names"
     7  
     8  const (
     9  	// JujuTagPrefix is the prefix for Juju-managed tags.
    10  	JujuTagPrefix = "juju-"
    11  
    12  	// JujuModel is the tag name used for identifying the
    13  	// Juju model a resource is part of.
    14  	JujuModel = JujuTagPrefix + "model-uuid"
    15  
    16  	// JujuController is the tag name used for identifying the
    17  	// Juju controller that manages a resource.
    18  	JujuController = JujuTagPrefix + "controller-uuid"
    19  
    20  	// JujuIsController is the tag name used for determining
    21  	// whether a machine instance is a controller or not.
    22  	JujuIsController = JujuTagPrefix + "is-controller"
    23  
    24  	// JujuUnitsDeployed is the tag name used for identifying
    25  	// the units deployed to a machine instance. The value is
    26  	// a space-separated list of the unit names.
    27  	JujuUnitsDeployed = JujuTagPrefix + "units-deployed"
    28  
    29  	// JujuStorageInstance is the tag name used for identifying
    30  	// the Juju storage instance that an IaaS storage resource
    31  	// is assigned to.
    32  	JujuStorageInstance = JujuTagPrefix + "storage-instance"
    33  
    34  	// JujuStorageOwner is the tag name used for identifying
    35  	// the service or unit that owns the Juju storage instance
    36  	// that an IaaS storage resource is assigned to.
    37  	JujuStorageOwner = JujuTagPrefix + "storage-owner"
    38  )
    39  
    40  // ResourceTagger is an interface that can provide resource tags.
    41  type ResourceTagger interface {
    42  	// ResourceTags returns a set of resource tags, and a
    43  	// flag indicating whether or not any resource tags are
    44  	// available.
    45  	ResourceTags() (map[string]string, bool)
    46  }
    47  
    48  // ResourceTags returns tags to set on an infrastructure resource
    49  // for the specified Juju environment.
    50  func ResourceTags(modelTag, controllerTag names.ModelTag, taggers ...ResourceTagger) map[string]string {
    51  	allTags := make(map[string]string)
    52  	for _, tagger := range taggers {
    53  		tags, ok := tagger.ResourceTags()
    54  		if !ok {
    55  			continue
    56  		}
    57  		for k, v := range tags {
    58  			allTags[k] = v
    59  		}
    60  	}
    61  	allTags[JujuModel] = modelTag.Id()
    62  	allTags[JujuController] = controllerTag.Id()
    63  	return allTags
    64  }