Documentation ¶
Overview ¶
Package seedwrite implements writing image seeds.
Index ¶
- func DeriveComponentSideInfo(compPath string, compInfo *snap.ComponentInfo, info *snap.Info, ...) (*snap.ComponentSideInfo, []*asserts.Ref, error)
- func DeriveSideInfo(snapPath string, model *asserts.Model, sf SeedAssertionFetcher, ...) (*snap.SideInfo, []*asserts.Ref, error)
- func IsSytemDirectoryExistsError(err error) bool
- type AssertsFetchFunc
- type Manifest
- func (sm *Manifest) AllowedSnapRevision(snapName string) snap.Revision
- func (sm *Manifest) AllowedValidationSets() []*ManifestValidationSet
- func (sm *Manifest) MarkSnapRevisionSeeded(snapName string, revision snap.Revision) error
- func (sm *Manifest) MarkValidationSetSeeded(vsa *asserts.ValidationSet, pinned bool) error
- func (sm *Manifest) SetAllowedSnapRevision(snapName string, revision snap.Revision) error
- func (sm *Manifest) SetAllowedValidationSet(accountID, name string, sequence int, pinned bool) error
- func (sm *Manifest) Write(filePath string) error
- type ManifestSnapRevision
- type ManifestValidationSet
- type NewFetcherFunc
- type Options
- type OptionsComponent
- type OptionsSnap
- type SeedAssertionFetcher
- type SeedComponent
- type SeedSnap
- type SystemAlreadyExistsError
- type Writer
- func (w *Writer) BootSnaps() ([]*SeedSnap, error)
- func (w *Writer) CheckValidationSets() error
- func (w *Writer) Downloaded(fetchAsserts AssertsFetchFunc) (complete bool, err error)
- func (w *Writer) InfoDerived() error
- func (w *Writer) LocalSnaps() ([]*SeedSnap, error)
- func (w *Writer) Manifest() *Manifest
- func (w *Writer) SeedSnaps(copySnap func(name, src, dst string) error) error
- func (w *Writer) SetInfo(sn *SeedSnap, info *snap.Info, seedComps map[string]*SeedComponent) error
- func (w *Writer) SetOptionsSnaps(optSnaps []*OptionsSnap) error
- func (w *Writer) SetRedirectChannel(sn *SeedSnap, redirectChannel string) error
- func (w *Writer) SnapsToDownload() (snaps []*SeedSnap, err error)
- func (w *Writer) Start(db asserts.RODatabase, f SeedAssertionFetcher) error
- func (w *Writer) UnassertedSnaps() ([]naming.SnapRef, error)
- func (w *Writer) Warnings() []string
- func (w *Writer) WriteMeta() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeriveComponentSideInfo ¶
func DeriveComponentSideInfo(compPath string, compInfo *snap.ComponentInfo, info *snap.Info, model *asserts.Model, sf SeedAssertionFetcher, db asserts.RODatabase) (*snap.ComponentSideInfo, []*asserts.Ref, error)
DeriveComponentSideInfo tries to construct a ComponentSideInfo for the given component using its digest to fetch the relevant assertions. It will fail with an asserts.NotFoundError if it cannot find them. model is used to cross check that the found snap-resource-revision is applicable on the device.
func DeriveSideInfo ¶
func DeriveSideInfo(snapPath string, model *asserts.Model, sf SeedAssertionFetcher, db asserts.RODatabase) (*snap.SideInfo, []*asserts.Ref, error)
DeriveSideInfo tries to construct a SideInfo for the given snap using its digest to fetch the relevant snap assertions. It will fail with an asserts.NotFoundError if it cannot find them. model is used to cross check that the found snap-revision is applicable on the device.
Types ¶
type AssertsFetchFunc ¶
An AssertsFetchFunc should fetch appropriate assertions for the snap sn, it can take into account format constraints caused by the given systemSnap and kernelSnap if set. The returned references are expected to be resolvable in the writing assertion database.
type Manifest ¶
type Manifest struct {
// contains filtered or unexported fields
}
Represents the validation-sets and snaps that are used to build an image seed. The manifest will only allow adding entries once to support a pre-provided manifest. The seed.manifest generated by ubuntu-image contains entries in the following format: <account-id>/<name>=<sequence> <account-id>/<name> <sequence> <snap-name> <snap-revision>
func MockManifest ¶
func MockManifest(revsAllowed, revsSeeded map[string]*ManifestSnapRevision, vsAllowed, vsSeeded map[string]*ManifestValidationSet) *Manifest
MockManifest is stricly for unit tests, do not use for non-test code.
func NewManifest ¶
func NewManifest() *Manifest
func ReadManifest ¶
ReadManifest reads a seed.manifest previously generated by Manifest.Write and returns a new Manifest structure reflecting the contents.
func (*Manifest) AllowedSnapRevision ¶
AllowedSnapRevision retrieves any specified revision rule for the snap name.
func (*Manifest) AllowedValidationSets ¶
func (sm *Manifest) AllowedValidationSets() []*ManifestValidationSet
AllowedValidationSets returns the validation sets specified as allowed.
func (*Manifest) MarkSnapRevisionSeeded ¶
MarkSnapRevisionSeeded attempts to mark a snap-revision as seeded in the manifest. The seeded revision will be validated against any previously allowed revisions set. It will also be validated against any revisions set in previously seeded validation sets.
func (*Manifest) MarkValidationSetSeeded ¶
func (sm *Manifest) MarkValidationSetSeeded(vsa *asserts.ValidationSet, pinned bool) error
MarkValidationSetSeeded marks a validation-set as seeded. It verifies against any previously set rules by SetAllowedValidationSet, and sets up new rules based on the snaps defined in the validation set. This relies on validation-set assertions being marked here the moment they are fetched by the seedwriter, which should be done before the first call to MarkSnapRevisionSeeded.
func (*Manifest) SetAllowedSnapRevision ¶
SetAllowedSnapRevision adds a revision rule for the given snap name, meaning that any snap marked used through MarkSnapRevisionUsed will be validated against this rule. The manifest will only allow one revision per snap, meaning that any subsequent calls to this will be ignored.
func (*Manifest) SetAllowedValidationSet ¶
func (sm *Manifest) SetAllowedValidationSet(accountID, name string, sequence int, pinned bool) error
SetAllowedValidationSet adds a sequence rule for the given validation set, meaning that any validation set marked for use through MarkValidationSetUsed must match the given parameters. The manifest will only allow one sequence per validation set, meaning that any subsequent calls to this will be ignored.
type ManifestSnapRevision ¶
ManifestSnapRevision represents a snap revision as noted in the seed manifest.
func (*ManifestSnapRevision) String ¶
func (s *ManifestSnapRevision) String() string
type ManifestValidationSet ¶
type ManifestValidationSet struct { AccountID string Name string Sequence int Pinned bool Snaps []string }
ManifestValidationSet represents a validation set as noted in the seed manifest. A validation set can optionally be pinned, but the sequence will always be set to the sequence that was used during the image build.
func (*ManifestValidationSet) String ¶
func (s *ManifestValidationSet) String() string
func (*ManifestValidationSet) Unique ¶
func (s *ManifestValidationSet) Unique() string
type NewFetcherFunc ¶
A NewFetcherFunc can build a Fetcher saving to an (implicit) database and also calling the given additional save function.
type Options ¶
type Options struct { SeedDir string DefaultChannel string // The label for the recovery system for Core20 models Label string // TestSkipCopyUnverifiedModel is set to support naive tests // using an unverified model, the resulting image is broken TestSkipCopyUnverifiedModel bool // Manifest is used to track snaps and validation sets that have // been seeded. It can be pre-provided to provide specific revisions // and validation-set sequences. Manifest *Manifest // ManifestPath if set, specifies the file path where the // seed.manifest file should be written. ManifestPath string }
Options holds the options for a Writer.
type OptionsComponent ¶
OptionsComponent represents an options-referred snap with its option values. E.g. a component passed to ubuntu-image via --comp <snap_name>+<comp_name>.
type OptionsSnap ¶
type OptionsSnap struct { Name string SnapID string Path string Channel string Components []OptionsComponent }
OptionsSnap represents an options-referred snap with its option values. E.g. a snap passed to ubuntu-image via --snap. If Name is set the snap is from the store. If Path is set the snap is local at Path location. Components are the components passed via the --comp option. If there is a component option but no matching snap option, an implicit OptionsSnap is created.
func (*OptionsSnap) Component ¶
func (s *OptionsSnap) Component(compName string) *OptionsComponent
func (*OptionsSnap) HasComponent ¶
func (s *OptionsSnap) HasComponent(compName string) bool
func (*OptionsSnap) ID ¶
func (s *OptionsSnap) ID() string
func (*OptionsSnap) SnapName ¶
func (s *OptionsSnap) SnapName() string
type SeedAssertionFetcher ¶
type SeedAssertionFetcher interface { Fetch(ref *asserts.Ref) error FetchSequence(seq *asserts.AtSequence) error Save(asserts.Assertion) error Refs() []*asserts.Ref ResetRefs() }
SeedAssertionFetcher is a Fetcher which is designed to help with the fetching of assertions during seeding. It keeps track of assertions fetched, and allows for retrieving them at any point in time during seeding. It wraps around the asserts.{SequenceFormingFetcher,Fetcher} interfaces to allow for flexible retrieval of assertions.
func MakeSeedAssertionFetcher ¶
func MakeSeedAssertionFetcher(newFetcher NewFetcherFunc) SeedAssertionFetcher
MakeSeedAssertionFetcher makes a SeedAssertionFetcher using newFetcher which can build a base Fetcher with an additional save function, to capture assertion references.
type SeedComponent ¶
type SeedComponent struct { naming.ComponentRef Path string Info *snap.ComponentInfo }
SeedComponent holds details of a component being added to a seed.
type SeedSnap ¶
type SeedSnap struct { naming.SnapRef Channel string Path string // Components are the components of the snap to be copied to the seed. // If using local components, the slice will be set by // Writer.AddComponentsToSnap(), as we don't know initially which ones // are being included in this way. Components []SeedComponent // Info is the *snap.Info for the seed snap, filling this is // delegated to the Writer using code, via Writer.SetInfo. Info *snap.Info // contains filtered or unexported fields }
SeedSnap holds details of a snap being added to a seed.
type SystemAlreadyExistsError ¶
type SystemAlreadyExistsError struct {
// contains filtered or unexported fields
}
SystemAlreadyExistsError is an error returned when given seed system already exists.
func (*SystemAlreadyExistsError) Error ¶
func (e *SystemAlreadyExistsError) Error() string
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Downloaded must be passed an AssertsFetchFunc responsible for fetching or retrieving snap assertions when applicable.
Optionally a similar but simpler mechanism covers local snaps, where LocalSnaps returns SeedSnaps that can be filled with information derived from the snap at SeedSnap.Path, then InfoDerived is called.
V-------->\ | | SetOptionsSnaps | | v | ________/ v / Start \ | | | | v | | / LocalSnaps | no | | | | local | | v | no option snaps | | SetInfo* | snaps | | | | | | v | | | InfoDerived | | | | | \ \ | / > > SnapsToDownload< | ^ v | SetInfo* | | | complete = false v / Downloaded | | complete = true | v SeedSnaps (copy files) | v WriteMeta * = 0 or many calls (as needed)
func (*Writer) BootSnaps ¶
BootSnaps returns the seed snaps involved in the boot process. It can be invoked only after Downloaded returns complete == true. It returns an error for classic models as for those no snaps participate in boot before user space.
func (*Writer) CheckValidationSets ¶
CheckValidationSets validates all snaps that are to be seeded against any specified validation set. Info for all seed snaps must have been derived prior to this call.
func (*Writer) Downloaded ¶
func (w *Writer) Downloaded(fetchAsserts AssertsFetchFunc) (complete bool, err error)
Downloaded checks the downloaded snaps metadata provided via setting it into the SeedSnaps returned by the previous SnapsToDownload. It also returns whether the seed snap set is complete or SnapsToDownload should be called again. An AssertsFetchFunc must be provided for Downloaded to request to fetch snap assertions as appropriate.
func (*Writer) InfoDerived ¶
InfoDerived checks the local snaps metadata provided via setting it into the SeedSnaps returned by the previous LocalSnaps.
func (*Writer) LocalSnaps ¶
LocalSnaps returns a list of seed snaps that are local. The writer delegates to produce *snap.Info for them to then be set via SetInfo. If matching snap assertions can be found as well, they should be made available through the AssertsFetchFunc passed to Downloaded later, the assumption is also that they are added to the writing assertion database.
func (*Writer) SeedSnaps ¶
SeedSnaps checks seed snaps and copies local snaps into the seed using copySnap.
func (*Writer) SetInfo ¶
SetInfo sets info and seedComps (which is a map of component names to SeedComponent) in the SeedSnap sn and computes destination paths for all if coming from the store. If the components do not come from the store, some additional checks are performed.
func (*Writer) SetOptionsSnaps ¶
func (w *Writer) SetOptionsSnaps(optSnaps []*OptionsSnap) error
SetOptionsSnaps accepts options-referred snaps represented as OptionsSnap.
func (*Writer) SetRedirectChannel ¶
SetRedirectChannel sets the redirect channel for the SeedSnap for the in case there is a default track for it.
func (*Writer) SnapsToDownload ¶
SnapsToDownload returns a list of seed snaps to download. Once that is done and their SeedSnaps Info field is set with SetInfo fields Downloaded should be called next.
func (*Writer) Start ¶
func (w *Writer) Start(db asserts.RODatabase, f SeedAssertionFetcher) error
Start starts the seed writing, and fetches the necessary model assertions using the provided SeedAssertionFetcher (See MakeSeedAssertionFetcher). The provided fetcher must support the FetchSequence in case the model refers to any validation sets. The seed-writer assumes that the snap assertions will end up in the given db (writing assertions database). When the system seed directory is already present, SystemAlreadyExistsError is returned.
func (*Writer) UnassertedSnaps ¶
UnassertedSnaps returns references for all unasserted snaps in the seed. It can be invoked only after Downloaded returns complete == true.