Documentation
¶
Overview ¶
Package hyperv contains pure PowerShell/XML builders and parsers for the LabLink VM-management tools. It deliberately has NO dependency on mcp-go, gRPC, or the rest of the server so the script/XML construction can be unit tested in isolation (Heimdall review §3 layering requirement).
Every script emitted here is "argument safe": caller-supplied values are emitted as single-quoted PowerShell literals via PSLit / PSBool, never interpolated directly into a command line. This matches the existing escapePSString convention in internal/mcptools/deploy.go and the network reviewer's "argument-safe construction" requirement.
Index ¶
- func BuildCreateVMScript(p CreateVMParams) (string, error)
- func BuildCreateVSwitchScript(p CreateVSwitchParams) (string, error)
- func BuildDeleteVMScript(p DeleteVMParams) (string, error)
- func BuildListNicsScript(includeVirtual bool, mgmtIP string) string
- func BuildListVSwitchesScript() string
- func EscapePS(s string) string
- func PSBool(b bool) string
- func PSLit(s string) string
- func PreflightScript() string
- func WrapTagged(body string) string
- type CreateVMParams
- type CreateVSwitchParams
- type DeleteVMParams
- type NIC
- type VSwitch
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildCreateVMScript ¶
func BuildCreateVMScript(p CreateVMParams) (string, error)
BuildCreateVMScript builds the create_vm mutation script with the network reviewer's completeness items: Gen2 secure boot template, deterministic DVD selection by ISO path, dynamic-memory min/max/buffer, path + free-space validation, VM-off and VHD-not-in-use checks.
func BuildCreateVSwitchScript ¶
func BuildCreateVSwitchScript(p CreateVSwitchParams) (string, error)
BuildCreateVSwitchScript builds the create_vswitch mutation script with the management-NIC severance safeguard baked in. Returns an error for invalid param combinations that can be detected statically.
func BuildDeleteVMScript ¶ added in v0.6.1
func BuildDeleteVMScript(p DeleteVMParams) (string, error)
BuildDeleteVMScript builds a dry-run-first VM deletion script. Storage deletion is restricted to the VM's own configuration directory beneath the approved managed root. Differencing parent paths are reported but never deleted.
func BuildListNicsScript ¶
BuildListNicsScript builds the discovery script for physical NICs.
mgmtIP is the target-side IP address that the LabLink server uses to reach this host (the host part of the registry node Address). The NIC that owns that IP — or, failing an exact match, the NIC carrying the active default route — is flagged is_management_nic / management_risk so callers and the create_vswitch safeguard can avoid severing the agent connection. For a localhost target mgmtIP is empty and only the default-route NIC is flagged (lower risk: you own your own host).
func BuildListVSwitchesScript ¶
func BuildListVSwitchesScript() string
BuildListVSwitchesScript builds the discovery script for vSwitches.
func EscapePS ¶
EscapePS escapes a string for inclusion inside a PowerShell single-quoted literal by doubling embedded single quotes.
func PSLit ¶
PSLit renders s as a complete single-quoted PowerShell string literal, doubling any embedded single quotes (the standard PowerShell escape).
func PreflightScript ¶
func PreflightScript() string
PreflightScript returns the shared Test-LabLinkHyperV preamble that every mutating Hyper-V tool runs first. It verifies the Hyper-V PowerShell module is present and the caller is elevated, emitting a tagged error otherwise.
Enabling the Hyper-V role itself (Enable-WindowsOptionalFeature) requires a reboot and is out of scope for Phase 1 — we only detect-and-report.
func WrapTagged ¶
WrapTagged is the exported form of wrapTagged for sibling packages (e.g. internal/hyperv/unattend) that build their own script bodies but want the same single-tagged-line failure convention.
Types ¶
type CreateVMParams ¶
type CreateVMParams struct {
Name string
VMLocation string // -Path for VM config; empty unless UseHostDefaults
// Exactly one of VHDPath (attach existing) or NewVHDPath (+NewVHDSizeGB).
VHDPath string
NewVHDPath string
NewVHDSizeGB float64
MemoryMB float64 // startup memory (default applied by caller)
// Dynamic-memory policy. When DynamicMemory is true, Min/Max/Buffer apply.
DynamicMemory bool
DynamicMinMB float64
DynamicMaxMB float64
DynamicBufferPct float64
CPUCount float64
VSwitch string
ISOPath string
SecureBoot bool
SecureBootTemplate string // default MicrosoftWindows
UseHostDefaults bool // permit Hyper-V default VM location when VMLocation empty
RequiredFreeSpaceGB float64
}
CreateVMParams configures BuildCreateVMScript for a Gen2 Windows VM.
type CreateVSwitchParams ¶
type CreateVSwitchParams struct {
Name string
Type string // "external" | "internal" | "private"
NetAdapter string // required when Type == external
AllowManagementOS bool // default true (caller sets)
IfExists string // "reuse" (default) | "fail" | "replace"
// IsRemote is true when the target is a registered node (not localhost).
// On a remote target an external switch on the management NIC is BLOCKED
// unless AllowMgmtDisruption is true (network reviewer finding #1).
IsRemote bool
// AllowMgmtDisruption overrides the management-NIC safeguard.
AllowMgmtDisruption bool
// MgmtIP is the target-side IP the server uses to reach this host; used to
// identify the management NIC at runtime on the target.
MgmtIP string
}
CreateVSwitchParams configures BuildCreateVSwitchScript.
type DeleteVMParams ¶ added in v0.6.1
type NIC ¶
type NIC struct {
Name string `json:"name"`
InterfaceDescription string `json:"interface_description"`
MAC string `json:"mac"`
Status string `json:"status"`
LinkSpeed string `json:"link_speed"`
BoundVSwitch string `json:"bound_vswitch"`
IsManagementNIC bool `json:"is_management_nic"`
ManagementRisk bool `json:"management_risk"`
RecommendedExternal bool `json:"recommended_for_external"`
}
NIC is a parsed physical network adapter row from list_physical_nics.
type VSwitch ¶
type VSwitch struct {
Name string `json:"name"`
Type string `json:"type"`
NetAdapter string `json:"net_adapter"`
AllowManagementOS bool `json:"allow_management_os"`
}
VSwitch is a parsed Hyper-V virtual switch row.
func ParseVSwitches ¶
ParseVSwitches parses the JSON emitted by BuildListVSwitchesScript.