charm

package
v0.0.0-...-4308112 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: AGPL-3.0 Imports: 16 Imported by: 21

Documentation

Index

Constants

View Source
const (
	// DefaultChannelString represents the default track and risk if nothing
	// is found.
	DefaultChannelString = "stable"
)

Variables

View Source
var (
	// DefaultChannel represents the default track and risk.
	DefaultChannel = charm.Channel{
		Risk: charm.Stable,
	}
	// DefaultRiskChannel represents the default only risk channel.
	DefaultRiskChannel = charm.Channel{
		Risk: charm.Stable,
	}
)
View Source
var MissingBaseError = errors.ConstError("charm does not define any bases")

MissingBaseError is used to denote that BaseForCharm could not determine a base because a legacy charm did not declare any.

Functions

func BaseForCharm

func BaseForCharm(requestedBase base.Base, supportedBases []base.Base) (base.Base, error)

BaseForCharm takes a requested base and a list of bases supported by a charm and returns the base which is relevant. If the requested base is empty, then the first supported base is used, otherwise the requested base is validated against the supported bases.

func BaseIsCompatibleWithCharm

func BaseIsCompatibleWithCharm(b base.Base, c charm.CharmMeta) error

BaseIsCompatibleWithCharm returns nil if the provided charm is compatible with the provided base. Otherwise, return an UnsupportedBaseError

func CharmNotFound

func CharmNotFound(url string) error

CharmNotFound returns an error indicating that the charm at the specified URL does not exist.

func ComputedBases

func ComputedBases(c charm.CharmMeta) ([]base.Base, error)

ComputedBases of a charm, preserving legacy behaviour. For charms prior to v2, fall back the metadata series can convert to bases

func InvalidPath

func InvalidPath(path string) error

InvalidPath returns an invalidPathError.

func IsInvalidPathError

func IsInvalidPathError(err error) bool

func IsUnsupportedBaseError

func IsUnsupportedBaseError(err error) bool

IsUnsupportedBaseError returns true if err is an UnsupportedSeriesError.

func MustParseChannel

func MustParseChannel(s string) charm.Channel

MustParseChannel parses a given string or returns a panic.

func NewCharmAtPath

func NewCharmAtPath(path string) (charm.Charm, *charm.URL, error)

NewCharmAtPath returns the charm represented by this path, and a URL that describes it. Deploying from a directory is no longer supported.

func NewCharmInfoAdaptor

func NewCharmInfoAdaptor(meta EssentialMetadata) charmInfoAdaptor

func NewUnsupportedBaseError

func NewUnsupportedBaseError(requestedBase base.Base, supportedBases []base.Base) error

NewUnsupportedBaseError returns an error indicating that the requested series is not supported by a charm.

func OSIsCompatibleWithCharm

func OSIsCompatibleWithCharm(os string, c charm.CharmMeta) error

OSIsCompatibleWithCharm returns nil is any of the bases the charm supports has an os which matched the provided os. Otherwise, return a NotSupported error

Types

type BaseSelector

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

BaseSelector is a helper type that determines what base the charm should be deployed to.

func ConfigureBaseSelector

func ConfigureBaseSelector(cfg SelectorConfig) (BaseSelector, error)

ConfigureBaseSelector returns a configured and validated BaseSelector

func (BaseSelector) CharmBase

func (s BaseSelector) CharmBase() (selectedBase base.Base, err error)

CharmBase determines what base to use with a charm. Order of preference is:

  • user requested with --base or defined by bundle when deploying
  • model default, if set, acts like --base
  • juju's default supported Ubuntu LTS (if compatible with valid charm bases)
  • the first supported base in the charm manifest
  • in the case of local charms with no manifest nor base in metadata, base must be provided by the user.

type CharmArchive

type CharmArchive interface {
	charm.Charm

	Version() string
	LXDProfile() *charm.LXDProfile
}

CharmArchive provides information about a downloaded charm archive.

type CharmID

type CharmID struct {
	// URL is the url of the charm.
	URL *charm.URL

	// Origin holds the original source of a charm, including its channel.
	Origin Origin

	// Metadata is optional extra information about a particular model's
	// "in-theatre" use of the charm.
	Metadata map[string]string
}

CharmID encapsulates data for identifying a unique charm in a charm repository.

type EssentialMetadata

type EssentialMetadata struct {
	ResolvedOrigin Origin

	Meta     *charm.Meta
	Manifest *charm.Manifest
	Config   *charm.Config
}

EssentialMetadata encapsulates the essential metadata required for deploying a particular charm.

type ID

type ID string

ID represents a charm unique identifier.

func NewID

func NewID() (ID, error)

NewID is a convince function for generating a new charm uuid.

func ParseID

func ParseID(value string) (ID, error)

ParseID returns a new ID from the given string. If the string is not a valid uuid an error satisfying errors.NotValid will be returned.

func (ID) String

func (u ID) String() string

String implements the stringer interface for ID.

func (ID) Validate

func (u ID) Validate() error

Validate ensures the consistency of the ID. If the uuid is invalid an error satisfying errors.NotValid will be returned.

type MetadataRequest

type MetadataRequest struct {
	CharmName string
	Origin    Origin
}

MetadataRequest encapsulates the arguments for a charm essential metadata resolution request.

type Origin

