lxdprofile

package
v0.0.0-...-8ff1004 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2019 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package lxdprofile defines a set of functions and constants that can interact with LXD Profiles. LXD Profiles are key/value YAML configuration files that the LXD provider and LXD container broker can consume and apply to a container.

More information about a type of LXD configuration profile can found https://github.com/lxc/lxd/blob/master/doc/containers.md

LXDProfile package defines core concepts that can be utilised from different packages of the codebase, that want to work with a LXD profile. Not all key/value configurations from the underlying LXD can be applied and some key/values need to be applied using `--force`. To validate the LXD Profile before attempting to apply it to a ubuntu LXD container, there are some validation functions.

Each LXDProfile is given a unique name when applied to the container. This is for three reasons:

  1. readability - when an operator is attempting to debug if a LXD Profile has been applied for a given charm revision, it should be straightforward for the operator to read the output of `lxd profile list` to marry them.
  2. Collisions - to ensure that no other charm profile can't collide with in the LXC namespace for an existing LXD Profile, each profile namespaces in the following way `juju-<model>-<application>-<charm-revision>`
  3. Removability - juju needs to clean up LXD profiles that where applied to the LXD container, but are subsequently not required any more, either by an upgrade of the charm or the complete removal of the charm. Either way, the removal of the charms from the LXC profile list is to prevent orphan profiles from being left dangling.

Index

Constants

View Source
const (
	// EmptyStatus represents the initial status
	EmptyStatus = ""

	// SuccessStatus defines if the lxd profile upgrade was a success
	SuccessStatus = "Success"

	// NotRequiredStatus defines when the lxd profile upgrade was not required
	NotRequiredStatus = "Not Required"

	// NotKnownStatus defines a state where the document for the lxd profile
	// is removed, or never existed, but we don't know what the status should be.
	NotKnownStatus = "Not known"

	// ErrorStatus defines when the lxd profile is in an error state
	ErrorStatus = "Error"

	// NotSupportedStatus defines when a machine does not support lxd profiles.
	NotSupportedStatus = "Not Supported"
)
View Source
const AppName = "juju"

AppName here is used as the application prefix name. We can't use names.Juju as that changes depending on platform.

Variables

View Source
var Prefix = fmt.Sprintf("%s-", AppName)

Prefix is used to prefix all the lxd profile programmable profiles. If a profile doesn't have the prefix, then it will be removed when ensuring the the validity of the names (see LXDProfileNames)

Functions

func AnnotateErrorStatus

func AnnotateErrorStatus(err error) string

AnnotateErrorStatus annotates an existing error with the correct status

func IsValidName

func IsValidName(name string) bool

IsValidName returns if the name of the lxd profile looks valid.

func LXDProfileNames

func LXDProfileNames(names []string) []string

LXDProfileNames ensures that the LXD profile names are unique yet preserve the same order as the input. It removes certain profile names from the list, for example "default" profile name will be removed.

func MatchProfileNameByAppName

func MatchProfileNameByAppName(names []string, appName string) (string, error)

MatchProfileNameByApp returns the first profile which matches the provided appName. No match returns an empty string. Assumes there is not more than one profile for the same application.

func Name

func Name(modelName, appName string, revision int) string

Name returns a serialisable name that we can use to identify profiles juju-<model>-<application>-<charm-revision>

func ProfileReplaceRevision

func ProfileReplaceRevision(profile string, rev int) (string, error)

ProfileReplaceRevision replaces the old revision with a new revision in the profile.

func ProfileRevision

func ProfileRevision(profile string) (int, error)

ProfileRevision returns an int which is the charm revision of the given profile name.

func UpgradeStatusErrorred

func UpgradeStatusErrorred(status string) bool

UpgradeStatusErrorred defines if the status is in a error state.

func UpgradeStatusFinished

func UpgradeStatusFinished(status string) bool

UpgradeStatusFinished defines if the upgrade has completed

func UpgradeStatusTerminal

func UpgradeStatusTerminal(status string) bool

UpgradeStatusTerminal defines if the status is in a terminal state. Success or not required is also considered terminal.

func ValidateCharmInfoLXDProfile

func ValidateCharmInfoLXDProfile(info *apicharms.CharmInfo) error

ValidateCharmInfoLXDProfile will validate the charm info to determin if the information provided is valid or not.

func ValidateCharmLXDProfile

func ValidateCharmLXDProfile(ch charm.Charm) error

ValidateCharmLXDProfile will attempt to validate a charm.Charm lxd profile. The LXDProfile is an optional method on the charm.Charm, so testing to check that it conforms to a LXDProfiler first is required. Failure to conform to the LXDProfiler will return no error.

func ValidateLXDProfile

func ValidateLXDProfile(profiler charm.LXDProfiler) error

ValidateLXDProfile will validate the profile to determin if the configuration is valid or not before passing continuing on.

Types

This section is empty.

Jump to

Keyboard shortcuts

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