charm

package module
v13.1.1 Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: LGPL-3.0 Imports: 43 Imported by: 74

README

Juju charms

This package parses juju charms.

Anatomy of a charm

A bare minimum charm consists of a directory containing a series of files and directories that inform Juju how to correctly handle and execute a charm.

The charming docs provide more advanced information and tutorials. The following is a very simple basic configuration guide.

metadata.yaml

The metadata.yaml is a required charm configuration yaml. It is expected that every charm contains a metadata.yaml.

An example of a very basic metadata.yaml:

name: example
summary: Example charm
description: |
    A contrived descriptive example of a charm
    description that has multiple line.
tags:
    - example
    - misc
series:
    - focal
    - bionic
config.yaml

config.yaml is an optional configuration yaml for a charm. The configuration allows the author to express a series of options for the user to configure the modelled charm software.

An example of a config.yaml:

options:
    name:
        default:
        description: The name of the example software
        type: string

It is expected that for every configuration option, there is a name and a type. All the other fields are optional.

The type can be either a string, int, float or boolean. Everything else will cause Juju to error out when reading the charm.

revision

The revision is used to indicate the revision of a charm. It expects that only an integer exists in that file.

lxd-profile.yaml

The lxd-profile.yaml is an optional configuration yaml. It allows the author of the charm to configure a series of LXD containers directly from the charm.

An example of a lxd-profile.yaml:

config:
  security.nesting: "true"
  security.privileged: "true"
  linux.kernel_modules: openvswitch,nbd,ip_tables,ip6_tables
devices:
  kvm:
    path: /dev/kvm
    type: unix-char
  mem:
    path: /dev/mem
    type: unix-char
  tun:
    path: /dev/net/tun
    type: unix-char
version

The version file is used to indicate the exact version of a charm. Useful for identifying the exact revision of a charm.

Documentation

Overview

Copyright 2019 Canonical Ltd. Licensed under the AGPLv3, see LICENCE file for details.

Index

Constants

This section is empty.

Variables

View Source
var Risks = []Risk{
	Stable,
	Candidate,
	Beta,
	Edge,
}

Risks is a list of the available channel risks.

Functions

func CheckMeta

func CheckMeta(ch CharmMeta) error

CheckMeta determines the version of the metadata used by this charm, then checks that it is valid as appropriate.

func EnsureSchema

func EnsureSchema(url string, defaultSchema Schema) (string, error)

EnsureSchema will ensure that the scheme for a given URL is correct and valid. If the url does not specify a schema, the provided defaultSchema will be injected to it.

func GetActionNameRule

func GetActionNameRule() *regexp.Regexp

Export `actionNameRule` variable to different contexts.

func IsCharmDir

func IsCharmDir(path string) bool

IsCharmDir report whether the path is likely to represent a charm, even it may be incomplete.

func IsMissingSeriesError

func IsMissingSeriesError(err error) bool

IsMissingSeriesError returns true if err is an errMissingSeries.

func IsUnsupportedSeriesError

func IsUnsupportedSeriesError(err error) bool

IsUnsupportedSeriesError returns true if err is an UnsupportedSeriesError.

func IsValidArchitecture

func IsValidArchitecture(architecture string) bool

IsValidArchitecture reports whether the architecture is a valid architecture in charm or bundle URLs.

func IsValidLocalCharmOrBundlePath

func IsValidLocalCharmOrBundlePath(path string) bool

IsValidLocalCharmOrBundlePath returns true if path is valid for reading a local charm or bundle.

func IsValidName

func IsValidName(name string) bool

IsValidName reports whether name is a valid charm or bundle name.

func IsValidOfferURL

func IsValidOfferURL(urlStr string) bool

IsValidOfferURL ensures that a URL string is a valid OfferURL.

func IsValidSeries

func IsValidSeries(series string) bool

IsValidSeries reports whether series is a valid series in charm or bundle URLs.

func MakeURL

func MakeURL(user, model, application, controller string) string

MakeURL constructs an offer URL from the specified components.

func MetaFormatReasons

func MetaFormatReasons(ch CharmMeta) (Format, []FormatSelectionReason)

MetaFormatReasons returns the format and why the selection was done. We can then inspect the reasons to understand the reasoning.

func NewUnsupportedSeriesError

func NewUnsupportedSeriesError(requestedSeries string, supportedSeries []string) error

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

func Quote

func Quote(unsafe string) string

Quote translates a charm url string into one which can be safely used in a file path. ASCII letters, ASCII digits, dot and dash stay the same; other characters are translated to their hex representation surrounded by underscores.

func ReadVersion

func ReadVersion(r io.Reader) (string, error)

ReadVersion extracts the VCS version from a charm's version file.

func SeriesForCharm

func SeriesForCharm(requestedSeries string, supportedSeries []string) (string, error)

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

func ValidateArchitecture

func ValidateArchitecture(arch string) error

ValidateArchitecture returns an error if the given architecture is invalid.

func ValidateName

func ValidateName(name string) error

ValidateName returns an error if the given name is invalid.

func ValidateSchema

func ValidateSchema(schema string) error

func ValidateSeries

func ValidateSeries(series string) error

ValidateSeries returns an error if the given series is invalid.

func VerifyNoOverlayFieldsPresent

func VerifyNoOverlayFieldsPresent(bd *BundleData) error

VerifyNoOverlayFieldsPresent scans the contents of bd and returns an error if the bundle contains any overlay-specific values.

Types

type ActionSpec

type ActionSpec struct {
	Description    string
	Parallel       bool
	ExecutionGroup string
	Params         map[string]interface{}
}

ActionSpec is a definition of the parameters and traits of an Action. The Params map is expected to conform to JSON-Schema Draft 4 as defined at http://json-schema.org/draft-04/schema# (see http://json-schema.org/latest/json-schema-core.html)

func (*ActionSpec) InsertDefaults

func (spec *ActionSpec) InsertDefaults(target map[string]interface{}) (map[string]interface{}, error)

InsertDefaults inserts the schema's default values in target using github.com/juju/gojsonschema. If a nil target is received, an empty map will be created as the target. The target is then mutated to include the defaults.

The returned map will be the transformed or created target map.

func (*ActionSpec) ValidateParams

func (spec *ActionSpec) ValidateParams(params map[string]interface{}) error

ValidateParams validates the passed params map against the given ActionSpec and returns any error encountered. Usage:

err := ch.Actions().ActionSpecs["snapshot"].ValidateParams(someMap)

type Actions

type Actions struct {
	ActionSpecs map[string]ActionSpec `yaml:"actions,omitempty" bson:",omitempty"`
}

Actions defines the available actions for the charm. Additional params may be added as metadata at a future time (e.g. version.)

func NewActions

func NewActions() *Actions

Build this out further if it becomes necessary.

func ReadActionsYaml

func ReadActionsYaml(charmName string, r io.Reader) (*Actions, error)

ReadActionsYaml builds an Actions spec from a charm's actions.yaml.

type ApplicationSpec

