github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/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  	// JujuEnv is the tag name used for identifying the
    13  	// Juju environment a resource is part of.
    14  	JujuEnv = JujuTagPrefix + "env-uuid"
    15  
    16  	// JujuStateServer is the tag name used for determining
    17  	// whether a machine instance is a state server or not.
    18  	JujuStateServer = JujuTagPrefix + "is-state"
    19  
    20  	// JujuUnitsDeployed is the tag name used for identifying
    21  	// the units deployed to a machine instance.
    22  	JujuUnitsDeployed = JujuTagPrefix + "units-deployed"
    23  
    24  	// JujuStorageInstance is the tag name used for identifying
    25  	// the Juju storage instance that an IaaS storage resource
    26  	// is assigned to.
    27  	JujuStorageInstance = JujuTagPrefix + "storage-instance"
    28  
    29  	// JujuStorageOwner is the tag name used for identifying
    30  	// the service or unit that owns the Juju storage instance
    31  	// that an IaaS storage resource is assigned to.
    32  	JujuStorageOwner = JujuTagPrefix + "storage-owner"
    33  )
    34  
    35  // ResourceTagger is an interface that can provide resource tags.
    36  type ResourceTagger interface {
    37  	// ResourceTags returns a set of resource tags, and a
    38  	// flag indicating whether or not any resource tags are
    39  	// available.
    40  	ResourceTags() (map[string]string, bool)
    41  }
    42  
    43  // ResourceTags returns tags to set on an infrastructure resource
    44  // for the specified Juju environment.
    45  func ResourceTags(e names.EnvironTag, taggers ...ResourceTagger) map[string]string {
    46  	allTags := make(map[string]string)
    47  	for _, tagger := range taggers {
    48  		tags, ok := tagger.ResourceTags()
    49  		if !ok {
    50  			continue
    51  		}
    52  		for k, v := range tags {
    53  			allTags[k] = v
    54  		}
    55  	}
    56  	allTags[JujuEnv] = e.Id()
    57  	return allTags
    58  }