complexity

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

README

complexity package

Pure, stateless functions for scoring VM migration complexity. No dependency on the HTTP layer or database — designed to be unit-tested in isolation.

Score scale

Scores express how much effort a migration is expected to require. Two independent dimensions are scored: OS type and disk size.

Score Label Meaning
0 Unknown OS not recognised; complexity cannot be assessed
1 Easy Straightforward migration, minimal intervention expected
2 Medium Standard migration, some attention required
3 Hard Complex migration, significant effort expected
4 White Glove Requires manual intervention and special handling

OS scores run 0–4. Disk scores run 1–4 (unknown does not apply to disk size).


OS classification

ClassifyOS(osName string) Score performs case-insensitive substring matching against OSDifficultyScores. If no keyword matches, the OS receives score 0 (unknown).

The full keyword-to-score mapping:

Score 1 — Easy
OS family Matched versions
Red Hat Enterprise Linux 6, 7, 8, 9, 10
Red Hat Fedora all
CentOS 6, 7, 8, 9
Oracle Linux 6, 7, 8, 9
Rocky Linux 8, 9
Score 2 — Medium
OS family Matched versions
Red Hat Enterprise Linux 4, 5
CentOS 4, 5
Oracle Linux 4, 5
SUSE Linux Enterprise 12, 15
Microsoft Windows Server 2016, 2019, 2022, 2025
Microsoft Windows 10, 11
Score 3 — Hard
OS family Matched versions
SUSE Linux Enterprise 8, 9, 10, 11
SUSE openSUSE all
AlmaLinux 8, 9
Ubuntu Linux 18.04, 20.04, 22.04, 24.04, generic
Debian GNU/Linux 5–12
Microsoft Windows Server 2000, 2003, 2008, 2008 R2, 2012, 2012 R2
Microsoft Windows XP, Vista, 7, 8
Oracle Solaris 10, 11
FreeBSD all
VMware Photon OS all
Amazon Linux 2 all
CoreOS Linux all
Apple macOS all
Score 4 — White Glove
OS family Matched versions
Microsoft SQL all (database workload)
Score 0 — Unknown

Any OS name that does not match a keyword in the table above. Examples: "Other (64-bit)", "Other Linux (64-bit)", unrecognised custom distributions.


Disk size classification

ScoreDiskTierLabel(label string) Score maps the pre-computed tier labels produced by the agent (stored in vms.diskSizeTier) to numeric scores.

Tier label Size range Score
Easy (0-10TB) ≤ 10 TB provisioned 1
Medium (10-20TB) ≤ 20 TB provisioned 2
Hard (20-50TB) ≤ 50 TB provisioned 3
White Glove (>50TB) > 50 TB provisioned 4

DiskSizeRangeRatings() returns the same map with keys trimmed to the numeric range only (e.g. "0-10TB") for use in API responses.


Functions

Function Returns Description
ClassifyOS(osName) Score Score for a single OS name string
OSBreakdown(entries) []OSDifficultyEntry VM counts aggregated by score (0–4), always 5 entries
OSNameBreakdown(entries) []OSNameEntry One entry per distinct OS name with its score and VM count
OSRatings(entries) map[string]Score OS name → score map (no VM counts)
ScoreDiskTierLabel(label) Score Score for a single disk tier label
DiskBreakdown(tiers) []DiskComplexityEntry VM counts and total TB aggregated by score (1–4), always 4 entries
DiskSizeRangeRatings() map[string]Score Static tier label → score lookup with range-only keys

Documentation

Overview

Package complexity provides pure, stateless functions for scoring VM migration complexity. It has no dependency on the HTTP layer or database and is designed to be unit-tested in isolation.

Two independent scoring dimensions are supported:

  • OS complexity (scores 0–4): derived by substring-matching the VM's OS name against OSDifficultyScores. Score 1 is the least complex; score 0 means the OS is unknown and complexity can not be assessed.

  • Disk complexity (scores 1–4): derived from the pre-computed disk-size tier labels stored in the inventory by the agent. Score 1 is the least complex; score 4 is the most complex.