type ApplicationSpec struct {
	// Charm holds the charm URL of the charm to
	// use for the given application.
	Charm string `bson:",omitempty" yaml:",omitempty" json:",omitempty"`

	// Channel describes the preferred channel to use when deploying a
	// remote charm.
	Channel string `bson:"channel,omitempty" yaml:"channel,omitempty" json:"channel,omitempty"`

	// Revision describes the revision of the charm to use when deploying.
	Revision *int `bson:"revision,omitempty" yaml:"revision,omitempty" json:"revision,omitempty"`

	// Series is the series to use when deploying the application.
	Series string `bson:",omitempty" yaml:",omitempty" json:",omitempty"`

	// Base is the base to use when deploying the application.
	Base string `bson:",omitempty" yaml:",omitempty" json:",omitempty"`

	// Resources is the set of resource revisions to deploy for the
	// application. Bundles only support charm store resources and not ones
	// that were uploaded to the controller.
	// A resource value can either be an integer revision number,
	// or a string holding a path to a local resource file.
	Resources map[string]interface{} `bson:",omitempty" yaml:",omitempty" json:",omitempty"`

	// NumUnits holds the number of units of the
	// application that will be deployed.
	// For Kubernetes bundles, this will be an alias for Scale.
	//
	// For a subordinate application, this actually represents
	// an arbitrary number of units depending on
	// the application it is related to.
	NumUnits int `bson:",omitempty" yaml:"num_units,omitempty" json:",omitempty"`

	// Scale_ holds the number of pods required for the application.
	// For IAAS bundles, this will be an alias for NumUnits.
	Scale_ int `bson:"scale,omitempty" yaml:"scale,omitempty" json:"scale,omitempty"`

	// To is interpreted according to whether this is an
	// IAAS or Kubernetes bundle.
	//
	// For Kubernetes bundles, the use of Placement is preferred.
	// To must be a single valued list representing label key values
	// used as a node selector.
	//
	// For IAAS bundles, To may hold up to NumUnits members with
	// each member specifying a desired placement
	// for the respective unit of the application.
	//
	// In regular-expression-like notation, each
	// element matches the following pattern:
	//
	//      (<containertype>:)?(<unit>|<machine>|new)
	//
	// If containertype is specified, the unit is deployed
	// into a new container of that type, otherwise
	// it will be "hulk-smashed" into the specified location,
	// by co-locating it with any other units that happen to
	// be there, which may result in unintended behavior.
	//
	// The second part (after the colon) specifies where
	// the new unit should be placed - it may refer to
	// a unit of another application specified in the bundle,
	// a machine id specified in the machines section,
	// or the special name "new" which specifies a newly
	// created machine.
	//
	// A unit placement may be specified with an application name only,
	// in which case its unit number is assumed to
	// be one more than the unit number of the previous
	// unit in the list with the same application, or zero
	// if there were none.
	//
	// If there are less elements in To than NumUnits,
	// the last element is replicated to fill it. If there
	// are no elements (or To is omitted), "new" is replicated.
	//
	// For example:
	//
	//     wordpress/0 wordpress/1 lxc:0 kvm:new
	//
	//  specifies that the first two units get hulk-smashed
	//  onto the first two units of the wordpress application,
	//  the third unit gets allocated onto an lxc container
	//  on machine 0, and subsequent units get allocated
	//  on kvm containers on new machines.
	//
	// The above example is the same as this:
	//
	//     wordpress wordpress lxc:0 kvm:new
	To []string `bson:",omitempty" json:",omitempty" yaml:",omitempty"`

	// Placement_ holds a model selector/affinity expression used to specify
	// pod placement for Kubernetes applications.
	// Not relevant for IAAS applications.
	Placement_ string `bson:"placement,omitempty" json:"placement,omitempty" yaml:"placement,omitempty"`

	// Expose holds whether the application must be exposed.
	Expose bool `bson:",omitempty" json:",omitempty" yaml:",omitempty"`

	// ExposedEndpoints defines on a per-endpoint basis, the list of space
	// names and/or CIDRs that should be able to access the ports opened
	// for an endpoint once the application is exposed. The keys of the map
	// are endpoint names or the special empty ("") value that is used as a
	// placeholder for referring to all endpoints.
	//
	// This attribute cannot be used in tandem with the 'expose: true'
	// flag; a validation error will be raised if both fields are specified.
	ExposedEndpoints map[string]ExposedEndpointSpec `` /* 126-byte string literal not displayed */

	// Options holds the configuration values
	// to apply to the new application. They should
	// be compatible with the charm configuration.
	Options map[string]interface{} `bson:",omitempty" json:",omitempty" yaml:",omitempty"`

	// Annotations holds any annotations to apply to the
	// application when deployed.
	Annotations map[string]string `bson:",omitempty" json:",omitempty" yaml:",omitempty"`

	// Constraints holds the default constraints to apply
	// when creating new machines for units of the application.
	// This is ignored for units with explicit placement directives.
	Constraints string `bson:",omitempty" json:",omitempty" yaml:",omitempty"`

	// Storage holds the constraints for storage to assign
	// to units of the application.
	Storage map[string]string `bson:",omitempty" json:",omitempty" yaml:",omitempty"`

	// Devices holds the constraints for devices to assign
	// to units of the application.
	Devices map[string]string `bson:",omitempty" json:",omitempty" yaml:",omitempty"`

	// EndpointBindings maps how endpoints are bound to spaces
	EndpointBindings map[string]string `bson:"bindings,omitempty" json:"bindings,omitempty" yaml:"bindings,omitempty"`

	// Offers holds one entry for each exported offer for this application
	// where the key is the offer name.
	Offers map[string]*OfferSpec `bson:"offers,omitempty" json:"offers,omitempty" yaml:"offers,omitempty" source:"overlay-only"`

	// Plan specifies the plan under which the application is to be deployed.
	// If "default", the default plan will be used for the charm
	Plan string `bson:"plan,omitempty" json:"plan,omitempty" yaml:"plan,omitempty"`

	// RequiresTrust indicates that the application requires access to
	// cloud credentials and must therefore be explicitly trusted by the
	// operator before it can be deployed.
	RequiresTrust bool `bson:"trust,omitempty" json:"trust,omitempty" yaml:"trust,omitempty"`
}

ApplicationSpec represents a single application that will be deployed as part of the bundle.

type Base

type Base struct {
	Name          string   `bson:"name,omitempty" json:"name,omitempty"`
	Channel       Channel  `bson:"channel,omitempty" json:"channel,omitempty"`
	Architectures []string `bson:"architectures,omitempty" json:"architectures,omitempty"`
}

Base represents an OS/Channel. Bases can also be converted to and from a series string.

func ParseBase

func ParseBase(s string, archs ...string) (Base, error)

ParseBase parses a base as string in the form "os@track/risk/branch" and an optional list of architectures

func (Base) String

func (b Base) String() string

String representation of the Base.

func (Base) Validate

func (b Base) Validate() error

Validate returns with no error when the Base is valid.

type Bundle

type Bundle interface {
	// Data returns the contents of the bundle's bundle.yaml file.
	Data() *BundleData
	// BundleBytes returns the raw bytes content of a bundle
	BundleBytes() []byte
	// ReadMe returns the contents of the bundle's README.md file.
	ReadMe() string
	// ContainsOverlays returns true if the bundle contains any overlays.
	ContainsOverlays() bool
}

The Bundle interface is implemented by any type that may be handled as a bundle. It encapsulates all the data of a bundle.

func ReadBundle

func ReadBundle(path string) (Bundle, error)

ReadBundle reads a Bundle from path, which can point to either a bundle archive or a bundle directory.

type BundleArchive

