seedwriter

package
v0.0.0-...-c7fba9c Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2021 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package seedwrite implements writing image seeds.

Index

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.

func IsSytemDirectoryExistsError

func IsSytemDirectoryExistsError(err error) bool

Types

type NewFetcherFunc

type NewFetcherFunc func(save func(asserts.Assertion) error) asserts.Fetcher

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

type OptionsSnap struct {
	Name    string
	SnapID  string
	Path    string
	Channel string
}

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

type RefAssertsFetcher interface {
	asserts.Fetcher
	Refs() []*asserts.Ref
	ResetRefs()
}

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 New

func New(model *asserts.Model, opts *Options) (*Writer, error)

New returns a Writer to write a seed for the given model and using the given Options.

func (*Writer) BootSnaps

func (w *Writer) BootSnaps() ([]*SeedSnap, error)

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

func (w *Writer) Downloaded() (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.

func (*Writer) InfoDerived

func (w *Writer) InfoDerived() error

InfoDerived checks the local snaps metadata provided via setting it into the SeedSnaps returned by the previous LocalSnaps.

func (*Writer) LocalSnaps

func (w *Writer) LocalSnaps() ([]*SeedSnap, error)

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

func (w *Writer) SeedSnaps(copySnap func(name, src, dst string) error) error

SeedSnaps checks seed snaps and copies local snaps into the seed using copySnap.

func (*Writer) SetInfo

func (w *Writer) SetInfo(sn *SeedSnap, info *snap.Info) error

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

func (w *Writer) SetRedirectChannel(sn *SeedSnap, redirectChannel string) error

SetRedirectChannel sets the redirect channel for the SeedSnap for the in case there is a default track for it.

func (*Writer) SnapsToDownload

func (w *Writer) SnapsToDownload() (snaps []*SeedSnap, err error)

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

func (w *Writer) UnassertedSnaps() ([]naming.SnapRef, error)

UnassertedSnaps returns references for all unasserted snaps in the seed. It can be invoked only after Downloaded returns complete == true.

func (*Writer) Warnings

func (w *Writer) Warnings() []string

Warnings returns the warning messages produced so far. No warnings should be generated after Downloaded signaled complete.

func (*Writer) WriteMeta

func (w *Writer) WriteMeta() error

WriteMeta writes seed metadata and assertions into the seed.

Jump to

Keyboard shortcuts

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