names

package module
Version: v0.0.0-...-8a0aa09 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2016 License: LGPL-3.0 Imports: 6 Imported by: 775

README

juju/names

This package provides helpers for handling Juju entity names.

Documentation

Index

Examples

Constants

View Source
const (
	ContainerTypeSnippet = "[a-z]+"
	ContainerSnippet     = "/" + ContainerTypeSnippet + "/" + NumberSnippet + ""
	MachineSnippet       = NumberSnippet + "(?:" + ContainerSnippet + ")*"
)
View Source
const (
	ServiceSnippet = "(?:[a-z][a-z0-9]*(?:-[a-z0-9]*[a-z][a-z0-9]*)*)"
	NumberSnippet  = "(?:0|[1-9][0-9]*)"
)
View Source
const (
	SpaceTagKind = "space"
	SpaceSnippet = "(?:[a-z0-9]+(?:-[a-z0-9]+)*)"
)
View Source
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]*)*)"
)
View Source
const (
	UserTagKind     = "user"
	LocalUserDomain = "local"
)
View Source
const ActionTagKind = "action"
View Source
const CharmTagKind = "charm"

CharmTagKind specifies charm tag kind

View Source
const EnvironTagKind = "environment"

EnvironTagKind is DEPRECATED: model tags are used instead.

View Source
const FilesystemTagKind = "filesystem"
View Source
const IPAddressTagKind = "ipaddress"
View Source
const MachineTagKind = "machine"
View Source
const ModelTagKind = "model"
View Source
const (
	NetworkSnippet = "(?:[a-zA-Z0-9_-]+)"
)
View Source
const NetworkTagKind = "network"
View Source
const (
	// PayloadTagKind is used as the prefix for the string
	// representation of payload tags.
	PayloadTagKind = "payload"
)
View Source
const RelationSnippet = "[a-z][a-z0-9]*(?:[_-][a-z0-9]+)*"
View Source
const RelationTagKind = "relation"
View Source
const ServiceTagKind = "service"
View Source
const SubnetTagKind = "subnet"
View Source
const UnitTagKind = "unit"
View Source
const VolumeTagKind = "volume"

Variables

View Source
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]*)*"
)

Functions

func IsContainerMachine

func IsContainerMachine(id string) bool

IsContainerMachine returns whether id is a valid container machine id.

func IsValidAction

func IsValidAction(id string) bool

IsValidAction returns whether id is a valid action id (UUID).

func IsValidCharm

func IsValidCharm(url string) bool

IsValidCharm returns whether name is a valid charm url.

func IsValidEnvironment

func IsValidEnvironment(id string) bool

IsValidEnvironment returns whether id is a valid environment UUID.

func IsValidFilesystem

func IsValidFilesystem(id string) bool

IsValidFilesystem returns whether id is a valid filesystem id.

func IsValidIPAddress

func IsValidIPAddress(id string) bool

IsValidIPAddress returns whether id is a valid IP address ID. Here it simply is checked if it is a valid UUID.

func IsValidMachine

func IsValidMachine(id string) bool

IsValidMachine returns whether id is a valid machine id.

func IsValidModel

func IsValidModel(id string) bool

IsValidModel returns whether id is a valid model UUID.

func IsValidNetwork

func IsValidNetwork(name string) bool

IsValidNetwork reports whether name is a valid network name.

func IsValidPayload

func IsValidPayload(id string) bool

IsValidPayload returns whether id is a valid Juju ID for a charm payload. The ID must be a valid UUID.

func IsValidRelation

func IsValidRelation(key string) bool

IsValidRelation returns whether key is a valid relation key.

func IsValidService

func IsValidService(name string) bool

IsValidService returns whether name is a valid service name.

func IsValidSpace

func IsValidSpace(name string) bool

IsValidSpace reports whether name is a valid space name.

func IsValidStorage

func IsValidStorage(id string) bool

IsValidStorage returns whether id is a valid storage instance ID.

func IsValidSubnet

func IsValidSubnet(cidr string) bool

IsValidSubnet returns whether cidr is a valid subnet CIDR.