type BundleArchive struct {
	Path string
	// contains filtered or unexported fields
}

func ReadBundleArchive

func ReadBundleArchive(path string) (*BundleArchive, error)

ReadBundleArchive reads a bundle archive from the given file path.

func ReadBundleArchiveBytes

func ReadBundleArchiveBytes(data []byte) (*BundleArchive, error)

ReadBundleArchiveBytes reads a bundle archive from the given byte slice.

func ReadBundleArchiveFromReader

func ReadBundleArchiveFromReader(r io.ReaderAt, size int64) (*BundleArchive, error)

ReadBundleArchiveFromReader returns a BundleArchive that uses r to read the bundle. The given size must hold the number of available bytes in the file.

Note that the caller is responsible for closing r - methods on the returned BundleArchive may fail after that.

func (*BundleArchive) BundleBytes added in v13.1.0

func (a *BundleArchive) BundleBytes() []byte

BundleBytes implements Bundle.BundleBytes.

func (*BundleArchive) ContainsOverlays

func (a *BundleArchive) ContainsOverlays() bool

ContainsOverlays implements Bundle.ReadMe.

func (*BundleArchive) Data

func (a *BundleArchive) Data() *BundleData

Data implements Bundle.Data.

func (*BundleArchive) ExpandTo

func (a *BundleArchive) ExpandTo(dir string) error

ExpandTo expands the bundle archive into dir, creating it if necessary. If any errors occur during the expansion procedure, the process will abort.

func (*BundleArchive) ReadMe

func (a *BundleArchive) ReadMe() string

ReadMe implements Bundle.ReadMe.

type BundleData

type BundleData struct {
	// Type is used to signify whether this bundle is for IAAS or Kubernetes deployments.
	// Valid values are "Kubernetes" or "", with empty signifying an IAAS bundle.
	Type string `bson:"bundle,omitempty" json:"bundle,omitempty" yaml:"bundle,omitempty"`

	// Applications holds one entry for each application
	// that the bundle will create, indexed by
	// the application name.
	Applications map[string]*ApplicationSpec `bson:"applications,omitempty" json:"applications,omitempty" yaml:"applications,omitempty"`

	// Machines holds one entry for each machine referred to
	// by unit placements. These will be mapped onto actual
	// machines at bundle deployment time.
	// It is an error if a machine is specified but
	// not referred to by a unit placement directive.
	Machines map[string]*MachineSpec `bson:",omitempty" json:",omitempty" yaml:",omitempty"`

	// Saas holds one entry for each software as a service (SAAS) for cross
	// model relation (CMR). These will be mapped to the consuming side when
	// deploying a bundle.
	Saas map[string]*SaasSpec `bson:"saas,omitempty" json:"saas,omitempty" yaml:"saas,omitempty"`

	// Series holds the default series to use when
	// the bundle deploys applications. A series defined for an application
	// takes precedence.
	Series string `bson:",omitempty" json:",omitempty" yaml:",omitempty"`

	// Base holds the default base to use when the bundle deploys
	// applications. A base defined for an application takes precedence.
	DefaultBase string `bson:"default-base,omitempty" json:"default-base,omitempty" yaml:"default-base,omitempty"`

	// Relations holds a slice of 2-element slices,
	// each specifying a relation between two applications.
	// Each two-element slice holds two endpoints,
	// each specified as either colon-separated
	// (application, relation) pair or just an application name.
	// The relation is made between each. If the relation
	// name is omitted, it will be inferred from the available
	// relations defined in the applications' charms.
	Relations [][]string `bson:",omitempty" json:",omitempty" yaml:",omitempty"`

	// White listed set of tags to categorize bundles as we do charms.
	Tags []string `bson:",omitempty" json:",omitempty" yaml:",omitempty"`

	// Short paragraph explaining what the bundle is useful for.
	Description string `bson:",omitempty" json:",omitempty" yaml:",omitempty"`
}

BundleData holds the contents of the bundle.

func ExtractBaseAndOverlayParts

func ExtractBaseAndOverlayParts(bd *BundleData) (base, overlay *BundleData, err error)

ExtractBaseAndOverlayParts splits the bundle data into a base and overlay-specific bundle so that their union yields bd. To decide whether a field is overlay-specific, the implementation uses reflection and recursively scans the BundleData fields looking for fields annotated with the "overlay-only: true" tag.

To produce the base bundle, the original bundle is filtered and all overlay-specific values are set to the zero value for their type. To produce the overlay-specific bundle, we once again filter the original bundle but this time zero out fields that do not contain any descendant fields that are overlay-specific.

To clarify how this method works let's consider a bundle created via the yaml blob below:

applications:
  apache2:
    charm: cs:apache2-26
    offers:
      my-offer:
        endpoints:
        - apache-website
        - website-cache
      my-other-offer:
        endpoints:
        - apache-website
series: bionic

The "offers" and "endpoints" attributes are overlay-specific fields. If we were to run this method and then marshal the results back to yaml we would get:

The base bundle:

applications:
  apache2:
    charm: cs:apache2-26
series: bionic

The overlay-specific bundle:

applications:
  apache2:
    offers:
      my-offer:
        endpoints:
        - apache-website
        - website-cache
      my-other-offer:
        endpoints:
        - apache-website

The two bundles returned by this method are copies of the original bundle data and can thus be safely manipulated by the caller.

func ReadAndMergeBundleData

func ReadAndMergeBundleData(sources ...BundleDataSource) (*BundleData, error)

ReadAndMergeBundleData reads N bundle data sources, composes their contents together and returns the result. The first bundle data source is treated as a base bundle while subsequent bundle data sources are treated as overlays which are sequentially merged onto the base bundle.

Before returning the merged bundle, ReadAndMergeBundleData will also attempt to resolve any include directives present in the machine annotations, application options and annotations.

When merging an overlay into a base bundle the following rules apply for the BundleData struct fields:

  • if an overlay specifies a bundle-level series, it overrides the base bundle series.
  • overlay-defined relations are appended to the base bundle relations
  • overlay-defined machines overwrite the base bundle machines.
  • if an overlay defines an application that is not present in the base bundle, it will get appended to the application list.
  • if an overlay defines an empty application or saas value, it will be removed from the base bundle together with any associated relations. For example, to remove an application named "mysql" the following overlay snippet can be provided: applications: mysql:
  • if an overlay defines an application that is also present in the base bundle the two application specs are merged together (see following rules)

ApplicationSpec merge rules:

  • if the overlay defines a value for a scalar or slice field, it will overwrite the value from the base spec (e.g. trust, series etc).
  • if the overlay specifies a nil/empty value for a map field, then the map field of the base spec will be cleared.
  • if the overlay specifies a non-empty value for a map field, its key/value tuples are iterated and:
  • if the value is nil/zero and the value is non-scalar, it is deleted from the base spec.
  • otherwise, the key/value is inserted into the base spec overwriting any existing entries.

func ReadBundleData

func ReadBundleData(r io.Reader) (*BundleData, error)

ReadBundleData reads bundle data from the given reader. The returned data is not verified - call Verify to ensure that it is OK.

func (*BundleData) RequiredCharms

func (bd *BundleData) RequiredCharms() []string

RequiredCharms returns a sorted slice of all the charm URLs required by the bundle.

func (*BundleData) SetBSON

func (bd *BundleData) SetBSON(raw bson.Raw) error

