juju: github.com/juju/juju/environs/tools Index | Files | Directories

package tools

import "github.com/juju/juju/environs/tools"

The tools package supports locating, parsing, and filtering Ubuntu tools metadata in simplestreams format. See http://launchpad.net/simplestreams and in particular the doc/README file in that project for more information about the file formats.

The tools package supports locating, parsing, and filtering Ubuntu tools metadata in simplestreams format. See http://launchpad.net/simplestreams and in particular the doc/README file in that project for more information about the file formats.

Index

Package Files

build.go marshal.go simplestreams.go storage.go tools.go urls.go validation.go versionfile.go

Constants

const (
    // ImageIds is the simplestreams tools content type.
    ContentDownload = "content-download"

    // StreamsVersionV1 is used to construct the path for accessing streams data.
    StreamsVersionV1 = "v1"

    // IndexFileVersion is used to construct the streams index file.
    IndexFileVersion = 2
)
const (
    // Used to specify the released tools metadata.
    ReleasedStream = "released"

    // Used to specify metadata for testing tools.
    TestingStream = "testing"

    // Used to specify the proposed tools metadata.
    ProposedStream = "proposed"

    // Used to specify the devel tools metadata.
    DevelStream = "devel"
)
const (
    WriteMirrors      = ShouldWriteMirrors(true)
    DoNotWriteMirrors = ShouldWriteMirrors(false)
)

Variables

var AllMetadataStreams = []string{ReleasedStream, ProposedStream, TestingStream, DevelStream}

AllMetadataStreams is the set of streams for which there will be simplestreams tools metadata.

var DefaultBaseURL = "https://streams.canonical.com/juju/tools"

This needs to be a var so we can override it for testing.

var ErrNoTools = errors.New("no agent binaries available")
var VersionFileFallbackDir = "/usr/lib/juju"

VersionFileFallbackDir is the other location we'll check for a juju-versions file if it's not alongside the binary (for example if Juju was installed from a .deb). (Exposed so we can override it in tests.)

func Archive Uses

func Archive(w io.Writer, dir string) error

Archive writes the executable files found in the given directory in gzipped tar format to w.

func ExistingJujudLocation Uses

func ExistingJujudLocation() (string, error)

ExistingJujudLocation returns the directory to a jujud executable in the path.

func FindExactTools Uses

func FindExactTools(env environs.Environ, vers version.Number, series string, arch string) (_ *coretools.Tools, err error)

FindExactTools returns only the tools that match the supplied version.

func FindTools Uses

func FindTools(env environs.BootstrapEnviron, majorVersion, minorVersion int, streams []string, filter coretools.Filter) (_ coretools.List, err error)

FindTools returns a List containing all tools in the given stream, with a given major.minor version number available in the cloud instance, filtered by filter. If minorVersion = -1, then only majorVersion is considered. If no *available* tools have the supplied major.minor version number, or match the supplied filter, the function returns a *NotFoundError.

func FindToolsForCloud Uses

func FindToolsForCloud(sources []simplestreams.DataSource, cloudSpec simplestreams.CloudSpec, streams []string,
    majorVersion, minorVersion int, filter coretools.Filter) (coretools.List, error)

FindToolsForCloud returns a List containing all tools in the given streams, with a given major.minor version number and cloudSpec, filtered by filter. If minorVersion = -1, then only majorVersion is considered. If no *available* tools have the supplied major.minor version number, or match the supplied filter, the function returns a *NotFoundError.

func GetMetadataSources Uses

func GetMetadataSources(env environs.BootstrapEnviron) ([]simplestreams.DataSource, error)

GetMetadataSources returns the sources to use when looking for simplestreams tools metadata for the given stream.

func JujudVersion Uses

func JujudVersion(dir string) (version.Binary, bool, error)

JujudVersion returns the Jujud version at the specified location, and whether it is an official binary.

func MarshalToolsMetadataJSON Uses

func MarshalToolsMetadataJSON(metadata map[string][]*ToolsMetadata, updated time.Time) (index, legacyIndex []byte, products map[string][]byte, err error)

MarshalToolsMetadataJSON marshals tools metadata to index and products JSON. updated is the time at which the JSON file was updated.

func MarshalToolsMetadataProductsJSON Uses

func MarshalToolsMetadataProductsJSON(
    streamMetadata map[string][]*ToolsMetadata, updated time.Time,
) (out map[string][]byte, err error)