func IsValidUnit

func IsValidUnit(name string) bool

IsValidUnit returns whether name is a valid unit name.

func IsValidUser

func IsValidUser(id string) bool

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.

func IsValidUserDomain

func IsValidUserDomain(domain string) bool

IsValidUserDomain returns whether the given user domain is valid.

func IsValidUserName

func IsValidUserName(name string) bool

IsValidUserName returns whether the given name is a valid name part of a user. That is, usernames with a domain suffix will return false.

func IsValidVolume

func IsValidVolume(id string) bool

IsValidVolume returns whether id is a valid volume ID.

func ReadableString

func ReadableString(tag Tag) string

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.

func StorageName

func StorageName(id string) (string, error)

StorageName returns the storage name from a storage instance ID. StorageName returns an error if "id" is not a valid storage instance ID.

func TagKind

func TagKind(tag string) (string, error)

TagKind returns one of the *TagKind constants for the given tag, or an error if none matches.

func UnitService

func UnitService(unitName string) (string, error)

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.

Types

type ActionTag

type ActionTag struct {
	// Tags that are serialized need to have fields exported.
	ID utils.UUID
}

func NewActionTag

func NewActionTag(id string) ActionTag

NewActionTag returns the tag of an action with the given id (UUID).

func ParseActionTag

func ParseActionTag(actionTag string) (ActionTag, error)

ParseActionTag parses an action tag string.

func (ActionTag) Id

func (t ActionTag) Id() string

func (ActionTag) Kind

func (t ActionTag) Kind() string

func (ActionTag) String

func (t ActionTag) String() string

type CharmTag

type CharmTag struct {
	// contains filtered or unexported fields
}

CharmTag represents tag for charm using charm's URL

func NewCharmTag

func NewCharmTag(charmURL string) CharmTag

NewCharmTag returns the tag for the charm with the given url. It will panic if the given charm url is not valid.

func ParseCharmTag

func ParseCharmTag(charmTag string) (CharmTag, error)

ParseCharmTag parses a charm tag string.

func (CharmTag) Id

func (t CharmTag) Id() string

Id satisfies Tag interface. Returns charm URL.

func (CharmTag) Kind

func (t CharmTag) Kind() string

Kind satisfies Tag interface. Returns Charm tag kind.

func (CharmTag) String

func (t CharmTag) String() string

String satisfies Tag interface. Produces string representation of charm tag.

type EnvironTag

type EnvironTag struct {
	// contains filtered or unexported fields
}

func NewEnvironTag

func NewEnvironTag(uuid string) EnvironTag

NewEnvironTag returns the tag of an environment with the given environment UUID.

func ParseEnvironTag

func ParseEnvironTag(environTag string) (EnvironTag, error)

ParseEnvironTag parses an environ tag string.

func (EnvironTag) Id

func (t EnvironTag) Id() string

func (EnvironTag) Kind

func (t EnvironTag) Kind() string

func (EnvironTag) String

func (t EnvironTag) String() string

type FilesystemTag

type FilesystemTag struct {
	// contains filtered or unexported fields
}

func NewFilesystemTag

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

func ParseFilesystemTag(filesystemTag string) (FilesystemTag, error)

ParseFilesystemTag parses a filesystem tag string.

func (FilesystemTag) Id

func (t FilesystemTag) Id() string

func (FilesystemTag) Kind

func (t FilesystemTag) Kind() string

func (FilesystemTag) String

func (t FilesystemTag) String() string

type IPAddressTag

type IPAddressTag struct {
	// contains filtered or unexported fields
}

func NewIPAddressTag

func NewIPAddressTag(id string) IPAddressTag

NewIPAddressTag returns the tag for the IP address with the given ID (UUID).

func ParseIPAddressTag

func ParseIPAddressTag(ipAddressTag string) (IPAddressTag, error)

ParseIPAddressTag parses an IP address tag string.

func (IPAddressTag) Id

func (t IPAddressTag) Id() string

func (IPAddressTag) Kind

func (t IPAddressTag) Kind() string

