import "github.com/juju/names"
action.go charm.go environ.go filesystem.go ipaddress.go machine.go model.go payload.go relation.go service.go space.go storage.go subnet.go tag.go unit.go user.go volume.go
const (
ContainerTypeSnippet = "[a-z]+"
ContainerSnippet = "/" + ContainerTypeSnippet + "/" + NumberSnippet + ""
MachineSnippet = NumberSnippet + "(?:" + ContainerSnippet + ")*"
)const (
ServiceSnippet = "(?:[a-z][a-z0-9]*(?:-[a-z0-9]*[a-z][a-z0-9]*)*)"
NumberSnippet = "(?:0|[1-9][0-9]*)"
)const (
SpaceTagKind = "space"
SpaceSnippet = "(?:[a-z0-9]+(?:-[a-z0-9]+)*)"
)const (
StorageTagKind = "storage"
// StorageNameSnippet is the regular expression that describes valid
// storage names (without the storage instance sequence number).
StorageNameSnippet = "(?:[a-z][a-z0-9]*(?:-[a-z0-9]*[a-z][a-z0-9]*)*)"
)const (
UserTagKind = "user"
LocalUserDomain = "local"
)const ActionTagKind = "action"const CharmTagKind = "charm"CharmTagKind specifies charm tag kind
const EnvironTagKind = "environment"EnvironTagKind is DEPRECATED: model tags are used instead.
const FilesystemTagKind = "filesystem"const IPAddressTagKind = "ipaddress"const MachineTagKind = "machine"const ModelTagKind = "model"const (
// PayloadTagKind is used as the prefix for the string
// representation of payload tags.
PayloadTagKind = "payload"
)const RelationSnippet = "[a-z][a-z0-9]*(?:[_-][a-z0-9]+)*"const RelationTagKind = "relation"const ServiceTagKind = "service"const SubnetTagKind = "subnet"const UnitTagKind = "unit"const VolumeTagKind = "volume"var (
// SeriesSnippet is a regular expression representing series
SeriesSnippet = "[a-z]+([a-z0-9]+)?"
// CharmNameSnippet is a regular expression representing charm name
CharmNameSnippet = "[a-z][a-z0-9]*(-[a-z0-9]*[a-z][a-z0-9]*)*"
)IsContainerMachine returns whether id is a valid container machine id.
IsValidAction returns whether id is a valid action id (UUID).
IsValidCharm returns whether name is a valid charm url.
IsValidEnvironment returns whether id is a valid environment UUID.
IsValidFilesystem returns whether id is a valid filesystem id.
IsValidIPAddress returns whether id is a valid IP address ID. Here it simply is checked if it is a valid UUID.
IsValidMachine returns whether id is a valid machine id.
IsValidModel returns whether id is a valid model UUID.
IsValidModelName returns whether name is a valid string safe for a model name.
IsValidPayload returns whether id is a valid Juju ID for a charm payload. The ID must be a valid alpha-numeric (plus hyphens).
IsValidRelation returns whether key is a valid relation key.
IsValidService returns whether name is a valid service name.
IsValidSpace reports whether name is a valid space name.
IsValidStorage returns whether id is a valid storage instance ID.
IsValidSubnet returns whether cidr is a valid subnet CIDR.
IsValidUnit returns whether name is a valid unit name.
IsValidUser returns whether id is a valid user id. Valid users may or may not be qualified with an @domain suffix. Examples of valid users include bob, bob@local, bob@somewhere-else, 0-a-f@123.
IsValidUserDomain returns whether the given user domain is valid.
IsValidUserName returns whether the given name is a valid name part of a user. That is, usernames with a domain suffix will return false.
IsValidVolume returns whether id is a valid volume ID.
ReadableString returns a human-readable string from the tag passed in. It currently supports unit and machine tags. Support for additional types can be added in as needed.
StorageName returns the storage name from a storage instance ID. StorageName returns an error if "id" is not a valid storage instance ID.
TagKind returns one of the *TagKind constants for the given tag, or an error if none matches.
UnitService returns the name of the service that the unit is associated with. It returns an error if unitName is not a valid unit name.
NewActionTag returns the tag of an action with the given id (UUID).
ParseActionTag parses an action tag string.
type CharmTag struct {
// contains filtered or unexported fields
}CharmTag represents tag for charm using charm's URL
NewCharmTag returns the tag for the charm with the given url. It will panic if the given charm url is not valid.
ParseCharmTag parses a charm tag string.
Id satisfies Tag interface. Returns charm URL.
Kind satisfies Tag interface. Returns Charm tag kind.
String satisfies Tag interface. Produces string representation of charm tag.
type EnvironTag struct {
// contains filtered or unexported fields
}func NewEnvironTag(uuid string) EnvironTag
NewEnvironTag returns the tag of an environment with the given environment UUID.
func ParseEnvironTag(environTag string) (EnvironTag, error)
ParseEnvironTag parses an environ tag string.
func (t EnvironTag) Id() string
func (t EnvironTag) Kind() string
func (t EnvironTag) String() string
type FilesystemTag struct {
// contains filtered or unexported fields
}func NewFilesystemTag(id string) FilesystemTag
NewFilesystemTag returns the tag for the filesystem with the given name. It will panic if the given filesystem name is not valid.
func ParseFilesystemTag(filesystemTag string) (FilesystemTag, error)
ParseFilesystemTag parses a filesystem tag string.
func (t FilesystemTag) Id() string
func (t FilesystemTag) Kind() string
func (t FilesystemTag) String() string
type IPAddressTag struct {
// contains filtered or unexported fields
}func NewIPAddressTag(id string) IPAddressTag
NewIPAddressTag returns the tag for the IP address with the given ID (UUID).
func ParseIPAddressTag(ipAddressTag string) (IPAddressTag, error)
ParseIPAddressTag parses an IP address tag string.
func (t IPAddressTag) Id() string
func (t IPAddressTag) Kind() string
func (t IPAddressTag) String() string
type MachineTag struct {
// contains filtered or unexported fields
}func FilesystemMachine(tag FilesystemTag) (MachineTag, bool)
FilesystemMachine returns the machine component of the filesystem tag, and a boolean indicating whether or not there is a machine component.
func NewMachineTag(id string) MachineTag
NewMachineTag returns the tag for the machine with the given id.
func ParseMachineTag(machineTag string) (MachineTag, error)
ParseMachineTag parses a machine tag string.
func VolumeMachine(tag VolumeTag) (MachineTag, bool)
VolumeMachine returns the machine component of the volume tag, and a boolean indicating whether or not there is a machine component.
func (t MachineTag) Id() string
func (t MachineTag) Kind() string
func (t MachineTag) String() string
type ModelTag struct {
// contains filtered or unexported fields
}ModelTag represents a tag used to describe a model.
NewModelTag returns the tag of an model with the given model UUID.
ParseModelTag parses an environ tag string.
type PayloadTag struct {
// contains filtered or unexported fields
}PayloadTag represents a charm payload.
func NewPayloadTag(id string) PayloadTag
NewPayloadTag returns the tag for a charm's payload with the given id.
func ParsePayloadTag(tag string) (PayloadTag, error)
ParsePayloadTag parses a payload tag string. So ParsePayloadTag(tag.String()) === tag.
func (t PayloadTag) Id() string
Id implements Tag.Id. It always returns the same ID with which it was created. So NewPayloadTag(x).Id() == x for all valid x.
func (t PayloadTag) Kind() string
Kind implements Tag.
func (t PayloadTag) String() string
String implements Tag.
type RelationTag struct {
// contains filtered or unexported fields
}func NewRelationTag(relationKey string) RelationTag
NewRelationTag returns the tag for the relation with the given key.
func ParseRelationTag(relationTag string) (RelationTag, error)
ParseRelationTag parses a relation tag string.
func (t RelationTag) Id() string
func (t RelationTag) Kind() string
func (t RelationTag) String() string
func NewServiceTag(serviceName string) ServiceTag
NewServiceTag returns the tag for the service with the given name.
func ParseServiceTag(serviceTag string) (ServiceTag, error)
ParseServiceTag parses a service tag string.
func (t ServiceTag) Id() string
func (t ServiceTag) Kind() string
func (t ServiceTag) String() string
type SpaceTag struct {
// contains filtered or unexported fields
}NewSpaceTag returns the tag of a space with the given name.
ParseSpaceTag parses a space tag string.
type StorageTag struct {
// contains filtered or unexported fields
}func NewStorageTag(id string) StorageTag
NewStorageTag returns the tag for the storage instance with the given ID. It will panic if the given string is not a valid storage instance Id.
func ParseStorageTag(s string) (StorageTag, error)
ParseStorageTag parses a storage tag string.
func (t StorageTag) Id() string
func (t StorageTag) Kind() string
func (t StorageTag) String() string
type SubnetTag struct {
// contains filtered or unexported fields
}NewSubnetTag returns the tag for subnet with the given CIDR.
ParseSubnetTag parses a subnet tag string.
type Tag interface {
// Kind returns the kind of the tag.
// This method is for legacy compatibility, callers should
// use equality or type assertions to verify the Kind, or type
// of a Tag.
Kind() string
// Id returns an identifier for this Tag.
// The contents and format of the identifier are specific
// to the implementer of the Tag.
Id() string
fmt.Stringer // all Tags should be able to print themselves
}A Tag tags things that are taggable. Its purpose is to uniquely identify some resource and provide a consistent representation of that identity in both a human-readable and a machine-friendly format. The latter benefits use of the tag in over-the-wire transmission (e.g. in HTTP RPC calls) and in filename paths. The human-readable tag "name" is available through the Id method. The machine-friendly representation is provided by the String method.
The ParseTag function may be used to build a tag from the machine- formatted string. As well each kind of tag has its own Parse* method. Each kind also has a New* method (e.g. NewMachineTag) which produces a tag from the human-readable tag "ID".
In the context of juju, the API *must* use tags to represent the various juju entities. This contrasts with user-facing code, where tags *must not* be used. Internal to juju the use of tags is a judgement call based on the situation.
ActionReceiverFrom Tag returns an ActionReceiver tag from a machine or unit tag.
ActionReceiverTag returns an ActionReceiver Tag from a machine or unit name.
ParseTag parses a string representation into a Tag.
Code:
tag, err := ParseTag("user-100")
if err != nil {
panic(err)
}
switch tag := tag.(type) {
case UserTag:
fmt.Printf("User tag, id: %s\n", tag.Id())
default:
fmt.Printf("Unknown tag, type %T\n", tag)
}
type UnitTag struct {
// contains filtered or unexported fields
}NewUnitTag returns the tag for the unit with the given name. It will panic if the given unit name is not valid.
In almost all cases it is more desirable to call NewUnitTagFromName which returns errors instead of panicing.
NewUnitTag returns the tag for the unit with the given name. It will return an error if the given unit name is not valid.
ParseUnitTag parses a unit tag string.
type UserTag struct {
// contains filtered or unexported fields
}UserTag represents a user that may be stored locally or associated with some external domain.
NewLocalUserTag returns the tag for a local user with the given name.
NewUserTag returns the tag for the user with the given name. It panics if the user name does not satisfy IsValidUser.
ParseUserTag parses a user tag string.
Canonical returns the user name and its domain in canonical form. Specifically, user tags in the local domain will always return an @local prefix, regardless of the id the user was created with. This is the only difference from the Id method.
Domain returns the user domain. Users in the local database are from the LocalDomain. Other users are considered 'remote' users.
Id implements Tag.Id. It always returns the same id that it was created with, so NewUserTag(x).Id() == x for all valid users x. This means that local users might or might not have an @local domain in their id.
IsLocal returns true if the tag represents a local user.
Name returns the name part of the user name without its associated domain.
WithDomain returns a copy of the user tag with the domain changed to the given argument. The domain must satisfy IsValidUserDomain or this function will panic.
type VolumeTag struct {
// contains filtered or unexported fields
}NewVolumeTag returns the tag for the volume with the given ID. It will panic if the given volume ID is not valid.
ParseVolumeTag parses a volume tag string.
Package names imports 6 packages (graph) and is imported by 2460 packages. Updated 2016-09-07. Refresh now. Tools for package owners.