File: interface.go

package info (click to toggle)
golang-github-juju-utils 0.0~git20171220.f38c0b0-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,748 kB
  • sloc: makefile: 20
file content (98 lines) | stat: -rw-r--r-- 3,537 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2015 Canonical Ltd.
// Copyright 2015 Cloudbase Solutions SRL
// Licensed under the LGPLv3, see LICENCE file for details.

// 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.
package manager

import (
	"github.com/juju/utils/packaging/commands"
	"github.com/juju/utils/proxy"
)

// PackageManager is the interface which carries out various
// package-management related work.
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
}

// NewPackageManager returns the appropriate PackageManager implementation
// based on the provided series.
func NewPackageManager(series string) (PackageManager, error) {
	// TODO (aznashwan): find a more deterministic way of filtering out
	// release series without importing version from core.
	switch series {
	case "centos7":
		return NewYumPackageManager(), nil
	case "opensuseleap":
		return NewZypperPackageManager(), nil
	default:
		return NewAptPackageManager(), nil
	}
}

// NewAptPackageManager returns a PackageManager for apt-based systems.
func NewAptPackageManager() PackageManager {
	return &apt{basePackageManager{commands.NewAptPackageCommander()}}
}

// NewYumPackageManager returns a PackageManager for yum-based systems.
func NewYumPackageManager() PackageManager {
	return &yum{basePackageManager{commands.NewYumPackageCommander()}}
}

func NewZypperPackageManager() PackageManager {
	return &zypper{basePackageManager{commands.NewZypperPackageCommander()}}
}