Documentation ¶
Overview ¶
Package devicestate implements the manager and state aspects responsible for the device identity and policies.
Index ¶
- Constants
- Variables
- func AllowUC20RemodelTesting(allow bool) (restore func())
- func CanManageRefreshes(st *state.State) bool
- func CreateRecoverySystem(st *state.State, label string) (*state.Change, error)
- func DeviceCtx(st *state.State, task *state.Task, providedDeviceCtx snapstate.DeviceContext) (snapstate.DeviceContext, error)
- func InjectSetModelError(err error)
- func Remodel(st *state.State, new *asserts.Model) (*state.Change, error)
- func Remodeling(st *state.State) bool
- type DeviceManager
- func (m *DeviceManager) CanStandby() bool
- func (m *DeviceManager) Ensure() error
- func (m *DeviceManager) Model() (*asserts.Model, error)
- func (m *DeviceManager) Reboot(systemLabel, mode string) error
- func (m *DeviceManager) Registered() <-chan struct{}
- func (m *DeviceManager) ReloadModeenv() error
- func (m *DeviceManager) RequestSystemAction(systemLabel string, action SystemAction) error
- func (m *DeviceManager) ResetToPostBootState()
- func (m *DeviceManager) Serial() (*asserts.Serial, error)
- func (m *DeviceManager) StartOfOperationTime() (time.Time, error)
- func (m *DeviceManager) StartUp() error
- func (m *DeviceManager) StoreContextBackend() storecontext.Backend
- func (m *DeviceManager) SystemMode(sysExpect SysExpectation) string
- func (m *DeviceManager) SystemModeInfo() (*SystemModeInfo, error)
- func (m *DeviceManager) Systems() ([]*System, error)
- type RebootOptions
- type RemodelKind
- type SysExpectation
- type System
- type SystemAction
- type SystemModeInfo
Constants ¶
const ( RebootHaltOp = "halt" RebootPoweroffOp = "poweroff" )
Variables ¶
var EarlyConfig func(st *state.State, preloadGadget func() (sysconfig.Device, *gadget.Info, error)) error
EarlyConfig is a hook set by configstate that can process early configuration during managers' startup.
var ErrNoSystems = errors.New("no systems seeds")
var ErrUnsupportedAction = errors.New("unsupported action")
Functions ¶
func AllowUC20RemodelTesting ¶
func AllowUC20RemodelTesting(allow bool) (restore func())
AllowUC20RemodelTesting is a temporary helper to allow testing remodeling of UC20 before the implementation is complete and the policy for this settled. It will be removed once remodel is fully implemented and made available for general use.
func CanManageRefreshes ¶
CanManageRefreshes returns true if the device can be switched to the "core.refresh.schedule=managed" mode.
TODO:
- Move the CanManageRefreshes code into the ifstate
- Look at the connections and find the connection for snapd-control with the managed attribute
- Take the snap from this connection and look at the snapstate to see if that snap has a snap declaration (to ensure it comes from the store)
func CreateRecoverySystem ¶
func DeviceCtx ¶
func DeviceCtx(st *state.State, task *state.Task, providedDeviceCtx snapstate.DeviceContext) (snapstate.DeviceContext, error)
DeviceCtx picks a device context from state, optional task or an optionally pre-provided one. Returns ErrNoState if a model assertion is not yet known. In particular if task belongs to a remodeling change this will find the appropriate remodel context.
func InjectSetModelError ¶
func InjectSetModelError(err error)
InjectSetModelError will trigger the selected error in the doSetModel handler. This is only useful for testing.
func Remodel ¶
Remodel takes a new model assertion and generates a change that takes the device from the old to the new model or an error if the transition is not possible.
TODO:
- Check estimated disk size delta
- Check all relevant snaps exist in new store (need to check that even unchanged snaps are accessible)
- Make sure this works with Core 20 as well, in the Core 20 case we must enforce the default-channels from the model as well
func Remodeling ¶
Remodeling returns true whether there's a remodeling in progress
Types ¶
type DeviceManager ¶
type DeviceManager struct {
// contains filtered or unexported fields
}
DeviceManager is responsible for managing the device identity and device policies.
func Manager ¶
func Manager(s *state.State, hookManager *hookstate.HookManager, runner *state.TaskRunner, newStore func(storecontext.DeviceBackend) snapstate.StoreService) (*DeviceManager, error)
Manager returns a new device manager.
func (*DeviceManager) CanStandby ¶
func (m *DeviceManager) CanStandby() bool
func (*DeviceManager) Ensure ¶
func (m *DeviceManager) Ensure() error
Ensure implements StateManager.Ensure.
func (*DeviceManager) Model ¶
func (m *DeviceManager) Model() (*asserts.Model, error)
Model returns the device model assertion.
func (*DeviceManager) Reboot ¶
func (m *DeviceManager) Reboot(systemLabel, mode string) error
Reboot triggers a reboot into the given systemLabel and mode.
When called without a systemLabel and without a mode it will just trigger a regular reboot.
When called without a systemLabel but with a mode it will use the current system to enter the given mode.
Note that "recover" and "run" modes are only available for the current system.
func (*DeviceManager) Registered ¶
func (m *DeviceManager) Registered() <-chan struct{}
Registered returns a channel that is closed when the device is known to have been registered.
func (*DeviceManager) ReloadModeenv ¶
func (m *DeviceManager) ReloadModeenv() error
ReloadModeenv is only useful for integration testing
func (*DeviceManager) RequestSystemAction ¶
func (m *DeviceManager) RequestSystemAction(systemLabel string, action SystemAction) error
RequestSystemAction requests the provided system to be run in a given mode as specified by action. A system reboot will be requested when the request can be successfully carried out.
func (*DeviceManager) ResetToPostBootState ¶
func (m *DeviceManager) ResetToPostBootState()
ResetToPostBootState is only useful for integration testing.
func (*DeviceManager) Serial ¶
func (m *DeviceManager) Serial() (*asserts.Serial, error)
Serial returns the device serial assertion.
func (*DeviceManager) StartOfOperationTime ¶
func (m *DeviceManager) StartOfOperationTime() (time.Time, error)
StartOfOperationTime returns the time when snapd started operating, and sets it in the state when called for the first time. The StartOfOperationTime time is seed-time if available, or current time otherwise.
func (*DeviceManager) StartUp ¶
func (m *DeviceManager) StartUp() error
StartUp implements StateStarterUp.Startup.
func (*DeviceManager) StoreContextBackend ¶
func (m *DeviceManager) StoreContextBackend() storecontext.Backend
func (*DeviceManager) SystemMode ¶
func (m *DeviceManager) SystemMode(sysExpect SysExpectation) string
SystemMode returns the current mode of the system. An expectation about the system controls the returned mode when none is set explicitly, as it's the case on pre-UC20 systems. In which case, with SysAny, the mode defaults to implicit "run", thus covering pre-UC20 systems. With SysHasModeeenv, as there is always an explicit mode in systems that use modeenv, no implicit default is used and thus "" is returned for pre-UC20 systems.
func (*DeviceManager) SystemModeInfo ¶
func (m *DeviceManager) SystemModeInfo() (*SystemModeInfo, error)
SystemModeInfo returns details about the current system mode the device is in.
func (*DeviceManager) Systems ¶
func (m *DeviceManager) Systems() ([]*System, error)
Systems list the available recovery/seeding systems. Returns the list of systems, ErrNoSystems when no systems seeds were found or other error.
type RebootOptions ¶
type RebootOptions struct {
Op string `json:"op,omitempty"`
}
RebootOptions can be attached to restart-system-to-run-mode tasks to control their restart behavior.
type RemodelKind ¶
type RemodelKind int
RemodelKind designates a kind of remodeling.
const ( // same brand/model, brand store UpdateRemodel RemodelKind = iota // same brand/model, different brand store StoreSwitchRemodel // different brand/model, maybe different brand store ReregRemodel )
func ClassifyRemodel ¶
func ClassifyRemodel(oldModel, newModel *asserts.Model) RemodelKind
ClassifyRemodel returns what kind of remodeling is going from oldModel to newModel.
func (RemodelKind) String ¶
func (k RemodelKind) String() string
type SysExpectation ¶
type SysExpectation int
const ( // SysAny indicates any system is appropriate. SysAny SysExpectation = iota // SysHasModeenv indicates only systems with modeenv are appropriate. SysHasModeenv )
type System ¶
type System struct { // Current is true when the system running now was installed from that // seed Current bool // Label of the seed system Label string // Model assertion of the system Model *asserts.Model // Brand information Brand *asserts.Account // Actions available for this system Actions []SystemAction }
type SystemAction ¶
type SystemModeInfo ¶
type SystemModeInfo struct { Mode string HasModeenv bool Seeded bool BootFlags []string HostDataLocations []string }
func SystemModeInfoFromState ¶
func SystemModeInfoFromState(st *state.State) (*SystemModeInfo, error)
SystemModeInfoFromState returns details about the system mode the device is in.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package internal (of devicestate) provides functions to access and set the device state for use only by devicestate, for convenience they are also exposed via devicestatetest for use in tests.
|
Package internal (of devicestate) provides functions to access and set the device state for use only by devicestate, for convenience they are also exposed via devicestatetest for use in tests. |