type Origin struct {
	Source Source
	Type   string
	ID     string
	Hash   string

	// Users can request a revision to be installed instead of a channel, so
	// we should model that correctly here.
	Revision *int
	Channel  *charm.Channel
	Platform Platform

	// InstanceKey is an optional unique string associated with the application.
	// To assist with keeping KPI data in charmhub, it must be the same for every
	// charmhub Refresh action for the Refresh api endpoint related to an
	// application. For all other actions, a random uuid will used when the request
	// is sent. Create with the charmhub.CreateInstanceKey method. LP: 1944582
	InstanceKey string
}

Origin holds the original source of a charm. Information about where the charm was installed from (charm-hub, local) and any additional information we can utilise when making modelling decisions for upgrading or changing.

func (Origin) String

func (o Origin) String() string

func (Origin) Validate

func (o Origin) Validate() error

Validate returns an error if the origin is invalid.

type Platform

type Platform struct {
	Architecture string
	OS           string
	Channel      string
}

Platform describes the platform used to install the charm with.

func MustParsePlatform

func MustParsePlatform(s string) Platform

MustParsePlatform parses a given string or returns a panic.

func ParsePlatform

func ParsePlatform(s string) (Platform, error)

ParsePlatform parses a string representing a store platform. Serialized version of platform can be expected to conform to the following:

  1. Architecture is mandatory.
  2. OS is optional and can be dropped. Release is mandatory if OS wants to be displayed.
  3. Release is also optional. Release can also optionally include a risk

Examples:

  1. `<arch>/<os>/<channel>`
  2. `<arch>/<os>/<track>/<risk>`
  3. `<arch>`

func ParsePlatformNormalize

func ParsePlatformNormalize(s string) (Platform, error)

ParsePlatformNormalize parses a string presenting a store platform. The returned platform's architecture, os and series are normalized.

func (Platform) Normalize

func (p Platform) Normalize() Platform

Normalize the platform with normalized architecture, os and channel.

func (Platform) String

func (p Platform) String() string

type Repository

type Repository interface {
	// GetDownloadURL returns a url from which a charm can be downloaded
	// based on the given charm url and charm origin.  A charm origin
	// updated with the ID and hash for the download is also returned.
	GetDownloadURL(context.Context, string, Origin) (*url.URL, Origin, error)

	// DownloadCharm retrieves specified charm from the store and saves its
	// contents to the specified path.
	DownloadCharm(ctx context.Context, charmName string, requestedOrigin Origin, archivePath string) (CharmArchive, Origin, *charmhub.Digest, error)

	// ResolveWithPreferredChannel verified that the charm with the requested
	// channel exists.  If no channel is specified, the latests, most stable is
	// used. It returns a charm URL which includes the most current revision,
	// if none was provided, a charm origin, and a slice of series supported by
	// this charm.
	ResolveWithPreferredChannel(context.Context, string, Origin) (*charm.URL, Origin, []Platform, error)

	// GetEssentialMetadata resolves each provided MetadataRequest and
	// returns back a slice with the results. The results include the
	// minimum set of metadata that is required for deploying each charm.
	GetEssentialMetadata(context.Context, ...MetadataRequest) ([]EssentialMetadata, error)

	// ListResources returns a list of resources associated with a given charm.
	ListResources(context.Context, string, Origin) ([]charmresource.Resource, error)

	// ResolveResources looks at the provided repository and backend (already
	// downloaded) resources to determine which to use. Provided (uploaded) take
	// precedence. If charmhub has a newer resource than the back end, use that.
	ResolveResources(ctx context.Context, resources []charmresource.Resource, id CharmID) ([]charmresource.Resource, error)

	// ResolveForDeploy does the same thing as ResolveWithPreferredChannel
	// returning EssentialMetadata also. Resources are returned if a
	// charm revision was not provided in the CharmID.
	ResolveForDeploy(context.Context, CharmID) (ResolvedDataForDeploy, error)
}

Repository describes an API for querying charm/bundle information and downloading them from a store.

type RepositoryFactory

type RepositoryFactory interface {
	GetCharmRepository(ctx context.Context, src Source) (Repository, error)
}

RepositoryFactory is a factory for charm Repositories.

type ResolvedDataForDeploy

type ResolvedDataForDeploy struct {
	URL *charm.URL

	EssentialMetadata EssentialMetadata

	// Resources is a map of resource names to their current repository revision
	// based on the supplied origin
	Resources map[string]charmresource.Resource
}

ResolvedDataForDeploy is the response data from ResolveForDeploy

type SelectorConfig

type SelectorConfig struct {
	Config              SelectorModelConfig
	Force               bool
	Logger              logger.Logger
	RequestedBase       base.Base
	SupportedCharmBases []base.Base
	WorkloadBases       []base.Base
	// usingImageID is true when the user is using the image-id constraint
	// when deploying the charm. This is needed to validate that in that
	// case the user is also explicitly providing a base.
	UsingImageID bool
}

type SelectorModelConfig

type SelectorModelConfig interface {
	// DefaultBase returns the configured default base
	// for the environment, and whether the default base was
	// explicitly configured on the environment.
	DefaultBase() (string, bool)
}

type Source

type Source string

Source represents the source of the charm.

const (
	// Local represents a local charm.
	Local Source = "local"
	// CharmHub represents a charm from the new charmHub.
	CharmHub Source = "charm-hub"
)

func (Source) Matches

func (c Source) Matches(o string) bool

Matches attempts to match a string to a given source.

func (Source) String

func (c Source) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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