appliance

package
v0.0.0-...-a44c915 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//lint:file-ignore U1000 All available upgrade statuses
	UpgradeStatusIdle        = "idle"
	UpgradeStatusStarted     = "started"
	UpgradeStatusDownloading = "downloading"
	UpgradeStatusVerifying   = "verifying"
	UpgradeStatusReady       = "ready"
	UpgradeStatusInstalling  = "installing"
	UpgradeStatusSuccess     = "success"
	UpgradeStatusFailed      = "failed"

	FileReady  = "Ready"
	FileFailed = "Failed"
)
View Source
const (
	IsLower   = -1
	IsEqual   = 0
	IsGreater = 1
)
View Source
const (
	MajorVersion = uint8(4)
	MinorVersion = uint8(2)
	PatchVersion = uint8(1)
)
View Source
const (
	FunctionController   = "Controller"
	FunctionGateway      = "Gateway"
	FunctionPortal       = "Portal"
	FunctionConnector    = "Connector"
	FunctionLogServer    = "LogServer"
	FunctionLogForwarder = "LogForwarder"
	FilterDelimiter      = "&"
)
View Source
const (
	TestAppliancePrimary                  = "primary"
	TestApplianceUnpreparedPrimary        = "primary-unprepared"
	TestApplianceSecondary                = "secondary"
	TestApplianceController3              = "controller3"
	TestApplianceControllerOffline        = "controller4"
	TestApplianceControllerNotPrepared    = "controller5"
	TestApplianceController2NotPrepared   = "controller7"
	TestApplianceControllerMismatch       = "controller6"
	TestApplianceControllerGatewayPrimary = "controller-gateway-primary"
	TestApplianceGatewayA1                = "gatewayA1"
	TestApplianceGatewayA2                = "gatewayA2"
	TestApplianceGatewayA3                = "gatewayA3"
	TestApplianceGatewayB1                = "gatewayB1"
	TestApplianceGatewayB2                = "gatewayB2"
	TestApplianceGatewayB3                = "gatewayB3"
	TestApplianceGatewayC1                = "gatewayC1"
	TestApplianceGatewayC2                = "gatewayC2"
	TestApplianceLogForwarderA1           = "logforwarderA1"
	TestApplianceLogForwarderA2           = "logforwarderA2"
	TestApplianceLogForwarderB1           = "logforwarderB1"
	TestApplianceLogForwarderB2           = "logforwarderB2"
	TestApplianceLogForwarderC1           = "logforwarderC1"
	TestApplianceLogForwarderC2           = "logforwarderC2"
	TestAppliancePortalA1                 = "portalA1"
	TestApplianceConnectorA1              = "connectorA1"
	TestApplianceLogServer                = "logserver"
	TestApplianceControllerGatewayA1      = "controller-gatewayA1"
	TestApplianceControllerGatewayB1      = "controller-gatewayB1"

	TestSiteA = "SiteA"
	TestSiteB = "SiteB"
	TestSiteC = "SiteC"
)
View Source
const (
	PrimaryUpgrade IsPrimaryUpgrade = "IsPrimaryUpgrade"
	Caller         CalledAs         = "calledAs"
)

Variables

View Source
var (
	ErrNeedsAllControllerUpgrade = errors.New("all controllers need to be prepared when doing a major or minor version upgrade.")
	ErrControllerVersionMismatch = errors.New("all controllers need to be prepared with the same version when doing a major or minor version upgrade.")
)
View Source
var (
	ErrSkipReasonNotPrepared            = errors.New("appliance is not prepared for upgrade")
	ErrSkipReasonOffline                = errors.New("appliance is offline")
	ErrSkipReasonInactive               = errors.New("appliance is inactive")
	ErrSkipReasonFiltered               = errors.New("filtered using the '--include' and/or '--exclude' flag")
	ErrSkipReasonAlreadyPrepared        = errors.New("appliance is already prepared for upgrade with a higher or equal version")
	ErrSkipReasonUnsupportedUpgradePath = errors.New("unsupported upgrade path")
	ErrSkipReasonAlreadySameVersion     = errors.New("appliance is already running a version higher or equal to the prepare version")
	ErrNoApplianceStats                 = errors.New("failed to find appliance stats")
	ErrVersionParse                     = errors.New("failed to parse current appliance version")
	ErrNothingToUpgrade                 = errors.New("No appliances are ready to upgrade. Please run 'upgrade prepare' before trying to complete an upgrade")
)
View Source
var (
	DefaultBackupDestination = filesystem.BackupDir()
)
View Source
var DefaultCommandFilter = map[string]map[string]string{
	"include": {},
	"exclude": {},
}
View Source
var (
	DefaultResponder = func(callback func(rw http.ResponseWriter, req *http.Request, count int)) http.HandlerFunc {
		count := 0
		return func(w http.ResponseWriter, r *http.Request) {
			callback(w, r, count)
		}
	}
)
View Source
var StatReady = []string{
	statControllerReady,
	statSingleControllerReady,
	statMultiControllerReady,
	statApplianceReady,
}
View Source
var StatusNotBusy = []string{
	statusHealthy,
	statusWarning,
	statusError,
	statusNotAvailable,
	statusOffline,
}

