Documentation ¶
Overview ¶
The manager package defines an interface which can carry out numerous package-management related operations on the local system and the respective implementations on apt and yum-based systems.
Index ¶
- Variables
- type PackageManager
- type Snap
- func (pm *Snap) AddRepository(repo string) error
- func (snap *Snap) ChangeChannel(pack, channel string) error
- func (pm *Snap) Cleanup() error
- func (snap *Snap) ConfigureStoreProxy(assertions, storeID string) error
- func (snap *Snap) DisableStoreProxy() error
- func (snap *Snap) GetProxySettings() (proxy.Settings, error)
- func (snap *Snap) Install(packs ...string) error
- func (pm *Snap) InstallPrerequisite() error
- func (snap *Snap) InstalledChannel(pack string) string
- func (snap *Snap) IsInstalled(pack string) bool
- func (pm *Snap) Purge(packs ...string) error
- func (pm *Snap) Remove(packs ...string) error
- func (pm *Snap) RemoveRepository(repo string) error
- func (snap *Snap) Search(pack string) (bool, error)
- func (pm *Snap) SetProxy(settings proxy.Settings) error
- func (pm *Snap) Update() error
- func (pm *Snap) Upgrade() error
Constants ¶
This section is empty.
Variables ¶
var ( // Override for testing. Delay = 10 * time.Second Attempts = 30 )
var CommandOutput = (*exec.Cmd).CombinedOutput
CommandOutput is cmd.Output. It was aliased for testing purposes.
var ProcessStateSys = (*os.ProcessState).Sys
ProcessStateSys is ps.Sys. It was aliased for testing purposes.
var RunCommand = func(command string, args ...string) (output string, err error) { cmd := exec.Command(command, args...) out, err := cmd.CombinedOutput() return string(out), err }
RunCommand is helper function to execute the command and gather the output.
var RunCommandWithRetry = func(cmd string, getFatalError func(string) error) (output string, code int, _ error) { args := strings.Fields(cmd) if len(args) <= 1 { return "", 1, errors.New(fmt.Sprintf("too few arguments: expected at least 2, got %d", len(args))) } logger.Infof("Running: %s", cmd) // Retry operation 30 times, sleeping every 10 seconds between attempts. // This avoids failure in the case of something else having the dpkg lock // (e.g. a charm on the machine we're deploying containers to). var out []byte tryAgain := false err := retry.Call(retry.CallArgs{ Clock: clock.WallClock, Delay: Delay, Attempts: Attempts, NotifyFunc: func(lastError error, attempt int) { logger.Infof("Retrying: %s", cmd) }, IsFatalError: func(err error) bool { return !tryAgain }, Func: func() error { tryAgain = false command := exec.Command(args[0], args[1:]...) var err error out, err = CommandOutput(command) if err == nil { return nil } exitError, ok := err.(*exec.ExitError) if !ok { return errors.Annotatef(err, "unexpected error type %T", err) } waitStatus, ok := ProcessStateSys(exitError.ProcessState).(exitStatuser) if !ok { return errors.Annotatef(err, "unexpected process state type %T", exitError.ProcessState.Sys()) } code = waitStatus.ExitStatus() if code != 100 { return errors.Trace(err) } if getFatalError != nil { if fatalErr := getFatalError(string(out)); fatalErr != nil { return errors.Annotatef(fatalErr, "encountered fatal error") } } tryAgain = true return err }, }) if err != nil { logger.Errorf("packaging command failed: %v; cmd: %q; output: %s", err, cmd, string(out)) return string(out), code, errors.Errorf("packaging command failed: %v", err) } return string(out), 0, nil }
RunCommandWithRetry is a helper function which tries to execute the given command. It tries to do so for 30 times with a 10 second sleep between commands. It returns the output of the command, the exit code, and an error, if one occurs, logging along the way. It was aliased for testing purposes.
Functions ¶
This section is empty.
Types ¶
type PackageManager ¶
type PackageManager interface { // InstallPrerequisite runs the command which installs the prerequisite // package which provides repository management functionalityes. InstallPrerequisite() error // Update runs the command to update the local package list. Update() error // Upgrade runs the command which issues an upgrade on all packages // with available newer versions. Upgrade() error // Install runs a *single* command that installs the given package(s). Install(packs ...string) error // Remove runs a *single* command that removes the given package(s). Remove(packs ...string) error // Purge runs the command that removes the given package(s) along // with any associated config files. Purge(packs ...string) error // Search runs the command that determines whether the given package is // available for installation from the currently configured repositories. Search(pack string) (bool, error) // IsInstalled runs the command which determines whether or not the // given package is currently installed on the system. IsInstalled(pack string) bool // AddRepository runs the command that adds a repository to the // list of available repositories. // NOTE: requires the prerequisite package whose installation command // is done by running InstallPrerequisite(). AddRepository(repo string) error // RemoveRepository runs the command that removes a given // repository from the list of available repositories. // NOTE: requires the prerequisite package whose installation command // is done by running InstallPrerequisite(). RemoveRepository(repo string) error // Cleanup runs the command that cleans up all orphaned packages, // left-over files and previously-cached packages. Cleanup() error // GetProxySettings returns the curretly-configured package manager proxy. GetProxySettings() (proxy.Settings, error) // SetProxy runs the commands to set the given proxy parameters for the // package management system. SetProxy(settings proxy.Settings) error }
PackageManager is the interface which carries out various package-management related work.
func NewAptPackageManager ¶
func NewAptPackageManager() PackageManager
NewAptPackageManager returns a PackageManager for apt-based systems.
func NewPackageManager ¶
func NewPackageManager(series string) (PackageManager, error)
NewPackageManager returns the appropriate PackageManager implementation based on the provided series.
func NewYumPackageManager ¶
func NewYumPackageManager() PackageManager
NewYumPackageManager returns a PackageManager for yum-based systems.
func NewZypperPackageManager ¶
func NewZypperPackageManager() PackageManager
type Snap ¶
type Snap struct {
// contains filtered or unexported fields
}
Snap is the PackageManager implementation for snap-based systems.
func NewSnapPackageManager ¶
func NewSnapPackageManager() *Snap
NewSnapPackageManager returns a PackageManager for snap-based systems.
func (*Snap) AddRepository ¶
AddRepository is defined on the PackageManager interface.
func (*Snap) ChangeChannel ¶
ChangeChannel updates the tracked channel for an installed snap.
func (*Snap) Cleanup ¶
func (pm *Snap) Cleanup() error
Cleanup is defined on the PackageManager interface.
func (*Snap) ConfigureStoreProxy ¶
ConfigureStoreProxy sets up snapd to connect to the snap store proxy instance defined in the provided assertions using the provided store ID.
If snap also needs to use HTTP/HTTPS proxies to talk to the outside world, these need to be configured separately before invoking this method via a call to SetProxy.
func (*Snap) DisableStoreProxy ¶
DisableStoreProxy resets the snapd proxy store settings.
If snap was also configured to use HTTP/HTTPS proxies these must be reset separately via a call to SetProxy. call to SetProxy.
func (*Snap) GetProxySettings ¶
GetProxySettings is defined on the PackageManager interface.
func (*Snap) InstallPrerequisite ¶
func (pm *Snap) InstallPrerequisite() error
InstallPrerequisite is defined on the PackageManager interface.
func (*Snap) InstalledChannel ¶
InstalledChannel returns the snap channel for an installed package.
func (*Snap) IsInstalled ¶
IsInstalled is defined on the PackageManager interface.
func (*Snap) RemoveRepository ¶
RemoveRepository is defined on the PackageManager interface.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
This package contains a mock implementation of the manager.PackageManager interface which always returns positive outcomes and a nil error.
|
This package contains a mock implementation of the manager.PackageManager interface which always returns positive outcomes and a nil error. |