Index

Constants

This section is empty.

Variables

View Source
var DiskScores = []Score{1, 2, 3, 4}

DiskScores lists all valid disk complexity scores in canonical order.

View Source
var DiskSizeScores = map[string]Score{
	"Easy (0-10TB)":       1,
	"Medium (10-20TB)":    2,
	"Hard (20-50TB)":      3,
	"White Glove (>50TB)": 4,
}

DiskSizeScores maps the pre-computed inventory tier label strings (produced by the agent) to numeric complexity scores. The thresholds follow complexity.md:

Score 1 — provisioned disk ≤ 10 TB
Score 2 — provisioned disk ≤ 20 TB
Score 3 — provisioned disk ≤ 50 TB
Score 4 — provisioned disk  > 50 TB

Edit this map to adjust disk complexity scoring.

View Source
var OSDifficultyScores = map[string]Score{

	"Red Hat Enterprise Linux 4":  2,
	"Red Hat Enterprise Linux 5":  2,
	"Red Hat Enterprise Linux 6":  1,
	"Red Hat Enterprise Linux 7":  1,
	"Red Hat Enterprise Linux 8":  1,
	"Red Hat Enterprise Linux 9":  1,
	"Red Hat Enterprise Linux 10": 1,
	"Red Hat Fedora":              1,

	"CentOS 4": 2,
	"CentOS 5": 2,
	"CentOS 6": 1,
	"CentOS 7": 1,
	"CentOS 8": 1,
	"CentOS 9": 1,

	"Oracle Linux 4": 2,
	"Oracle Linux 5": 2,
	"Oracle Linux 6": 1,
	"Oracle Linux 7": 1,
	"Oracle Linux 8": 1,
	"Oracle Linux 9": 1,

	"Rocky Linux 8": 1,
	"Rocky Linux 9": 1,

	"AlmaLinux 8": 3,
	"AlmaLinux 9": 3,

	"SUSE Linux Enterprise 8":  3,
	"SUSE Linux Enterprise 9":  3,
	"SUSE Linux Enterprise 10": 3,
	"SUSE Linux Enterprise 11": 3,
	"SUSE Linux Enterprise 12": 2,
	"SUSE Linux Enterprise 15": 2,
	"SUSE openSUSE":            3,

	"Ubuntu Linux 18.04": 3,
	"Ubuntu Linux 20.04": 3,
	"Ubuntu Linux 22.04": 3,
	"Ubuntu Linux 24.04": 3,
	"Ubuntu Linux":       3,

	"Debian GNU/Linux 5":  3,
	"Debian GNU/Linux 6":  3,
	"Debian GNU/Linux 7":  3,
	"Debian GNU/Linux 8":  3,
	"Debian GNU/Linux 9":  3,
	"Debian GNU/Linux 10": 3,
	"Debian GNU/Linux 11": 3,
	"Debian GNU/Linux 12": 3,

	"Microsoft Windows Server 2000":    3,
	"Microsoft Windows Server 2003":    3,
	"Microsoft Windows Server 2008 R2": 3,
	"Microsoft Windows Server 2008":    3,
	"Microsoft Windows Server 2012 R2": 3,
	"Microsoft Windows Server 2012":    3,
	"Microsoft Windows Server 2016":    2,
	"Microsoft Windows Server 2019":    2,
	"Microsoft Windows Server 2022":    2,
	"Microsoft Windows Server 2025":    2,

	"Microsoft Windows XP":    3,
	"Microsoft Windows Vista": 3,
	"Microsoft Windows 7":     3,
	"Microsoft Windows 8":     3,
	"Microsoft Windows 10":    2,
	"Microsoft Windows 11":    2,

	"Oracle Solaris 10": 3,
	"Oracle Solaris 11": 3,

	"FreeBSD": 3,

	"VMware Photon OS": 3,
	"Amazon Linux 2":   3,
	"CoreOS Linux":     3,
	"Apple macOS":      3,

	"Microsoft SQL": 4,
}