Functions

func ActiveFunctions

func ActiveFunctions(appliances []openapi.Appliance) map[string]bool

ActiveFunctions returns a map of all active functions in the appliances.

func AppendUniqueAppliance

func AppendUniqueAppliance(appliances []openapi.Appliance, appliance openapi.Appliance) []openapi.Appliance

func AutoscalingGateways

func AutoscalingGateways(appliances []openapi.Appliance) (*openapi.Appliance, []openapi.Appliance)

AutoscalingGateways return the template appliance and all gateways

func BackupPrompt

func BackupPrompt(appliances []openapi.Appliance, preSelected []openapi.Appliance) ([]openapi.Appliance, error)

func CheckApplianceVersionsDisallowed

func CheckApplianceVersionsDisallowed(currentVersion, targetVersion *version.Version) error

func CheckNeedsMultiControllerUpgrade

func CheckNeedsMultiControllerUpgrade(stats *openapi.StatsAppliancesList, upgradeStatusMap map[string]UpgradeStatusResult, appliances []openapi.Appliance) ([]openapi.Appliance, error)

func CleanupBackup

func CleanupBackup(opts *BackupOpts, IDs map[string]string) error

func CompareVersionsAndBuildNumber

func CompareVersionsAndBuildNumber(x, y *version.Version) (int, error)

CompareVersionsAndBuildNumber compares two versions and returns the result with an integer representation -1 if y is lower than x 0 if versions match 1 if y is greater than x

func DownloadDockerBundles

func DownloadDockerBundles(ctx context.Context, p *tui.Progress, client *http.Client, path string, registry *url.URL, images map[string]string, ciMode bool) (*os.File, error)

func FilterActivated

func FilterActivated(appliances []openapi.Appliance) (active []openapi.Appliance, inactive []openapi.Appliance)

func FilterAppliances

func FilterAppliances(appliances []openapi.Appliance, filter map[string]map[string]string, orderBy []string, descending bool) ([]openapi.Appliance, []openapi.Appliance, error)

func FilterAvailable

func FilterAvailable(appliances []openapi.Appliance, stats []openapi.StatsAppliancesListAllOfData) ([]openapi.Appliance, []openapi.Appliance, error)

FilterAvailable return lists of online, offline, errors that will be used during upgrade

func FindCurrentController

func FindCurrentController(appliances []openapi.Appliance, hostname string) (*openapi.Appliance, error)

func FindPrimaryController

func FindPrimaryController(appliances []openapi.Appliance, hostname string, validate bool) (*openapi.Appliance, error)

FindPrimaryController The given hostname should match one of the Controller's actual admin hostname. Hostnames should be compared in a case insensitive way.

func GenerateApplianceWithStats

func GenerateApplianceWithStats(activeFunctions []string, name, hostname, currentVersion, targetVersion, status, upgradeStatus string, online bool, site, siteName string) (openapi.Appliance, openapi.StatsAppliancesListAllOfData, openapi.StatsAppliancesListAllOfData)

func GetActiveFunctions

func GetActiveFunctions(appliance openapi.Appliance) []string

func GetApplianceVersion

func GetApplianceVersion(appliance openapi.Appliance, stats openapi.StatsAppliancesList) (*version.Version, error)

func GroupByFunctions

func GroupByFunctions(appliances []openapi.Appliance) map[string][]openapi.Appliance

GroupByFunctions group appliances by function

func HasDiffVersions

func HasDiffVersions(stats []openapi.StatsAppliancesListAllOfData) (bool, map[string]string)

func IsMajorUpgrade