MarshalToolsMetadataProductsJSON marshals tools metadata to products JSON. updated is the time at which the JSON file was updated.

func MergeAndWriteMetadata Uses

func MergeAndWriteMetadata(stor storage.Storage, toolsDir, stream string, tools coretools.List, writeMirrors ShouldWriteMirrors) error

MergeAndWriteMetadata reads the existing metadata from storage (if any), and merges it with metadata generated from the given tools list. The resulting metadata is written to storage.

func PreferredStreams Uses

func PreferredStreams(vers *version.Number, forceDevel bool, stream string) []string

PreferredStreams returns the tools streams that should be searched for tools, based on the required version, whether devel mode is required, and any user specified stream. The streams are in fallback order - if there are no matching tools in one stream the next should be checked.

func ProductMetadataPath Uses

func ProductMetadataPath(stream string) string

ProductMetadataPath returns the tools product metadata path for the given stream.

func ReadAllMetadata Uses

func ReadAllMetadata(store storage.StorageReader) (map[string][]*ToolsMetadata, error)

ReadAllMetadata returns the tools metadata from the given storage for all streams. The result is a map of metadata slices, keyed on stream.

func ReadList Uses

func ReadList(stor storage.StorageReader, toolsDir string, majorVersion, minorVersion int) (coretools.List, error)

ReadList returns a List of the tools in store with the given major.minor version. If minorVersion = -1, then only majorVersion is considered. If majorVersion is -1, then all tools tarballs are used. If store contains no such tools, it returns ErrNoMatches.

func RegisterToolsDataSourceFunc Uses

func RegisterToolsDataSourceFunc(id string, f ToolsDataSourceFunc)

RegisterToolsDataSourceFunc registers an ToolsDataSourceFunc with the specified id, overwriting any function previously registered with the same id.

func ResolveMetadata Uses

func ResolveMetadata(stor storage.StorageReader, toolsDir string, metadata []*ToolsMetadata) error

ResolveMetadata resolves incomplete metadata by fetching the tools from storage and computing the size and hash locally.

func Sort Uses

func Sort(metadata []*ToolsMetadata)

Sort sorts a slice of ToolsMetadata in ascending order of their version in order to ensure the results of Fetch are ordered deterministically.

func StorageName Uses

func StorageName(vers version.Binary, stream string) string

StorageName returns the name that is used to store and retrieve the given version of the juju tools.

func ToolsContentId Uses

func ToolsContentId(stream string) string

ToolsContentId returns the tools content id for the given stream.

func ToolsURL Uses

func ToolsURL(source string) (string, error)

ToolsURL returns a valid tools URL constructed from source. source may be a directory, or a URL like file://foo or http://foo.

func UnregisterToolsDataSourceFunc Uses

func UnregisterToolsDataSourceFunc(id string)

UnregisterToolsDataSourceFunc unregisters an ToolsDataSourceFunc with the specified id.

func ValidateToolsMetadata Uses

func ValidateToolsMetadata(params *ToolsMetadataLookupParams) ([]string, *simplestreams.ResolveInfo, error)

ValidateToolsMetadata attempts to load tools metadata for the specified cloud attributes and returns any tools versions found, or an error if the metadata could not be loaded.

func WriteMetadata Uses

func WriteMetadata(stor storage.Storage, streamMetadata map[string][]*ToolsMetadata, streams []string, writeMirrors ShouldWriteMirrors) error

WriteMetadata writes the given tools metadata for the specified streams to the given storage. streamMetadata contains all known metadata so that the correct index files can be written. Only product files for the specified streams are written.

type BundleToolsFunc Uses

type BundleToolsFunc func(build bool, w io.Writer, forceVersion *version.Number) (version.Binary, bool, string, error)

BundleToolsFunc is a function which can bundle all the current juju tools in gzipped tar format to the given writer.

var BundleTools BundleToolsFunc = bundleTools

Override for testing.

type HasAgentMirror Uses

type HasAgentMirror interface {
    // AgentMirror returns the CloudSpec to use for looking up agent
    // binaries.
    AgentMirror() (simplestreams.CloudSpec, error)
}

HasAgentMirror is an optional interface that an Environ may implement to support agent/tools mirror lookup.

TODO(axw) 2016-04-11 #1568715 This exists only because we currently lack image simplestreams usable by the new Azure Resource Manager provider. When we have that, we can use "HasRegion" everywhere.

type MetadataFile Uses

type MetadataFile struct {
    Path string
    Data []byte
}

