Documentation ¶
Overview ¶
Package seedwrite implements writing image seeds.
Index ¶
- func DeriveSideInfo(snapPath string, rf RefAssertsFetcher, db asserts.RODatabase) (*snap.SideInfo, []*asserts.Ref, error)
- func IsSytemDirectoryExistsError(err error) bool
- type NewFetcherFunc
- type Options
- type OptionsSnap
- type RefAssertsFetcher
- type SeedSnap
- type SystemAlreadyExistsError
- type Writer
- func (w *Writer) BootSnaps() ([]*SeedSnap, error)
- func (w *Writer) Downloaded() (complete bool, err error)
- func (w *Writer) InfoDerived() error
- func (w *Writer) LocalSnaps() ([]*SeedSnap, error)
- func (w *Writer) SeedSnaps(copySnap func(name, src, dst string) error) error
- func (w *Writer) SetInfo(sn *SeedSnap, info *snap.Info) 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, newFetcher NewFetcherFunc) (RefAssertsFetcher, 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 DeriveSideInfo ¶
func DeriveSideInfo(snapPath string, rf RefAssertsFetcher, 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.
Types ¶
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 }
Options holds the options for a Writer.
type OptionsSnap ¶
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.
func (*OptionsSnap) ID ¶
func (s *OptionsSnap) ID() string
func (*OptionsSnap) SnapName ¶
func (s *OptionsSnap) SnapName() string
type RefAssertsFetcher ¶
A RefAssertsFetcher is a Fetcher that can at any point return references to the fetched assertions.
func MakeRefAssertsFetcher ¶
func MakeRefAssertsFetcher(newFetcher NewFetcherFunc) RefAssertsFetcher
MakeRefAssertsFetcher makes a RefAssertsFetcher using newFetcher which can build a base Fetcher with an additional save function.
type SeedSnap ¶
type SeedSnap struct { naming.SnapRef Channel string Path string // Info is the *snap.Info for the seed snap, filling this is // delegated to the Writer using code, via Writer.SetInfo. Info *snap.Info // ARefs are references to the snap assertions if applicable, // filling these is delegated to the Writer using code, the // assumption is that the corresponding assertions can be // found in the database passed to Writer.Start. ARefs []*asserts.Ref // 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
}
Writer writes Core 16/18 and Core 20 seeds.
Its methods need to be called in sequences that match prescribed flows.
Some methods can be skipped given some conditions.
SnapsToDownload and Downloaded needs to be called in a loop where the SeedSnaps returned by SnapsToDownload get SetInfo called with *snap.Info retrieved from the store and then the snaps can be downloaded at SeedSnap.Path, after which Downloaded must be invoked and the flow breaks out of the loop only when it returns complete = true. In the loop as well assertions for the snaps can be fetched and SeedSnap.ARefs set.
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) Downloaded ¶
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.
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 can be passed into SeedSnap ARefs, assuming they were 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 of the SeedSnap and possibly computes its destination Path.
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 with SetInfo and ARefs fields are set, Downloaded should be called next.
func (*Writer) Start ¶
func (w *Writer) Start(db asserts.RODatabase, newFetcher NewFetcherFunc) (RefAssertsFetcher, error)
Start starts the seed writing. It creates a RefAssertsFetcher using newFetcher and uses it to fetch model related assertions. For convenience it returns the fetcher possibly for use to fetch seed snap assertions, a task that the writer delegates as well as snap downloading. The writer assumes that the snap assertions will end up in the given db (writing assertion 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.