OSDifficultyScores maps OS name substrings to numeric complexity scores. ClassifyOS checks whether each key is a case-insensitive substring of the VM's OS name.

When multiple keys match the same OS name, all matching keys carry the same score, so non-deterministic map iteration order does not affect the result.

Score semantics:

0 = unknown (no key matched)
1 = score 1 easiest
2 = score 2
3 = score 3
4 = score 4 hardest
View Source
var OSScores = []Score{0, 1, 2, 3, 4}

OSScores lists all valid OS complexity scores in canonical order.

Functions

func DiskSizeRangeRatings

func DiskSizeRangeRatings() map[string]Score

DiskSizeRangeRatings returns the DiskSizeScores map with keys reformatted to contain only the numeric range portion of each tier label (e.g. "Easy (0-10TB)" becomes "0-10TB"). Use this when exposing the lookup table in API responses so that UI-level label words ("Easy", "Hard", etc.) do not bleed into the data layer.

func OSRatings

func OSRatings(osEntries []VMOsEntry) map[string]Score

OSRatings returns a map from OS name to complexity score for every entry in the given slice. Each name is classified via ClassifyOS. Callers can use this map to show per-OS score annotations alongside the aggregate OSBreakdown result.

Types

type DiskComplexityEntry

type DiskComplexityEntry struct {
	Score       Score
	VMCount     int
	TotalSizeTB float64
}

DiskComplexityEntry is one row in the disk complexity breakdown.

func DiskBreakdown

func DiskBreakdown(tiers []DiskTierInput) []DiskComplexityEntry

DiskBreakdown maps pre-computed inventory tier labels to numeric scores and returns a slice of DiskComplexityEntry in canonical score order (1–4). All four scores are always present; absent scores carry VMCount == 0 and TotalSizeTB == 0.

type DiskTierInput

type DiskTierInput struct {
	Label       string // Tier label as stored in the inventory (key in vms.diskSizeTier)
	VMCount     int
	TotalSizeTB float64
}

DiskTierInput represents a pre-computed disk size tier from the inventory.

type OSDifficultyEntry

type OSDifficultyEntry struct {
	Score   Score
	VMCount int
}

OSDifficultyEntry is one row in the OS complexity breakdown.

func OSBreakdown

func OSBreakdown(osEntries []VMOsEntry) []OSDifficultyEntry

OSBreakdown classifies each OS entry by numeric score and returns a slice of OSDifficultyEntry in canonical score order (0–4). All five scores are always present; absent scores carry VMCount == 0.

type OSNameEntry added in v0.8.0

type OSNameEntry struct {
	Name    string // OS name as reported by VMware
	Score   Score
	VMCount int
}

OSNameEntry is one row in the per-OS-name complexity breakdown.

func OSNameBreakdown added in v0.8.0

func OSNameBreakdown(osEntries []VMOsEntry) []OSNameEntry

OSNameBreakdown returns one OSNameEntry per distinct OS name in osEntries.

type Score

type Score = int

Score is a numeric complexity level. Lower values indicate simpler migrations. OS scores run 0–4; disk scores run 1–4.

func ClassifyOS

func ClassifyOS(osName string) Score

ClassifyOS returns the numeric complexity score for the given OS name by checking whether each key in OSDifficultyScores appears as a case-insensitive substring of osName. Returns 0 if no key matches (unknown).

func ScoreDiskTierLabel

func ScoreDiskTierLabel(label string) Score

ScoreDiskTierLabel returns the numeric score for an inventory disk tier label. Returns 0 if the label is not in DiskSizeScores.

type VMOsEntry

type VMOsEntry struct {
	Name  string // OS name as reported by VMware (e.g., "Red Hat Enterprise Linux 8 (64-bit)")
	Count int    // Number of VMs running this OS
}

VMOsEntry represents a single OS in the inventory with its VM count.

Jump to

Keyboard shortcuts

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