func (IPAddressTag) String

func (t IPAddressTag) String() string

type MachineTag

type MachineTag struct {
	// contains filtered or unexported fields
}

func FilesystemMachine

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

func NewMachineTag(id string) MachineTag

NewMachineTag returns the tag for the machine with the given id.

func ParseMachineTag

func ParseMachineTag(machineTag string) (MachineTag, error)

ParseMachineTag parses a machine tag string.

func VolumeMachine

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 (MachineTag) Id

func (t MachineTag) Id() string

func (MachineTag) Kind

func (t MachineTag) Kind() string

func (MachineTag) String

func (t MachineTag) String() string

type ModelTag

type ModelTag struct {
	// contains filtered or unexported fields
}

ModelTag represents a tag used to describe a model.

func NewModelTag

func NewModelTag(uuid string) ModelTag

NewModelTag returns the tag of an model with the given model UUID.

func ParseModelTag

func ParseModelTag(modelTag string) (ModelTag, error)

ParseModelTag parses an environ tag string.

func (ModelTag) Id

func (t ModelTag) Id() string

func (ModelTag) Kind

func (t ModelTag) Kind() string

func (ModelTag) String

func (t ModelTag) String() string

type NetworkTag

type NetworkTag struct {
	// contains filtered or unexported fields
}

func NewNetworkTag

func NewNetworkTag(name string) NetworkTag

NewNetworkTag returns the tag of a network with the given name.

func ParseNetworkTag

func ParseNetworkTag(networkTag string) (NetworkTag, error)

ParseNetworkTag parses a network tag string.

func (NetworkTag) Id

func (t NetworkTag) Id() string

func (NetworkTag) Kind

func (t NetworkTag) Kind() string

func (NetworkTag) String

func (t NetworkTag) String() string

type PayloadTag

type PayloadTag struct {
	// contains filtered or unexported fields
}

PayloadTag represents a charm payload.

func NewPayloadTag

func NewPayloadTag(id string) PayloadTag

NewPayloadTag returns the tag for a charm's payload with the given id.

func ParsePayloadTag

func ParsePayloadTag(tag string) (PayloadTag, error)

ParsePayloadTag parses a payload tag string. So ParsePayloadTag(tag.String()) === tag.

func (PayloadTag) Id

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 (PayloadTag) Kind

func (t PayloadTag) Kind() string

Kind implements Tag.

func (PayloadTag) String

func (t PayloadTag) String() string

String implements Tag.

type RelationTag

type RelationTag struct {
	// contains filtered or unexported fields
}

func NewRelationTag

func NewRelationTag(relationKey string) RelationTag

NewRelationTag returns the tag for the relation with the given key.

func ParseRelationTag

func ParseRelationTag(relationTag string) (RelationTag, error)

ParseRelationTag parses a relation tag string.

func (RelationTag) Id

func (t RelationTag) Id() string

func (RelationTag) Kind

func (t RelationTag) Kind() string

func (RelationTag) String

func (t RelationTag) String() string

type ServiceTag

type ServiceTag struct {
	Name string
}

func NewServiceTag

func NewServiceTag(serviceName string) ServiceTag

NewServiceTag returns the tag for the service with the given name.

func ParseServiceTag

func ParseServiceTag(serviceTag string) (ServiceTag, error)

ParseServiceTag parses a service tag string.

func (ServiceTag) Id

func (t ServiceTag) Id() string

func (ServiceTag) Kind

func (t ServiceTag) Kind() string

func (ServiceTag) String

func (t ServiceTag) String() string

type SpaceTag

type SpaceTag struct {
	// contains filtered or unexported fields
}

func NewSpaceTag

func NewSpaceTag(name string) SpaceTag

NewSpaceTag returns the tag of a space with the given name.

func ParseSpaceTag

func ParseSpaceTag(spaceTag string) (SpaceTag, error)

ParseSpaceTag parses a space tag string.

func (SpaceTag) Id

func (t SpaceTag) Id() string

func (SpaceTag) Kind

func (t SpaceTag) Kind() string