func IsMajorUpgrade(current, next *version.Version) bool

func IsMinorUpgrade

func IsMinorUpgrade(current, next *version.Version) bool

func IsOnAppliance

func IsOnAppliance() bool

func IsPatchUpgrade

func IsPatchUpgrade(current, next *version.Version) bool

func NeedsMultiControllerUpgrade

func NeedsMultiControllerUpgrade(upgradeStatuses map[string]UpgradeStatusResult, initialStatData []openapi.StatsAppliancesListAllOfData, all, preparing []openapi.Appliance, majorOrMinor bool) (bool, error)

func ParseVersionFromZip

func ParseVersionFromZip(filename string) (*version.Version, error)

func ParseVersionString

func ParseVersionString(input string) (*version.Version, error)

ParseVersionString tries to determine appliance version based on the input filename, It assumes the file is has the standard naming convention of appgate-5.4.4-26245-release.img.zip where 5.4.4 is the semver of the appliance.

func PerformBackup

func PerformBackup(cmd *cobra.Command, args []string, opts *BackupOpts) (map[string]string, error)

func PrepareBackup

func PrepareBackup(opts *BackupOpts) error

func PrettyBytes

func PrettyBytes(v float64) string

func PrintDiskSpaceWarningMessage

func PrintDiskSpaceWarningMessage(out io.Writer, stats []openapi.StatsAppliancesListAllOfData, apiVersion int)

func PromptSelect

func PromptSelect(ctx context.Context, a *Appliance, filter map[string]map[string]string, orderBy []string, descending bool) (string, error)

PromptSelect from online appliances

func PromptSelectAll

func PromptSelectAll(ctx context.Context, a *Appliance, filter map[string]map[string]string, orderBy []string, descending bool) (string, error)

PromptSelectAll from all appliances, offline and online

func ShowAutoscalingWarningMessage

func ShowAutoscalingWarningMessage(templateAppliance *openapi.Appliance, gateways []openapi.Appliance) (string, error)

func StatsIsOnline

func StatsIsOnline(s openapi.StatsAppliancesListAllOfData) bool

StatsIsOnline will return true if the Controller reports the appliance to be online in a valid status

func ValidateHostname

func ValidateHostname(controller openapi.Appliance, hostname string) error

Types

type Appliance

type Appliance struct {
	APIClient           *openapi.APIClient
	HTTPClient          *http.Client
	Token               string
	UpgradeStatusWorker WaitForUpgradeStatus
	ApplianceStats      WaitForApplianceStatus
}

Appliance is a wrapper around the APIClient for common functions around the appliance API that will be used within several commands.

func (*Appliance) ApplianceSwitchPartition

func (a *Appliance) ApplianceSwitchPartition(ctx context.Context, id string) error

func (*Appliance) DeleteFile

func (a *Appliance) DeleteFile(ctx context.Context, filename string) error

DeleteFile Delete a File from the current Controller.

func (*Appliance) DeprecatedStats

func (a *Appliance) DeprecatedStats(ctx context.Context, filter map[string]map[string]string, orderBy []string, descending bool) (*openapi.StatsAppliancesList, *http.Response, error)

func (*Appliance) DisableController

func (a *Appliance) DisableController(ctx context.Context, id string, appliance openapi.Appliance) error

func (*Appliance) DisableMaintenanceMode

func (a *Appliance) DisableMaintenanceMode(ctx context.Context, id string) (string, error)

func (*Appliance) EnableController

func (a *Appliance) EnableController(ctx context.Context, id string, appliance openapi.Appliance) error

func (*Appliance) EnableMaintenanceMode

func (a *Appliance) EnableMaintenanceMode(ctx context.Context, id string) (string, error)

func (*Appliance) FileStatus

func (a *Appliance) FileStatus(ctx context.Context, filename string) (*openapi.File, error)

FileStatus Get the status of a File uploaded to the current Controller.

func (*Appliance) Get

func (a *Appliance) Get(ctx context.Context, applianceID string) (*openapi.Appliance, error)

Get return a single appliance based on applianceID

func (*Appliance) List

func (a *Appliance) List(ctx context.Context, filter map[string]map[string]string, orderBy []string, descending bool) ([]openapi.Appliance, error)

List from the Collective Filter is applied in app after getting all the appliances because the auto generated API screws up the 'filterBy' command

func (*Appliance) ListFiles

func (a *Appliance) ListFiles(ctx context.Context, orderBy []string, descending bool) ([]openapi.File, error)

func (*Appliance) PrepareFileOn

func (a *Appliance) PrepareFileOn(ctx context.Context, filename, id string, devKeyring bool) (string, error)

func (*Appliance) RepartitionIPAllocations

func (a *Appliance) RepartitionIPAllocations(ctx context.Context) (string, error)

func (*Appliance) UpdateAppliance

func (a *Appliance) UpdateAppliance(ctx context.Context, id string, appliance openapi.Appliance) error

func (*Appliance) UpdateMaintenanceMode

func (a *Appliance) UpdateMaintenanceMode(ctx context.Context, id string, value bool) (string, error)

func (*Appliance) UpgradeCancel

func (a *Appliance) UpgradeCancel(ctx context.Context, applianceID string) error

func (*Appliance) UpgradeComplete

func (a *Appliance) UpgradeComplete(ctx context.Context, id string, SwitchPartition bool) error

func (*Appliance) UpgradeStatus

func (a *Appliance) UpgradeStatus(ctx context.Context, applianceID string) (*openapi.AppliancesIdUpgradeDelete200Response, error)

func (*Appliance) UpgradeStatusMap

func (a *Appliance) UpgradeStatusMap(ctx context.Context, appliances []openapi.Appliance) (map[string]UpgradeStatusResult, error)

UpgradeStatusMap return a map with appliance.id, UpgradeStatusResult

func (*Appliance) UpgradeStatusRetry

func (a *Appliance) UpgradeStatusRetry(ctx context.Context, applianceID string) (*openapi.AppliancesIdUpgradeDelete200Response, error)

func (*Appliance) UpgradeSwitchPartition

func (a *Appliance) UpgradeSwitchPartition(ctx context.Context, id string) error

func (*Appliance) UploadFile

func (a *Appliance) UploadFile(ctx context.Context, r io.Reader, headers map[string]string) error

UploadFile directly to the current Controller. Note that the File is stored only on the current Controller, not synced between Controllers.

func (*Appliance) UploadToController

func (a *Appliance) UploadToController(ctx context.Context, url, filename string) error

func (*Appliance) ZTPStatus

func (a *Appliance) ZTPStatus(ctx context.Context) (*openapi.ZtpStatus, error)

func (*Appliance) ZTPUpdateNotify

func (a *Appliance) ZTPUpdateNotify(ctx context.Context) (*openapi.ZtpVersionStatus, error)

type ApplianceStatus

type ApplianceStatus struct {
	Appliance *Appliance
}

func (*ApplianceStatus) WaitForApplianceState

func (u *ApplianceStatus) WaitForApplianceState(ctx context.Context, appliance openapi.Appliance, want []string, tracker *tui.Tracker) error

func (*ApplianceStatus) WaitForApplianceStatus

func (u *ApplianceStatus) WaitForApplianceStatus(ctx context.Context, appliance openapi.Appliance, want []string, tracker *tui.Tracker) error

type BackupOpts

type BackupOpts struct {
	Config        *configuration.Config
	Appliance     func(*configuration.Config) (*Appliance, error)
	Out           io.Writer
	SpinnerOut    func() io.Writer
	Destination   string
	With          []string
	AllFlag       bool
	PrimaryFlag   bool
	CurrentFlag   bool
	NoInteractive bool
	FilterFlag    map[string]map[string]string
	OrderBy       []string
	Descending    bool
	Quiet         bool
	CiMode        bool
}

type CalledAs

type CalledAs string

type CollectiveTestStruct

type CollectiveTestStruct struct {
	Appliances    map[string]openapi.Appliance
	Stats         *openapi.StatsAppliancesList
	UpgradedStats *openapi.StatsAppliancesList
}

func GenerateCollective

func GenerateCollective(t *testing.T, hostname, from, to string, appliances []string) *CollectiveTestStruct

func (*CollectiveTestStruct) GenerateStubs

func (cts *CollectiveTestStruct) GenerateStubs(appliances []openapi.Appliance, stats, upgradedStats openapi.StatsAppliancesList) []httpmock.Stub

func (*CollectiveTestStruct) GetAppliance

func (cts *CollectiveTestStruct) GetAppliance(name string) *openapi.Appliance

func (*CollectiveTestStruct) GetAppliances

func (cts *CollectiveTestStruct) GetAppliances() []openapi.Appliance

