Documentation ¶
Overview ¶
Package tools 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.
Package tools 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 ¶
- Constants
- Variables
- func Archive(w io.Writer, dir string) error
- func ExistingJujuLocation() (string, error)
- func FindExactTools(ss SimplestreamsFetcher, env environs.Environ, vers version.Number, ...) (_ *coretools.Tools, err error)
- func FindTools(ss SimplestreamsFetcher, env environs.BootstrapEnviron, ...) (_ coretools.List, err error)
- func FindToolsForCloud(ss SimplestreamsFetcher, sources []simplestreams.DataSource, ...) (coretools.List, error)
- func GetMetadataSources(env environs.BootstrapEnviron, ...) ([]simplestreams.DataSource, error)
- func JujudVersion(dir string) (version.Binary, bool, error)
- func MarshalToolsMetadataJSON(metadata map[string][]*ToolsMetadata, updated time.Time) (index, legacyIndex []byte, products map[string][]byte, err error)
- func MarshalToolsMetadataProductsJSON(streamMetadata map[string][]*ToolsMetadata, updated time.Time) (out map[string][]byte, err error)
- func MergeAndWriteMetadata(ss SimplestreamsFetcher, store storage.Storage, toolsDir, stream string, ...) error
- func PreferredStreams(vers *version.Number, forceDevel bool, stream string) []string
- func ProductMetadataPath(stream string) string
- func ReadAllMetadata(ss SimplestreamsFetcher, store storage.StorageReader) (map[string][]*ToolsMetadata, error)
- func ReadList(stor storage.StorageReader, toolsDir string, majorVersion, minorVersion int) (coretools.List, error)
- func RegisterToolsDataSourceFunc(id string, f ToolsDataSourceFunc)
- func ResolveMetadata(stor storage.StorageReader, toolsDir string, metadata []*ToolsMetadata) error
- func Sort(metadata []*ToolsMetadata)
- func StorageName(vers version.Binary, stream string) string
- func ToolsContentId(stream string) string
- func ToolsURL(source string) (string, error)
- func UnregisterToolsDataSourceFunc(id string)
- func ValidateToolsMetadata(ss SimplestreamsFetcher, params *ToolsMetadataLookupParams) ([]string, *simplestreams.ResolveInfo, error)
- func WriteMetadata(stor storage.Storage, streamMetadata map[string][]*ToolsMetadata, ...) error
- type BundleToolsFunc
- type MetadataFile
- type ShouldWriteMirrors
- type SimplestreamsFetcher
- type ToolsConstraint
- type ToolsDataSourceFunc
- type ToolsMetadata
- func Fetch(ss SimplestreamsFetcher, sources []simplestreams.DataSource, ...) ([]*ToolsMetadata, *simplestreams.ResolveInfo, error)
- func MergeMetadata(tmlist1, tmlist2 []*ToolsMetadata) ([]*ToolsMetadata, error)
- func MetadataFromTools(toolsList coretools.List, toolsDir string) []*ToolsMetadata
- func ReadMetadata(ss SimplestreamsFetcher, store storage.StorageReader, stream string) ([]*ToolsMetadata, error)
- type ToolsMetadataLookupParams
- type VersionHash
- type Versions
Constants ¶
const ( // ContentDownload 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 = streamsAgentURL
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.)
Functions ¶
func Archive ¶
Archive writes the executable files found in the given directory in gzipped tar format to w.
func ExistingJujuLocation ¶
ExistingJujuLocation returns the directory where 'juju' is running, and where we expect to find 'jujuc' and 'jujud'.
func FindExactTools ¶
func FindExactTools(ss SimplestreamsFetcher, env environs.Environ, vers version.Number, osType string, arch string) (_ *coretools.Tools, err error)
FindExactTools returns only the tools that match the supplied version.
func FindTools ¶
func FindTools(ss SimplestreamsFetcher, 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 ¶
func FindToolsForCloud(ss SimplestreamsFetcher, 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 ¶
func GetMetadataSources(env environs.BootstrapEnviron, dataSourceFactory simplestreams.DataSourceFactory) ([]simplestreams.DataSource, error)
GetMetadataSources returns the sources to use when looking for simplestreams tools metadata for the given stream.
func JujudVersion ¶
JujudVersion returns the Jujud version at the specified location, and whether it is an official binary.
func MarshalToolsMetadataJSON ¶
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 ¶
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 ¶
func MergeAndWriteMetadata(ss SimplestreamsFetcher, store 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 ¶
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 ¶
ProductMetadataPath returns the tools product metadata path for the given stream.
func ReadAllMetadata ¶
func ReadAllMetadata(ss SimplestreamsFetcher, 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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
StorageName returns the name that is used to store and retrieve the given version of the juju tools.
func ToolsContentId ¶
ToolsContentId returns the tools content id for the given stream.
func ToolsURL ¶
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 ¶
func UnregisterToolsDataSourceFunc(id string)
UnregisterToolsDataSourceFunc unregisters an ToolsDataSourceFunc with the specified id.
func ValidateToolsMetadata ¶
func ValidateToolsMetadata(ss SimplestreamsFetcher, 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 ¶
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.
Types ¶
type BundleToolsFunc ¶
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 MetadataFile ¶
type ShouldWriteMirrors ¶
type ShouldWriteMirrors bool
type SimplestreamsFetcher ¶
type SimplestreamsFetcher interface { NewDataSource(simplestreams.Config) simplestreams.DataSource GetMetadata([]simplestreams.DataSource, simplestreams.GetMetadataParams) ([]interface{}, *simplestreams.ResolveInfo, error) }
SimplestreamsFetcher defines a way to fetch metadata from the simplestreams server.
type ToolsConstraint ¶
type ToolsConstraint struct { simplestreams.LookupParams Version version.Number MajorVersion int MinorVersion int }
ToolsConstraint defines criteria used to find a tools metadata record.
func NewGeneralToolsConstraint ¶
func NewGeneralToolsConstraint(majorVersion, minorVersion int, params simplestreams.LookupParams) *ToolsConstraint
NewGeneralToolsConstraint returns a ToolsConstraint for tools with matching major/minor version numbers.
func NewVersionedToolsConstraint ¶
func NewVersionedToolsConstraint(vers version.Number, params simplestreams.LookupParams) *ToolsConstraint
NewVersionedToolsConstraint returns a ToolsConstraint for a tools with a specific version.
func (*ToolsConstraint) IndexIds ¶
func (tc *ToolsConstraint) IndexIds() []string
IndexIds generates a string array representing product ids formed similarly to an ISCSI qualified name (IQN).
func (*ToolsConstraint) ProductIds ¶
func (tc *ToolsConstraint) ProductIds() ([]string, error)
ProductIds generates a string array representing product ids formed similarly to an ISCSI qualified name (IQN).
type ToolsDataSourceFunc ¶
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 ¶
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 ¶
func Fetch(ss SimplestreamsFetcher, 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 ¶
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 ¶
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 ¶
func ReadMetadata(ss SimplestreamsFetcher, store storage.StorageReader, stream string) ([]*ToolsMetadata, error)
ReadMetadata returns the tools metadata from the given storage for the specified stream.
func (*ToolsMetadata) String ¶
func (t *ToolsMetadata) String() string
type ToolsMetadataLookupParams ¶
type ToolsMetadataLookupParams struct { simplestreams.MetadataLookupParams Version string Major int Minor int }
ToolsMetadataLookupParams is used to query metadata for matching tools.
type VersionHash ¶
VersionHash contains the SHA256 of one jujud version.
type Versions ¶
type Versions struct {
Versions []VersionHash `yaml:"versions"`
}
Versions stores the content of a jujud signature file.
func ParseVersions ¶
ParseVersions constructs a versions object from a reader..