SetBSON implements the bson.Setter interface.

func (*BundleData) UnmarshalJSON

func (bd *BundleData) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*BundleData) UnmarshalYAML

func (bd *BundleData) UnmarshalYAML(f func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

func (*BundleData) Verify

func (bd *BundleData) Verify(
	verifyConstraints func(c string) error,
	verifyStorage func(s string) error,
	verifyDevices func(s string) error,
) error

Verify is a convenience method that calls VerifyWithCharms with a nil charms map.

func (*BundleData) VerifyLocal

func (bd *BundleData) VerifyLocal(
	bundleDir string,
	verifyConstraints func(c string) error,
	verifyStorage func(s string) error,
	verifyDevices func(s string) error,
) error

VerifyLocal verifies that a local bundle file is consistent. A local bundle file may contain references to charms which are referred to by a directory, either relative or absolute.

bundleDir is used to construct the full path for charms specified using a relative directory path. The charm path is therefore expected to be relative to the bundle.yaml file.

func (*BundleData) VerifyWithCharms

func (bd *BundleData) VerifyWithCharms(
	verifyConstraints func(c string) error,
	verifyStorage func(s string) error,
	verifyDevices func(s string) error,
	charms map[string]Charm,
) error

VerifyWithCharms verifies that the bundle is consistent. The verifyConstraints function is called to verify any constraints that are found. If verifyConstraints is nil, no checking of constraints will be done. Similarly, a non-nil verifyStorage, verifyDevices function is called to verify any storage constraints.

It verifies the following:

- All defined machines are referred to by placement directives. - All applications referred to by placement directives are specified in the bundle. - All applications referred to by relations are specified in the bundle. - All basic constraints are valid. - All storage constraints are valid.

If charms is not nil, it should hold a map with an entry for each charm url returned by bd.RequiredCharms. The verification will then also check that applications are defined with valid charms, relations are correctly made and options are defined correctly.

If the verification fails, Verify returns a *VerificationError describing all the problems found.

type BundleDataPart

type BundleDataPart struct {
	Data            *BundleData
	PresenceMap     FieldPresenceMap
	UnmarshallError error
}

BundleDataPart combines a parsed BundleData instance with a nested map that can be used to discriminate between fields that are missing from the data and those that are present but defined to be empty.

type BundleDataSource

type BundleDataSource interface {
	Parts() []*BundleDataPart
	BundleBytes() []byte
	BasePath() string
	ResolveInclude(path string) ([]byte, error)
}

BundleDataSource is implemented by types that can parse bundle data into a list of composable parts.

func LocalBundleDataSource

func LocalBundleDataSource(path string) (BundleDataSource, error)

LocalBundleDataSource reads a (potentially multi-part) bundle from path and returns a BundleDataSource for it. Path may point to a yaml file, a bundle directory or a bundle archive.

func StreamBundleDataSource

func StreamBundleDataSource(r io.Reader, basePath string) (BundleDataSource, error)

StreamBundleDataSource reads a (potentially multi-part) bundle from r and returns a BundleDataSource for it.

type BundleDir

type BundleDir struct {
	Path string
	// contains filtered or unexported fields
}

BundleDir defines a bundle from a given directory.

func ReadBundleDir

func ReadBundleDir(path string) (dir *BundleDir, err error)

ReadBundleDir returns a BundleDir representing an expanded bundle directory. It does not verify the bundle data.

func (*BundleDir) ArchiveTo

func (dir *BundleDir) ArchiveTo(w io.Writer) error

func (*BundleDir) BundleBytes added in v13.1.0

func (dir *BundleDir) BundleBytes() []byte

BundleBytes implements Bundle.BundleBytes

func (*BundleDir) ContainsOverlays

func (dir *BundleDir) ContainsOverlays() bool

ContainsOverlays returns true if the bundle contains any overlays.

func (*BundleDir) Data

func (dir *BundleDir) Data() *BundleData

Data returns the contents of the bundle's bundle.yaml file.

func (*BundleDir) ReadMe

func (dir *BundleDir) ReadMe() string

ReadMe returns the contents of the bundle's README.md file.

type Channel

type Channel struct {
	Track  string `json:"track,omitempty"`
	Risk   Risk   `json:"risk,omitempty"`
	Branch string `json:"branch,omitempty"`
}

Channel identifies and describes completely a store channel.

A channel consists of, and is subdivided by, tracks, risk-levels and branches:

  • Tracks enable snap developers to publish multiple supported releases of their application under the same snap name.
  • Risk-levels represent a progressive potential trade-off between stability and new features.
  • Branches are _optional_ and hold temporary releases intended to help with bug-fixing.

The complete channel name can be structured as three distinct parts separated by slashes:

<track>/<risk>/<branch>

func MakeChannel

func MakeChannel(track, risk, branch string) (Channel, error)

MakeChannel creates a core charm Channel from a set of component parts.

func MakePermissiveChannel

func MakePermissiveChannel(track, risk, branch string) Channel

MakePermissiveChannel creates a normalized core charm channel which never fails. It assumes that the risk has been prechecked.

func ParseChannel

func ParseChannel(s string) (Channel, error)

ParseChannel parses a string representing a store channel.

func ParseChannelNormalize

func ParseChannelNormalize(s string) (Channel, error)

ParseChannelNormalize parses a string representing a store channel. The returned channel's track, risk and name are normalized.

func (Channel) Empty

func (ch Channel) Empty() bool

Empty returns true if all it's components are empty.

func (Channel) Normalize

func (ch Channel) Normalize() Channel

Normalize the channel with normalized track, risk and names.

func (Channel) String

func (ch Channel) String() string

type Charm

type Charm interface {
	CharmMeta
	Config() *Config
	Actions() *Actions
	Revision() int
}

The Charm interface is implemented by any type that may be handled as a charm.

func ReadCharm

func ReadCharm(path string) (charm Charm, err error)

ReadCharm reads a Charm from path, which can point to either a charm archive or a charm directory.

type CharmArchive

type CharmArchive struct {
	Path string // May be empty if CharmArchive wasn't read from a file
	// contains filtered or unexported fields
}

CharmArchive type encapsulates access to data and operations on a charm archive.

func ReadCharmArchive

func ReadCharmArchive(path string) (*CharmArchive, error)

ReadCharmArchive returns a CharmArchive for the charm in path.

func ReadCharmArchiveBytes

func ReadCharmArchiveBytes(data []byte) (archive *CharmArchive, err error)

ReadCharmArchiveBytes returns a CharmArchive read from the given data. Make sure the archive fits in memory before using this.

func ReadCharmArchiveFromReader

func ReadCharmArchiveFromReader(r io.ReaderAt, size int64) (archive *CharmArchive, err error)

ReadCharmArchiveFromReader returns a CharmArchive that uses r to read the charm. The given size must hold the number of available bytes in the file.

Note that the caller is responsible for closing r - methods on the returned CharmArchive may fail after that.

func (CharmArchive) Actions

func (c CharmArchive) Actions() *Actions

Actions returns the Actions representing the actions.yaml file for the charm expanded in dir.

func (*CharmArchive) ArchiveMembers

func (a *CharmArchive) ArchiveMembers() (set.Strings, error)

ArchiveMembers returns a set of the charm's contents.

func (CharmArchive) Config

func (c CharmArchive) Config() *Config

Config returns the Config representing the config.yaml file for the charm expanded in dir.

func (*CharmArchive) ExpandTo

func (a *CharmArchive) ExpandTo(dir string) error

ExpandTo expands the charm archive into dir, creating it if necessary. If any errors occur during the expansion procedure, the process will abort.

func (CharmArchive) LXDProfile

func (c CharmArchive) LXDProfile() *LXDProfile

LXDProfile returns the LXDProfile representing the lxd-profile.yaml file for the charm expanded in dir.

func (CharmArchive) Manifest

func (c CharmArchive) Manifest() *Manifest

Manifest returns the Manifest representing the manifest.yaml file for the charm expanded in dir.

func (CharmArchive) Meta

func (c CharmArchive) Meta() *Meta

Meta returns the Meta representing the metadata.yaml file for the charm expanded in dir.

func (CharmArchive) Revision

func (c CharmArchive) Revision() int

Revision returns the revision number for the charm expanded in dir.

func (CharmArchive) SetRevision

func (c CharmArchive) SetRevision(revision int)

SetRevision changes the charm revision number. This affects the revision reported by Revision and the revision of the charm created. The revision file in the charm directory is not modified.

func (CharmArchive) Version

func (c CharmArchive) Version() string

Version returns the VCS version representing the version file from archive.

type CharmDir

type CharmDir struct {
	Path string
	// contains filtered or unexported fields
}

CharmDir encapsulates access to data and operations on a charm directory.

func ReadCharmDir

func ReadCharmDir(path string) (*CharmDir, error)

ReadCharmDir returns a CharmDir representing an expanded charm directory.

func (CharmDir) Actions

func (c CharmDir) Actions() *Actions

Actions returns the Actions representing the actions.yaml file for the charm expanded in dir.

func (*CharmDir) ArchiveTo

func (dir *CharmDir) ArchiveTo(w io.Writer) error

ArchiveTo creates a charm file from the charm expanded in dir. By convention a charm archive should have a ".charm" suffix.

func (CharmDir) Config

func (c CharmDir) Config() *Config

Config returns the Config representing the config.yaml file for the charm expanded in dir.

func (CharmDir) LXDProfile

func (c CharmDir) LXDProfile() *LXDProfile

LXDProfile returns the LXDProfile representing the lxd-profile.yaml file for the charm expanded in dir.

func (CharmDir) Manifest

func (c CharmDir) Manifest() *Manifest

Manifest returns the Manifest representing the manifest.yaml file for the charm expanded in dir.

func (*CharmDir) MaybeGenerateVersionString

func (dir *CharmDir) MaybeGenerateVersionString(logger Logger) (string, string, error)

MaybeGenerateVersionString generates charm version string. We want to know whether parent folders use one of these vcs, that's why we try to execute each one of them The second return value is the detected vcs type.

func (CharmDir) Meta

func (c CharmDir) Meta() *Meta

Meta returns the Meta representing the metadata.yaml file for the charm expanded in dir.

func (CharmDir) Revision

func (c CharmDir) Revision() int

Revision returns the revision number for the charm expanded in dir.

func (*CharmDir) SetDiskRevision

func (dir *CharmDir) SetDiskRevision(revision int) error

SetDiskRevision does the same as SetRevision but also changes the revision file in the charm directory.

func (CharmDir) SetRevision

func (c CharmDir) SetRevision(revision int)

SetRevision changes the charm revision number. This affects the revision reported by Revision and the revision of the charm created. The revision file in the charm directory is not modified.

func (CharmDir) Version

func (c CharmDir) Version() string

Version returns the VCS version representing the version file from archive.

type CharmMeta

type CharmMeta interface {
	Meta() *Meta
	Manifest() *Manifest
}

CharmMeta describes methods that inform charm operation.

type Config

type Config struct {
	Options map[string]Option
}

Config represents the supported configuration options for a charm, as declared in its config.yaml file.

func NewConfig

func NewConfig() *Config

NewConfig returns a new Config without any options.

func ReadConfig

func ReadConfig(r io.Reader) (*Config, error)

ReadConfig reads a Config in YAML format.

func (*Config) DefaultSettings

func (c *Config) DefaultSettings() Settings

DefaultSettings returns settings containing the default value of every option in the config. Default values may be nil.

func (*Config) FilterSettings

func (c *Config) FilterSettings(settings Settings) Settings

FilterSettings returns the subset of the supplied settings that are valid.

func (*Config) ParseSettingsStrings

func (c *Config) ParseSettingsStrings(values map[string]string) (Settings, error)

ParseSettingsStrings returns settings derived from the supplied map. Every value in the map must be parseable to the correct type for the option identified by its key. Empty values are interpreted as nil.

func (*Config) ParseSettingsYAML

func (c *Config) ParseSettingsYAML(yamlData []byte, key string) (Settings, error)

ParseSettingsYAML returns settings derived from the supplied YAML data. The YAML must unmarshal to a map of strings to settings data; the supplied key must be present in the map, and must point to a map in which every value must have, or be a string parseable to, the correct type for the associated config option. Empty strings and nil values are both interpreted as nil.

func (*Config) ValidateSettings

func (c *Config) ValidateSettings(settings Settings) (Settings, error)

ValidateSettings returns a copy of the supplied settings with a consistent type for each value. It returns an error if the settings contain unknown keys or invalid values.

type Container

type Container struct {
	Resource string  `bson:"resource,omitempty" json:"resource,omitempty" yaml:"resource,omitempty"`
	Mounts   []Mount `bson:"mounts,omitempty" json:"mounts,omitempty" yaml:"mounts,omitempty"`
	Uid      *int    `bson:"uid,omitempty" json:"uid,omitempty" yaml:"uid,omitempty"`
	Gid      *int    `bson:"gid,omitempty" json:"gid,omitempty" yaml:"gid,omitempty"`
}

Container specifies the possible systems it supports and mounts it wants.

type Deployment

type Deployment struct {
	DeploymentType DeploymentType `bson:"type"`
	DeploymentMode DeploymentMode `bson:"mode"`
	ServiceType    ServiceType    `bson:"service"`
	MinVersion     string         `bson:"min-version"`
}

Deployment represents a charm's deployment requirements in the charm metadata.yaml file.

type DeploymentMode

type DeploymentMode string

DeploymentMode defines a deployment mode.

const (
	ModeOperator DeploymentMode = "operator"
	ModeWorkload DeploymentMode = "workload"
)

type DeploymentType

type DeploymentType string

DeploymentType defines a deployment type.

const (
	DeploymentStateless DeploymentType = "stateless"
	DeploymentStateful  DeploymentType = "stateful"
	DeploymentDaemon    DeploymentType = "daemon"
)

type Device

type Device struct {
	// Name is the name of the device.
	Name string `bson:"name"`

	// Description is a description of the device.
	Description string `bson:"description"`

	// Type is the device type.
	// currently supported types are
	// - gpu
	// - nvidia.com/gpu
	// - amd.com/gpu
	Type DeviceType `bson:"type"`

	// CountMin is the min number of devices that the charm requires.
	CountMin int64 `bson:"countmin"`

	// CountMax is the max number of devices that the charm requires.
	CountMax int64 `bson:"countmax"`
}

Device represents a charm's device requirement (GPU for example).

type DeviceType

type DeviceType string

DeviceType defines a device type.

type ExposedEndpointSpec

type ExposedEndpointSpec struct {
	// ExposeToSpaces contains a list of spaces that should be able to
	// access the application ports opened for an endpoint when the
	// application is exposed.
	ExposeToSpaces []string `bson:"expose-to-spaces,omitempty" json:"expose-to-spaces,omitempty" yaml:"expose-to-spaces,omitempty" source:"overlay-only"`

	// ExposeToCIDRs contains a list of CIDRs that should be able to access
	// the application ports opened for an endpoint when the application is
	// exposed.
	ExposeToCIDRs []string `bson:"expose-to-cidrs,omitempty" json:"expose-to-cidrs,omitempty" yaml:"expose-to-cidrs,omitempty" source:"overlay-only"`
}

ExposedEndpointSpec describes the expose parameters for an application endpoint.

type ExtraBinding

type ExtraBinding struct {
	Name string `bson:"name" json:"Name"`
}

ExtraBinding represents an extra bindable endpoint that is not a relation.

type FieldPresenceMap

type FieldPresenceMap map[interface{}]interface{}

FieldPresenceMap indicates which keys of a parsed bundle yaml document were present when the document was parsed. This map is used by the overlay merge code to figure out whether empty/nil field values were actually specified as such in the yaml document.

type Format

type Format int

Format of the parsed charm.

const (
	FormatUnknown Format = iota
	FormatV1      Format = iota
	FormatV2      Format = iota
)

Formats are the different versions of charm metadata supported.

func MetaFormat

func MetaFormat(ch CharmMeta) Format

MetaFormat returns the underlying format from checking the charm for the right values.

type FormatSelectionReason

type FormatSelectionReason = string

FormatSelectionReason represents the reason for a format version selection.

const (
	// SelectionManifest states that it found a manifest.
	SelectionManifest FormatSelectionReason = "manifest"
	// SelectionBases states that there was at least 1 base.
	SelectionBases FormatSelectionReason = "bases"
	// SelectionSeries states that there was at least 1 series.
	SelectionSeries FormatSelectionReason = "series"
	// SelectionContainers states that there was at least 1 container.
	SelectionContainers FormatSelectionReason = "containers"
)

type LXDProfile

type LXDProfile struct {
	Config      map[string]string            `json:"config" yaml:"config"`
	Description string                       `json:"description" yaml:"description"`
	Devices     map[string]map[string]string `json:"devices" yaml:"devices"`
}

LXDProfile is the same as ProfilePut defined in github.com/lxc/lxd/shared/api/profile.go

func NewLXDProfile

func NewLXDProfile() *LXDProfile

NewLXDProfile creates a LXDProfile with the internal data structures initialised to non nil values.

func ReadLXDProfile

func ReadLXDProfile(r io.Reader) (*LXDProfile, error)

ReadLXDProfile reads in a LXDProfile from a charm's lxd-profile.yaml. It is not validated at this point so that the caller can choose to override any validation.

func (*LXDProfile) Empty

func (profile *LXDProfile) Empty() bool

Empty returns true if neither devices nor config have been defined in the profile.

func (*LXDProfile) ValidateConfigDevices

func (profile *LXDProfile) ValidateConfigDevices() error

ValidateConfigDevices validates the Config and Devices properties of the LXDProfile. WhiteList devices: unix-char, unix-block, gpu, usb. BlackList config: boot*, limits* and migration*. An empty profile will not return an error.

type LXDProfiler

type LXDProfiler interface {
	// LXDProfile returns the LXDProfile found in lxd-profile.yaml of the charm
	LXDProfile() *LXDProfile
}

LXDProfiler defines a way to access a LXDProfile from a charm.

type Location

type Location interface {
	Path() string
	String() string
}

Location represents a charm location, which must declare a path component and a string representation.

type Logger

type Logger interface {
	Warningf(message string, args ...interface{})
	Debugf(message string, args ...interface{})
	Errorf(message string, args ...interface{})
	Tracef(message string, args ...interface{})
	Infof(message string, args ...interface{})
}

Logger represents the logging methods called.

type MachineSpec

type MachineSpec struct {
	Constraints string            `bson:",omitempty" json:",omitempty" yaml:",omitempty"`
	Annotations map[string]string `bson:",omitempty" json:",omitempty" yaml:",omitempty"`
	Series      string            `bson:",omitempty" json:",omitempty" yaml:",omitempty"`
	Base        string            `bson:",omitempty" json:",omitempty" yaml:",omitempty"`
}

MachineSpec represents a notional machine that will be mapped onto an actual machine at bundle deployment time.

type Manifest

type Manifest struct {
	Bases []Base `yaml:"bases"`
}

Manifest represents the recording of the building of the charm or bundle. The manifest file should represent the metadata.yaml, but a lot more information.

func ReadManifest

func ReadManifest(r io.Reader) (*Manifest, error)

ReadManifest reads in a Manifest from a charm's manifest.yaml. Some of validation is done when unmarshalling the manifest, including verification that the base.Name is a supported operating system. Full validation done by calling Validate().

func (*Manifest) UnmarshalYAML

func (m *Manifest) UnmarshalYAML(f func(interface{}) error) error

func (*Manifest) Validate

func (m *Manifest) Validate() error

Validate checks the manifest to ensure there are no empty names, nor channels, and that architectures are supported.

type Meta

type Meta struct {
	Name           string                   `bson:"name" json:"Name"`
	Summary        string                   `bson:"summary" json:"Summary"`
	Description    string                   `bson:"description" json:"Description"`
	Subordinate    bool                     `bson:"subordinate" json:"Subordinate"`
	Provides       map[string]Relation      `bson:"provides,omitempty" json:"Provides,omitempty"`
	Requires       map[string]Relation      `bson:"requires,omitempty" json:"Requires,omitempty"`
	Peers          map[string]Relation      `bson:"peers,omitempty" json:"Peers,omitempty"`
	ExtraBindings  map[string]ExtraBinding  `bson:"extra-bindings,omitempty" json:"ExtraBindings,omitempty"`
	Categories     []string                 `bson:"categories,omitempty" json:"Categories,omitempty"`
	Tags           []string                 `bson:"tags,omitempty" json:"Tags,omitempty"`
	Series         []string                 `bson:"series,omitempty" json:"SupportedSeries,omitempty"`
	Storage        map[string]Storage       `bson:"storage,omitempty" json:"Storage,omitempty"`
	Devices        map[string]Device        `bson:"devices,omitempty" json:"Devices,omitempty"`
	Deployment     *Deployment              `bson:"deployment,omitempty" json:"Deployment,omitempty"`
	PayloadClasses map[string]PayloadClass  `bson:"payloadclasses,omitempty" json:"PayloadClasses,omitempty"`
	Resources      map[string]resource.Meta `bson:"resources,omitempty" json:"Resources,omitempty"`
	Terms          []string                 `bson:"terms,omitempty" json:"Terms,omitempty"`
	MinJujuVersion version.Number           `bson:"min-juju-version,omitempty" json:"min-juju-version,omitempty"`

	// v2
	Containers map[string]Container    `bson:"containers,omitempty" json:"containers,omitempty" yaml:"containers,omitempty"`
	Assumes    *assumes.ExpressionTree `bson:"assumes,omitempty" json:"assumes,omitempty" yaml:"assumes,omitempty"`
	CharmUser  RunAs                   `bson:"charm-user,omitempty" json:"charm-user,omitempty" yaml:"charm-user,omitempty"`
}

Meta represents all the known content that may be defined within a charm's metadata.yaml file. Note: Series is serialised for backward compatibility as "supported-series" because a previous charm version had an incompatible Series field that was unused in practice but still serialized. This only applies to JSON because Meta has a custom YAML marshaller.

func ReadMeta

func ReadMeta(r io.Reader) (*Meta, error)

ReadMeta reads the content of a metadata.yaml file and returns its representation. The data has verified as unambiguous, but not validated.

func (Meta) Check

func (m Meta) Check(format Format, reasons ...FormatSelectionReason) error

Check checks that the metadata is well-formed.

func (Meta) CombinedRelations

func (m Meta) CombinedRelations() map[string]Relation

CombinedRelations returns all defined relations, regardless of their type in a single map.

func (Meta) Hooks

func (m Meta) Hooks() map[string]bool

Hooks returns a map of all possible valid hooks, taking relations into account. It's a map to enable fast lookups, and the value is always true.

func (Meta) MarshalYAML

func (m Meta) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler (yaml.v2). It is recommended to call Check() before calling this method, otherwise you make get metadata which is not v1 nor v2 format.

func (*Meta) UnmarshalYAML

func (meta *Meta) UnmarshalYAML(f func(interface{}) error) error

UnmarshalYAML

type Mount

type Mount struct {
	Storage  string `bson:"storage,omitempty" json:"storage,omitempty" yaml:"storage,omitempty"`
	Location string `bson:"location,omitempty" json:"location,omitempty" yaml:"location,omitempty"`
}

Mount allows a container to mount a storage filesystem from the storage top-level directive.

type OfferSpec

type OfferSpec struct {
	// The list of endpoints exposed via the offer.
	Endpoints []string `bson:"endpoints" json:"endpoints" yaml:"endpoints" source:"overlay-only"`

	// The access control list for this offer. The keys are users and the
	// values are access permissions.
	ACL map[string]string `bson:"acl,omitempty" json:"acl,omitempty" yaml:"acl,omitempty" source:"overlay-only"`
}

OfferSpec describes an offer for a particular application.

type OfferURL

type OfferURL struct {
	// Source represents where the offer is hosted.
	// If empty, the model is another model in the same controller.
	Source string // "<controller-name>" or "<jaas>" or ""

	// User is the user whose namespace in which the offer is made.
	// Where a model is specified, the user is the model owner.
	User string

	// ModelName is the name of the model providing the exported endpoints.
	// It is only used for local URLs or for specifying models in the same
	// controller.
	ModelName string

	// ApplicationName is the name of the application providing the exported endpoints.
	ApplicationName string
}

OfferURL represents the location of an offered application and its associated exported endpoints.

func ParseOfferURL

func ParseOfferURL(urlStr string) (*OfferURL, error)

ParseOfferURL parses the specified URL string into an OfferURL. The URL string is of one of the forms:

<model-name>.<application-name>
<model-name>.<application-name>:<relation-name>
<user>/<model-name>.<application-name>
<user>/<model-name>.<application-name>:<relation-name>
<controller>:<user>/<model-name>.<application-name>
<controller>:<user>/<model-name>.<application-name>:<relation-name>

func (*OfferURL) AsLocal

func (u *OfferURL) AsLocal() *OfferURL

AsLocal returns a copy of the URL with an empty (local) source.

func (*OfferURL) HasEndpoint

func (u *OfferURL) HasEndpoint() bool

HasEndpoint returns whether this offer URL includes an endpoint name in the application name.

func (*OfferURL) Path

func (u *OfferURL) Path() string

Path returns the path component of the URL.

func (*OfferURL) String

func (u *OfferURL) String() string

type OfferURLParts

type OfferURLParts OfferURL

OfferURLParts contains various attributes of a URL.

func ParseOfferURLParts

func ParseOfferURLParts(urlStr string) (*OfferURLParts, error)

ParseOfferURLParts parses a partial URL, filling out what parts are supplied. This method is used to generate a filter used to query matching offer URLs.

type Option

type Option struct {
	Type        string      `yaml:"type"`
	Description string      `yaml:"description,omitempty"`
	Default     interface{} `yaml:"default,omitempty"`
}

Option represents a single charm config option.

type PayloadClass

type PayloadClass struct {
	// Name identifies the payload class.
	Name string

	// Type identifies the type of payload (e.g. kvm, docker).
	Type string
}

PayloadClass holds the information about a payload class, as stored in a charm's metadata.

func (PayloadClass) Validate

func (pc PayloadClass) Validate() error

Validate checks the payload class to ensure its data is valid.

type Relation

type Relation struct {
	Name      string        `bson:"name"`
	Role      RelationRole  `bson:"role"`
	Interface string        `bson:"interface"`
	Optional  bool          `bson:"optional"`
	Limit     int           `bson:"limit"`
	Scope     RelationScope `bson:"scope"`
}

Relation represents a single relation defined in the charm metadata.yaml file.

func (Relation) ImplementedBy

func (r Relation) ImplementedBy(ch Charm) bool

ImplementedBy returns whether the relation is implemented by the supplied charm.

func (Relation) IsImplicit

func (r Relation) IsImplicit() bool

IsImplicit returns whether the relation is supplied by juju itself, rather than by a charm.

type RelationRole

type RelationRole string

RelationRole defines the role of a relation.

const (
	RoleProvider RelationRole = "provider"
	RoleRequirer RelationRole = "requirer"
	RolePeer     RelationRole = "peer"
)

type RelationScope

type RelationScope string

RelationScope describes the scope of a relation.

const (
	ScopeGlobal    RelationScope = "global"
	ScopeContainer RelationScope = "container"
)

type Risk

type Risk string

Risk describes the type of risk in a current channel.

const (
	Stable    Risk = "stable"
	Candidate Risk = "candidate"
	Beta      Risk = "beta"
	Edge      Risk = "edge"
)

type RunAs

type RunAs string

RunAs defines which user to run a certain process as.

const (
	RunAsDefault RunAs = ""
	RunAsRoot    RunAs = "root"
	RunAsSudoer  RunAs = "sudoer"
	RunAsNonRoot RunAs = "non-root"
)

type SaasSpec

type SaasSpec struct {
	URL string `bson:",omitempty" json:",omitempty" yaml:",omitempty"`
}

SaasSpec represents a single software as a service (SAAS) node. This will be mapped to consuming of offers from a bundle deployment.

type Schema

type Schema string

Schema represents the different types of valid schemas.

const (
	// Local represents a local charm URL, describes as a file system path.
	Local Schema = "local"

	// CharmHub schema represents the charmhub charm repository.
	CharmHub Schema = "ch"
)

func (Schema) Matches

func (s Schema) Matches(other string) bool

Matches attempts to compare if a schema string matches the schema.

func (Schema) Prefix

func (s Schema) Prefix(url string) string

Prefix creates a url with the given prefix, useful for typed schemas.

func (Schema) String

func (s Schema) String() string

type ServiceType

type ServiceType string

ServiceType defines a service type.

const (
	ServiceCluster      ServiceType = "cluster"
	ServiceLoadBalancer ServiceType = "loadbalancer"
	ServiceExternal     ServiceType = "external"
	ServiceOmit         ServiceType = "omit"
)

type Settings

type Settings map[string]interface{}

Settings is a group of charm config option names and values. A Settings S is considered valid by the Config C if every key in S is an option in C, and every value either has the correct type or is nil.

type Storage

type Storage struct {
	// Name is the name of the store.
	//
	// Name has no default, and must be specified.
	Name string `bson:"name"`

	// Description is a description of the store.
	//
	// Description has no default, and is optional.
	Description string `bson:"description"`

	// Type is the storage type: filesystem or block-device.
	//
	// Type has no default, and must be specified.
	Type StorageType `bson:"type"`

	// Shared indicates that the storage is shared between all units of
	// an application deployed from the charm. It is an error to attempt to
	// assign non-shareable storage to a "shared" storage requirement.
	//
	// Shared defaults to false.
	Shared bool `bson:"shared"`

	// ReadOnly indicates that the storage should be made read-only if
	// possible. If the storage cannot be made read-only, Juju will warn
	// the user.
	//
	// ReadOnly defaults to false.
	ReadOnly bool `bson:"read-only"`

	// CountMin is the number of storage instances that must be attached
	// to the charm for it to be useful; the charm will not install until
	// this number has been satisfied. This must be a non-negative number.
	//
	// CountMin defaults to 1 for singleton stores.
	CountMin int `bson:"countmin"`

	// CountMax is the largest number of storage instances that can be
	// attached to the charm. If CountMax is -1, then there is no upper
	// bound.
	//
	// CountMax defaults to 1 for singleton stores.
	CountMax int `bson:"countmax"`

	// MinimumSize is the minimum size of store that the charm needs to
	// work at all. This is not a recommended size or a comfortable size
	// or a will-work-well size, just a bare minimum below which the charm
	// is going to break.
	// MinimumSize requires a unit, one of MGTPEZY, and is stored as MiB.
	//
	// There is no default MinimumSize; if left unspecified, a provider
	// specific default will be used, typically 1GB for block storage.
	MinimumSize uint64 `bson:"minimum-size"`

	// Location is the mount location for filesystem stores. For multi-
	// stores, the location acts as the parent directory for each mounted
	// store.
	//
	// Location has no default, and is optional.
	Location string `bson:"location,omitempty"`

	// Properties allow the charm author to characterise the relative storage
	// performance requirements and sensitivities for each store.
	// eg “transient” is used to indicate that non persistent storage is acceptable,
	// such as tmpfs or ephemeral instance disks.
	//
	// Properties has no default, and is optional.
	Properties []string `bson:"properties,omitempty"`
}

Storage represents a charm's storage requirement.

type StorageType

type StorageType string

StorageType defines a storage type.

const (
	StorageBlock      StorageType = "block"
	StorageFilesystem StorageType = "filesystem"
)

type TermsId

type TermsId struct {
	Tenant   string
	Owner    string
	Name     string
	Revision int
}

TermsId represents a single term id. The term can either be owned or "public" (meaning there is no owner). The Revision starts at 1. Therefore a value of 0 means the revision is unset.

func ParseTerm

func ParseTerm(s string) (*TermsId, error)

ParseTerm takes a termID as a string and parses it into a Term. A complete term is in the form: tenant:owner/name/revision This function accepts partially specified identifiers typically in one of the following forms: name owner/name owner/name/27 # Revision 27 name/283 # Revision 283 cs:owner/name # Tenant cs

func (*TermsId) String

func (t *TermsId) String() string

String returns the term in canonical form. This would be one of:

tenant:owner/name/revision
tenant:name
owner/name/revision
owner/name
name/revision
name

func (*TermsId) Validate

func (t *TermsId) Validate() error

Validate returns an error if the Term contains invalid data.

type URL

type URL struct {
	Schema       string // "ch" or "local".
	Name         string // "wordpress".
	Revision     int    // -1 if unset, N otherwise.
	Series       string // "precise" or "" if unset; "bundle" if it's a bundle.
	Architecture string // "amd64" or "" if unset for charmstore (v1) URLs.
}

URL represents a charm or bundle location:

local:oneiric/wordpress
ch:wordpress
ch:amd64/jammy/wordpress-30

func MustParseURL

func MustParseURL(url string) *URL

MustParseURL works like ParseURL, but panics in case of errors.

func ParseURL

func ParseURL(url string) (*URL, error)

ParseURL parses the provided charm URL string into its respective structure.

A missing schema is assumed to be 'ch'.

func (*URL) FullPath

func (u *URL) FullPath() string

FullPath returns the full path of a URL path including the schema.

func (*URL) GetBSON

func (u *URL) GetBSON() (interface{}, error)

GetBSON turns u into a bson.Getter so it can be saved directly on a MongoDB database with mgo.

TODO (stickupkid): This should not be here, as this is purely for mongo data stores and that should be implemented at the site of data store, not dependant on the library.

func (*URL) MarshalJSON

func (u *URL) MarshalJSON() ([]byte, error)

MarshalJSON will marshal the URL into a slice of bytes in a JSON representation.

func (*URL) MarshalText

func (u *URL) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler by returning u.FullPath()

func (*URL) Path

func (u *URL) Path() string

Path returns the path of the URL without the schema.

func (*URL) SetBSON

func (u *URL) SetBSON(raw bson.Raw) error

SetBSON turns u into a bson.Setter so it can be loaded directly from a MongoDB database with mgo.

TODO (stickupkid): This should not be here, as this is purely for mongo data stores and that should be implemented at the site of data store, not dependant on the library.

func (*URL) String

func (u *URL) String() string

String returns the string representation of the URL.

func (*URL) UnmarshalJSON

func (u *URL) UnmarshalJSON(b []byte) error

UnmarshalJSON will unmarshal the URL from a JSON representation.

func (*URL) UnmarshalText

func (u *URL) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TestUnmarshaler by parsing the data with ParseURL.

func (*URL) WithArchitecture

func (u *URL) WithArchitecture(arch string) *URL

WithArchitecture returns a URL equivalent to url but with Architecture set to architecture.

func (*URL) WithRevision

func (u *URL) WithRevision(revision int) *URL

WithRevision returns a URL equivalent to url but with Revision set to revision.

func (*URL) WithSeries

func (u *URL) WithSeries(series string) *URL

WithSeries returns a URL equivalent to url but with Series set to series.

type UnitPlacement

type UnitPlacement struct {
	// ContainerType holds the container type of the new
	// new unit, or empty if unspecified.
	ContainerType string

	// Machine holds the numeric machine id, or "new",
	// or empty if the placement specifies an application.
	Machine string

	// application holds the application name, or empty if
	// the placement specifies a machine.
	Application string

	// Unit holds the unit number of the application, or -1
	// if unspecified.
	Unit int
}

func ParsePlacement

func ParsePlacement(p string) (*UnitPlacement, error)

ParsePlacement parses a unit placement directive, as specified in the To clause of an application entry in the applications section of a bundle.

type VerificationError

type VerificationError struct {
	Errors []error
}

VerificationError holds an error generated by BundleData.Verify, holding all the verification errors found when verifying.

func (*VerificationError) Error

func (err *VerificationError) Error() string

Directories

Path Synopsis
Package hooks provides types and constants that define the hooks known to Juju.
Package hooks provides types and constants that define the hooks known to Juju.

Jump to

Keyboard shortcuts

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