type ShouldWriteMirrors Uses

type ShouldWriteMirrors bool

type ToolsConstraint Uses

type ToolsConstraint struct {
    simplestreams.LookupParams
    Version      version.Number
    MajorVersion int
    MinorVersion int
}

ToolsConstraint defines criteria used to find a tools metadata record.

func NewGeneralToolsConstraint Uses

func NewGeneralToolsConstraint(majorVersion, minorVersion int, params simplestreams.LookupParams) *ToolsConstraint

NewGeneralToolsConstraint returns a ToolsConstraint for tools with matching major/minor version numbers.

func NewVersionedToolsConstraint Uses

func NewVersionedToolsConstraint(vers version.Number, params simplestreams.LookupParams) *ToolsConstraint

NewVersionedToolsConstraint returns a ToolsConstraint for a tools with a specific version.

func (*ToolsConstraint) IndexIds Uses

func (tc *ToolsConstraint) IndexIds() []string

IndexIds generates a string array representing product ids formed similarly to an ISCSI qualified name (IQN).

func (*ToolsConstraint) ProductIds Uses

func (tc *ToolsConstraint) ProductIds() ([]string, error)

ProductIds generates a string array representing product ids formed similarly to an ISCSI qualified name (IQN).

type ToolsDataSourceFunc Uses

type ToolsDataSourceFunc func(environs.Environ) (simplestreams.DataSource, error)

ToolsDataSourceFunc is a function type that takes an environment and returns a simplestreams datasource.

ToolsDataSourceFunc will be used in GetMetadataSources. Any error satisfying errors.IsNotSupported will be ignored; any other error will be cause GetMetadataSources to fail.

type ToolsMetadata Uses

type ToolsMetadata struct {
    Release  string `json:"release"`
    Version  string `json:"version"`
    Arch     string `json:"arch"`
    Size     int64  `json:"size"`
    Path     string `json:"path"`
    FullPath string `json:"-"`
    FileType string `json:"ftype"`
    SHA256   string `json:"sha256"`
}

ToolsMetadata holds information about a particular tools tarball.

func Fetch Uses

func Fetch(
    sources []simplestreams.DataSource, cons *ToolsConstraint,
) ([]*ToolsMetadata, *simplestreams.ResolveInfo, error)

Fetch returns a list of tools for the specified cloud matching the constraint. The base URL locations are as specified - the first location which has a file is the one used. Signed data is preferred, but if there is no signed data available and onlySigned is false, then unsigned data is used.

func MergeMetadata Uses

func MergeMetadata(tmlist1, tmlist2 []*ToolsMetadata) ([]*ToolsMetadata, error)

MergeMetadata merges the given tools metadata. If metadata for the same tools version exists in both lists, an entry with non-empty size/SHA256 takes precedence; if the two entries have different sizes/hashes, then an error is returned.

func MetadataFromTools Uses

func MetadataFromTools(toolsList coretools.List, toolsDir string) []*ToolsMetadata

MetadataFromTools returns a tools metadata list derived from the given tools list. The size and sha256 will not be computed if missing.

func ReadMetadata Uses

func ReadMetadata(store storage.StorageReader, stream string) ([]*ToolsMetadata, error)

ReadMetadata returns the tools metadata from the given storage for the specified stream.

func (*ToolsMetadata) String Uses

func (t *ToolsMetadata) String() string

type ToolsMetadataLookupParams Uses

type ToolsMetadataLookupParams struct {
    simplestreams.MetadataLookupParams
    Version string
    Major   int
    Minor   int
}

ToolsMetadataLookupParams is used to query metadata for matching tools.

type VersionHash Uses

type VersionHash struct {
    Version string `yaml:"version"`
    SHA256  string `yaml:"sha256"`
}

VersionHash contains the SHA256 of one jujud version.

type Versions Uses

type Versions struct {
    Versions []VersionHash `yaml:"versions"`
}

Versions stores the content of a jujud signature file.

func ParseVersions Uses

func ParseVersions(r io.Reader) (*Versions, error)

ParseVersions constructs a versions object from a reader..

func (*Versions) VersionsMatching Uses

func (v *Versions) VersionsMatching(r io.Reader) ([]string, error)

VersionsMatching returns all version numbers for which the SHA256 matches the content of the reader passed in.

Directories

PathSynopsis
testing

Package tools imports 36 packages (graph) and is imported by 602 packages. Updated 2019-08-19. Refresh now. Tools for package owners.