func (*CollectiveTestStruct) GetUpgradeStatusMap

func (cts *CollectiveTestStruct) GetUpgradeStatusMap() map[string]UpgradeStatusResult

type DockerManifest

type DockerManifest struct {
	SchemaVersion int
	MediaType     string
	Config        ManifestConfig
	Layers        []ManifestConfig
}

type ImageJSON

type ImageJSON struct {
	Image string `json:"image"`
}

type IsPrimaryUpgrade

type IsPrimaryUpgrade string

type ManifestConfig

type ManifestConfig struct {
	MediaType string
	Size      int
	Digest    string
}

type SkipUpgrade

type SkipUpgrade struct {
	Reason    error
	Appliance openapi.Appliance
}

func CheckVersions

func CheckVersions(ctx context.Context, stats openapi.StatsAppliancesList, appliances []openapi.Appliance, v *version.Version) ([]openapi.Appliance, []SkipUpgrade)

CheckVersions will check if appliance versions are equal to the version being uploaded on all appliances Returns a slice of appliances that are not equal, a slice of appliances that have the same version and an error

func (SkipUpgrade) Error

func (su SkipUpgrade) Error() string

type UpgradePlan

type UpgradePlan struct {
	PrimaryController       *openapi.Appliance
	Controllers             []openapi.Appliance
	LogForwardersAndServers []openapi.Appliance
	Batches                 [][]openapi.Appliance
	Skipping                []SkipUpgrade
	BackupIds               []string
	// contains filtered or unexported fields
}

func NewUpgradePlan

func NewUpgradePlan(
	appliances []openapi.Appliance, stats *openapi.StatsAppliancesList,
	upgradeStatusMap map[string]UpgradeStatusResult,
	adminHostname string,
	filter map[string]map[string]string,
	orderBy []string,
	descending bool,
	maxUnavailable int,
) (*UpgradePlan, error)

func (*UpgradePlan) AddBackups

func (up *UpgradePlan) AddBackups(applianceIds []string) error

func (*UpgradePlan) AddInactiveAppliances

func (up *UpgradePlan) AddInactiveAppliances(appliances []openapi.Appliance)

func (*UpgradePlan) AddOfflineAppliances

func (up *UpgradePlan) AddOfflineAppliances(appliances []openapi.Appliance)

func (*UpgradePlan) GetPrimaryController

func (up *UpgradePlan) GetPrimaryController() *openapi.Appliance

func (*UpgradePlan) HasDiffVersions

func (up *UpgradePlan) HasDiffVersions(newStats []openapi.StatsAppliancesListAllOfData) (bool, map[string]string)

func (*UpgradePlan) NothingToUpgrade

func (up *UpgradePlan) NothingToUpgrade() bool

func (*UpgradePlan) PrintPostCompleteSummary

func (up *UpgradePlan) PrintPostCompleteSummary(out io.Writer, stats []openapi.StatsAppliancesListAllOfData) error

func (*UpgradePlan) PrintPreCompleteSummary

func (up *UpgradePlan) PrintPreCompleteSummary(out io.Writer) error

func (*UpgradePlan) Validate

func (up *UpgradePlan) Validate() error

type UpgradeStatus

type UpgradeStatus struct {
	Appliance *Appliance
}

func (*UpgradeStatus) WaitForUpgradeStatus

func (u *UpgradeStatus) WaitForUpgradeStatus(ctx context.Context, appliance openapi.Appliance, desiredStatuses []string, undesiredStatuses []string, tracker *tui.Tracker) error

type UpgradeStatusResult

type UpgradeStatusResult struct {
	Status, Details, Name string
}

type WaitForApplianceStatus

type WaitForApplianceStatus interface {
	WaitForApplianceState(ctx context.Context, appliance openapi.Appliance, want []string, tracker *tui.Tracker) error
	// WaitForStatus tries appliance stats until the appliance has want status or it reaches the timeout
	WaitForApplianceStatus(ctx context.Context, appliance openapi.Appliance, want []string, tracker *tui.Tracker) error
}

type WaitForUpgradeStatus

type WaitForUpgradeStatus interface {
	// WaitForUpgradeStatus does exponential backoff retries on upgrade status until it reaches a desiredStatuses and reports it to current <- string
	WaitForUpgradeStatus(ctx context.Context, appliance openapi.Appliance, desiredStatuses []string, undesiredStatuses []string, tracker *tui.Tracker) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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