func (SpaceTag) String

func (t SpaceTag) String() string

type StorageTag

type StorageTag struct {
	// contains filtered or unexported fields
}

func NewStorageTag

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

func ParseStorageTag(s string) (StorageTag, error)

ParseStorageTag parses a storage tag string.

func (StorageTag) Id

func (t StorageTag) Id() string

func (StorageTag) Kind

func (t StorageTag) Kind() string

func (StorageTag) String

func (t StorageTag) String() string

type SubnetTag

type SubnetTag struct {
	// contains filtered or unexported fields
}

func NewSubnetTag

func NewSubnetTag(cidr string) SubnetTag

NewSubnetTag returns the tag for subnet with the given CIDR.

func ParseSubnetTag

func ParseSubnetTag(subnetTag string) (SubnetTag, error)

ParseSubnetTag parses a subnet tag string.

func (SubnetTag) Id

func (t SubnetTag) Id() string

func (SubnetTag) Kind

func (t SubnetTag) Kind() string

func (SubnetTag) String

func (t SubnetTag) String() string

type Tag

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.

func ActionReceiverFromTag

func ActionReceiverFromTag(tag string) (Tag, error)

ActionReceiverFrom Tag returns an ActionReceiver tag from a machine or unit tag.

func ActionReceiverTag

func ActionReceiverTag(name string) (Tag, error)

ActionReceiverTag returns an ActionReceiver Tag from a machine or unit name.

func ParseTag

func ParseTag(tag string) (Tag, error)

ParseTag parses a string representation into a Tag.

Example
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)
}
Output:

type UnitTag

type UnitTag struct {
	// contains filtered or unexported fields
}

func NewUnitTag

func NewUnitTag(unitName string) UnitTag

NewUnitTag returns the tag for the unit with the given name. It will panic if the given unit name is not valid.

func ParseUnitTag

func ParseUnitTag(unitTag string) (UnitTag, error)

ParseUnitTag parses a unit tag string.

func (UnitTag) Id

func (t UnitTag) Id() string

func (UnitTag) Kind

func (t UnitTag) Kind() string

func (UnitTag) String

func (t UnitTag) String() string

type UserTag

type UserTag struct {
	// contains filtered or unexported fields
}

UserTag represents a user that may be stored locally or associated with some external domain.

func NewLocalUserTag

func NewLocalUserTag(name string) UserTag

NewLocalUserTag returns the tag for a local user with the given name.

func NewUserTag

func NewUserTag(userName string) UserTag

NewUserTag returns the tag for the user with the given name. It panics if the user name does not satisfy IsValidUser.

func ParseUserTag

func ParseUserTag(tag string) (UserTag, error)

ParseUserTag parses a user tag string.

func (UserTag) Canonical

func (t UserTag) Canonical() 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.

func (UserTag) Domain

func (t UserTag) Domain() string

Domain returns the user domain. Users in the local database are from the LocalDomain. Other users are considered 'remote' users.

func (UserTag) Id

func (t UserTag) Id() string

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.

func (UserTag) IsLocal

func (t UserTag) IsLocal() bool

IsLocal returns true if the tag represents a local user.

func (UserTag) Kind

func (t UserTag) Kind() string

func (UserTag) Name

func (t UserTag) Name() string

Name returns the name part of the user name without its associated domain.

func (UserTag) String

func (t UserTag) String() string

func (UserTag) WithDomain

func (t UserTag) WithDomain(domain string) UserTag

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

type VolumeTag struct {
	// contains filtered or unexported fields
}

func NewVolumeTag

func NewVolumeTag(id string) VolumeTag

NewVolumeTag returns the tag for the volume with the given ID. It will panic if the given volume ID is not valid.

func ParseVolumeTag

func ParseVolumeTag(volumeTag string) (VolumeTag, error)

ParseVolumeTag parses a volume tag string.

func (VolumeTag) Id

func (t VolumeTag) Id() string

func (VolumeTag) Kind

func (t VolumeTag) Kind() string

func (VolumeTag) String

func (t VolumeTag) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL