hyperv

package
v0.9.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 11 Imported by: 0

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

Constants

View Source
const (
	IsolatedMetadataSchema             = 1
	IsolatedOrchestratorMetadataPrefix = "LABLINK_ISOLATED_ORCHESTRATOR:"
	IsolatedVMMetadataPrefix           = "LABLINK_ISOLATED_VM:"
	IsolatedOwnerMarkerPrefix          = "lablink-isolated/"
)
View Source
const (
	HyperVVMGroupSID          = "S-1-5-83-0"
	HyperVWorkerCapabilitySID = "S-1-15-3-1024-2268835264-3721307629-241982045-173645152-1490879176-104643441-2915960892-1612460704"
	LinuxVMMetadataPrefix     = "LABLINK_MANAGED_VM:"
	LinuxVMOwnershipFile      = ".lablink-linux-vm-ownership.json"
	LinuxVMOwnershipSchema    = 2
	LinuxVMCleanupAttached    = "cidata_attached"
	LinuxVMCleanupDetached    = "cidata_detached"
	LinuxVMCleanupComplete    = "complete"
	LinuxVMMetadataSchema     = 2
)
View Source
const LinuxImageBuilderMetadataPrefix = "LABLINK_LINUX_IMAGE_BUILDER_V1:"

Variables

This section is empty.

Functions

func BuildAcquireIsolatedHostLockScript

func BuildAcquireIsolatedHostLockScript(p IsolatedHostLeaseParams) (string, error)

func BuildAttachIsolatedNICScript

func BuildAttachIsolatedNICScript(p AttachIsolatedNICParams) (string, error)

func BuildCIDATAISOScript added in v0.7.0

func BuildCIDATAISOScript(p CIDATAISOParams) (string, error)

BuildCIDATAISOScript creates a standard NoCloud seed ISO with Windows IMAPI2FS. Every seed and payload file remains at the ISO root.

func BuildClaimIsolatedVMScript

func BuildClaimIsolatedVMScript(p ClaimIsolatedVMParams) (string, error)

func BuildCleanupIsolatedNetworkMetadataScript

func BuildCleanupIsolatedNetworkMetadataScript(
	p CleanupIsolatedNetworkMetadataParams,
) (string, error)

func BuildCleanupIsolatedOrchestratorMetadataScript

func BuildCleanupIsolatedOrchestratorMetadataScript(
	p CleanupIsolatedOrchestratorMetadataParams,
) (string, error)

func BuildCleanupLinuxVMStageScript added in v0.7.0

func BuildCleanupLinuxVMStageScript(p LinuxVMOwnershipParams) (string, error)

func BuildCleanupOwnedLinuxVMArtifactsScript added in v0.7.0

func BuildCleanupOwnedLinuxVMArtifactsScript(p CleanupOwnedLinuxVMArtifactsParams) (string, error)

func BuildConfigureExistingLinuxVMScript added in v0.7.0

func BuildConfigureExistingLinuxVMScript(p ConfigureExistingLinuxVMParams) (string, error)

func BuildCreateIsolatedPrivateSwitchScript

func BuildCreateIsolatedPrivateSwitchScript(p CreateIsolatedPrivateSwitchParams) (string, error)

func BuildCreateLinuxVMScript added in v0.7.0

func BuildCreateLinuxVMScript(p CreateLinuxVMParams) (string, error)

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 BuildDeleteIsolatedOrchestratorVMScript

func BuildDeleteIsolatedOrchestratorVMScript(
	p DeleteIsolatedOrchestratorVMParams,
) (string, error)

func BuildDeleteIsolatedPrivateSwitchScript

func BuildDeleteIsolatedPrivateSwitchScript(p DeleteIsolatedPrivateSwitchParams) (string, error)

func BuildDeleteIsolatedVMScript

func BuildDeleteIsolatedVMScript(p DeleteIsolatedVMParams) (string, error)

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 BuildDiscoverIsolatedHostScript

func BuildDiscoverIsolatedHostScript(p IsolatedDiscoveryParams) (string, error)

func BuildInspectIsolatedVMScript

func BuildInspectIsolatedVMScript(p InspectIsolatedVMParams) (string, error)

func BuildInspectLinuxImageBuilderScript added in v0.7.0

func BuildInspectLinuxImageBuilderScript(name string, expected LinuxImageBuilderMetadata) (string, error)

func BuildInspectVMManagementScript added in v0.7.0

func BuildInspectVMManagementScript(name string) (string, error)

func BuildLinuxImageAcquireLockScript added in v0.7.0

func BuildLinuxImageAcquireLockScript(p LinuxImageLockParams) (string, error)

func BuildLinuxImageBuilderAcquireLockScript added in v0.7.0

func BuildLinuxImageBuilderAcquireLockScript(p LinuxImageBuilderLockParams) (string, error)

func BuildLinuxImageBuilderAttachScript added in v0.7.0

func BuildLinuxImageBuilderAttachScript(p LinuxImageBuilderAttachParams) (string, error)

func BuildLinuxImageBuilderDetachScript added in v0.7.0

func BuildLinuxImageBuilderDetachScript(p LinuxImageBuilderDetachParams) (string, error)

func BuildLinuxImageBuilderInventoryScript added in v0.7.0

func BuildLinuxImageBuilderInventoryScript(statePath string) (string, error)

func BuildLinuxImageBuilderReleaseLockScript added in v0.7.0

func BuildLinuxImageBuilderReleaseLockScript(p LinuxImageBuilderLockParams) (string, error)

func BuildLinuxImageBuilderSetupScript added in v0.7.0

func BuildLinuxImageBuilderSetupScript(statePath string) (string, error)

func BuildLinuxImageBuilderSourcePreflightScript added in v0.7.0

func BuildLinuxImageBuilderSourcePreflightScript(baseVHD, vmRoot, vswitch string) (string, error)

func BuildLinuxImageBuilderStartScript added in v0.7.0

func BuildLinuxImageBuilderStartScript(name string) (string, error)

func BuildLinuxImageBuilderTransformScript added in v0.7.0

func BuildLinuxImageBuilderTransformScript(p LinuxImageBuilderTransformParams) (string, error)

func BuildLinuxImageBuilderUserTaskScript added in v0.7.0

func BuildLinuxImageBuilderUserTaskScript(payload string, timeoutSeconds int) (string, error)

func BuildLinuxImageConvertScript added in v0.7.0

func BuildLinuxImageConvertScript(p LinuxImageConvertParams) (string, error)

func BuildLinuxImageDownloadScript added in v0.7.0

func BuildLinuxImageDownloadScript(p LinuxImageDownloadParams) (string, error)

func BuildLinuxImageHashScript added in v0.7.0

func BuildLinuxImageHashScript(path string) (string, error)

func BuildLinuxImagePrerequisiteProbeScript added in v0.7.0

func BuildLinuxImagePrerequisiteProbeScript() (string, error)

func BuildLinuxImagePublishScript added in v0.7.0

func BuildLinuxImagePublishScript(p LinuxImagePublishParams) (string, error)

func BuildLinuxImageRecordBuilderScript added in v0.7.0

func BuildLinuxImageRecordBuilderScript(statePath, profile, vmName, nodeName string) (string, error)

func BuildLinuxImageReleaseLockScript added in v0.7.0

func BuildLinuxImageReleaseLockScript(p LinuxImageLockParams) (string, error)

func BuildLinuxImageStatusScript added in v0.7.0

func BuildLinuxImageStatusScript(cacheRoot string, diskSizeGB int) (string, error)

func BuildLinuxImageVerifyScript added in v0.7.0

func BuildLinuxImageVerifyScript(p LinuxImageVerifyParams) (string, error)

func BuildLinuxVMAcquireLockScript added in v0.7.0

func BuildLinuxVMAcquireLockScript(p LinuxVMLockParams) (string, error)

func BuildLinuxVMCIDATACleanupScript added in v0.7.0

func BuildLinuxVMCIDATACleanupScript(name, isoPath string) (string, error)

func BuildLinuxVMReleaseLockScript added in v0.7.0

func BuildLinuxVMReleaseLockScript(p LinuxVMLockParams) (string, error)

func BuildLinuxVMStartAndDiscoverScript added in v0.7.0

func BuildLinuxVMStartAndDiscoverScript(name string) (string, error)

func BuildListNicsScript

func BuildListNicsScript(includeVirtual bool, mgmtIP string) string

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 BuildPersistLinuxVMOwnershipScript added in v0.7.0

func BuildPersistLinuxVMOwnershipScript(p LinuxVMOwnershipParams) (string, error)

func BuildPhysicalHostIdentityScript

func BuildPhysicalHostIdentityScript() string

func BuildPrepareLinuxVMStageScript added in v0.7.0

func BuildPrepareLinuxVMStageScript(p LinuxVMOwnershipParams) (string, error)

func BuildReadLinuxVMMetadataScript added in v0.7.0

func BuildReadLinuxVMMetadataScript(name string) (string, error)

func BuildRebindIsolatedParentFenceScript

func BuildRebindIsolatedParentFenceScript(p RebindIsolatedParentFenceParams) (string, error)

BuildRebindIsolatedParentFenceScript installs a reclaimed host lease/fence in the exact orchestrator VM metadata. Frozen/deleting parents retain their unchanged approved enumeration while its lease and fence are rebound.

func BuildReconcileIsolatedAdapterMetadataScript

func BuildReconcileIsolatedAdapterMetadataScript(
	p ReconcileIsolatedAdapterMetadataParams,
) (string, error)

func BuildReconcileLinuxVMArtifactsScript added in v0.7.0

func BuildReconcileLinuxVMArtifactsScript(p ReconcileLinuxVMArtifactsParams) (string, error)

func BuildReconcileStaleIsolatedMetadataScript

func BuildReconcileStaleIsolatedMetadataScript(
	p ReconcileStaleIsolatedMetadataParams,
) (string, error)

func BuildReleaseIsolatedHostLockScript

func BuildReleaseIsolatedHostLockScript(p IsolatedHostLeaseParams) (string, error)

func BuildRemoveIsolatedNICScript

func BuildRemoveIsolatedNICScript(p RemoveIsolatedNICParams) (string, error)

func BuildRenewIsolatedHostLockScript

func BuildRenewIsolatedHostLockScript(p IsolatedHostLeaseParams) (string, error)

func BuildResourceSafetyScript added in v0.6.2

func BuildResourceSafetyScript(p ResourceSafetyParams) (string, error)

func BuildSetIsolatedParentLifecycleScript

func BuildSetIsolatedParentLifecycleScript(p SetIsolatedParentLifecycleParams) (string, error)

func BuildSetLinuxVMRegistrationScript added in v0.7.0

func BuildSetLinuxVMRegistrationScript(name string, registered bool) (string, error)

func BuildStartIsolatedVMScript

func BuildStartIsolatedVMScript(p StartIsolatedVMParams) (string, error)

func BuildValidateExistingLinuxVMStorageScript added in v0.7.0

func BuildValidateExistingLinuxVMStorageScript(name string, expected LinuxVMMetadata) (string, error)

func DeterministicIsolatedMAC

func DeterministicIsolatedMAC(resourceID string) (string, error)

DeterministicIsolatedMAC returns a locally administered unicast MAC in the format accepted by Hyper-V's StaticMacAddress parameter.

func EscapePS

func EscapePS(s string) string

EscapePS escapes a string for inclusion inside a PowerShell single-quoted literal by doubling embedded single quotes.

func IsolatedOwnerMarker

func IsolatedOwnerMarker(orchestratorID, resourceType, resourceID string) (string, error)

func LinuxImageBuilderManagedMetadata added in v0.7.0

func LinuxImageBuilderManagedMetadata(m LinuxImageBuilderMetadata) (string, error)

func MarshalIsolatedAdapterMetadata

func MarshalIsolatedAdapterMetadata(metadata IsolatedAdapterMetadata) (string, error)

func MarshalIsolatedNetworkMetadata

func MarshalIsolatedNetworkMetadata(metadata IsolatedNetworkMetadata) (string, error)

func MarshalIsolatedOrchestratorMetadata

func MarshalIsolatedOrchestratorMetadata(metadata IsolatedOrchestratorMetadata) (string, error)

func MarshalIsolatedVMMetadata

func MarshalIsolatedVMMetadata(metadata IsolatedVMMetadata) (string, error)

func MarshalLinuxVMMetadata added in v0.7.0

func MarshalLinuxVMMetadata(metadata LinuxVMMetadata) (string, error)

func PSBool

func PSBool(b bool) string

PSBool renders a Go bool as a PowerShell boolean literal.

func PSLit

func PSLit(s string) string

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 ReconcileUncertainAdapterCreate

func ReconcileUncertainAdapterCreate(expected IsolatedAdapterMetadata, observations []IsolatedAdapterObservation) (UncertainCreateDecision, *IsolatedAdapterObservation, error)

ReconcileUncertainAdapterCreate uses VM GUID, adapter ID metadata, static MAC, and switch GUID. It never adopts a same-name adapter by name alone.

func ReconcileUncertainSwitchCreate

func ReconcileUncertainSwitchCreate(expected IsolatedNetworkMetadata, observations []IsolatedSwitchObservation) (UncertainCreateDecision, *IsolatedSwitchObservation, error)

ReconcileUncertainSwitchCreate decides whether a lost create result can be adopted. Name equality alone never authorizes adoption.

func ResourceSafetyScript added in v0.6.2

func ResourceSafetyScript(p ResourceSafetyParams) (string, error)

ResourceSafetyScript returns a PowerShell fragment that populates $resourceSafety and throws before mutation when projected free memory or target-volume capacity would fall below the configured reserve.

func WrapTagged

func WrapTagged(body string) string

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 AttachIsolatedNICParams

type AttachIsolatedNICParams struct {
	Guard              IsolatedMutationGuard
	NetworkID          string
	ResourceType       string
	ResourceID         string
	OrchestratorVMGUID string
	VMGUID             string
	AdapterName        string
	ExpectedAdapterID  string
	SwitchGUID         string
	MAC                string
	Generation         int64
}

type CIDATAISOParams added in v0.7.0

type CIDATAISOParams struct {
	SourceDir     string
	ISOPath       string
	OwnershipPath string
}

type CascadeAuthority

type CascadeAuthority struct {
	OrchestratorID   string                 `json:"orchestrator_id"`
	FrozenGeneration int64                  `json:"frozen_generation"`
	OperationID      string                 `json:"operation_id"`
	PlanRevision     string                 `json:"plan_revision"`
	PlanHash         string                 `json:"plan_hash"`
	HostFence        int64                  `json:"host_fence"`
	LeaseID          string                 `json:"lease_id"`
	Items            []CascadeAuthorityItem `json:"items"`
}

CascadeAuthority is the revision-bound cleanup capability installed when an orchestrator is frozen. It authorizes only the enumerated actions.

type CascadeAuthorityItem

type CascadeAuthorityItem struct {
	ResourceType string             `json:"resource_type"`
	ResourceID   string             `json:"resource_id"`
	Action       cascadeauth.Action `json:"action"`
	Generation   int64              `json:"generation"`
	SwitchGUID   string             `json:"switch_guid,omitempty"`
	VMGUID       string             `json:"vm_guid,omitempty"`
	AdapterID    string             `json:"adapter_id,omitempty"`
	Completed    bool               `json:"completed"`
}

type ClaimIsolatedVMParams

type ClaimIsolatedVMParams struct {
	Guard              IsolatedMutationGuard
	OrchestratorVMGUID string
	VMName             string
	SwitchGUID         string
	AdapterName        string
	MAC                string
	Metadata           IsolatedVMMetadata
}

type CleanupIsolatedNetworkMetadataParams

type CleanupIsolatedNetworkMetadataParams struct {
	Guard              IsolatedMutationGuard
	OrchestratorVMGUID string
	NetworkID          string
	AdapterID          string
	AdapterName        string
	SwitchGUID         string
	SwitchName         string
	MAC                string
	Generation         int64
}

type CleanupIsolatedOrchestratorMetadataParams

type CleanupIsolatedOrchestratorMetadataParams struct {
	Guard              IsolatedMutationGuard
	OrchestratorVMGUID string
	HyperVName         string
}

type CleanupOwnedLinuxVMArtifactsParams added in v0.7.0

type CleanupOwnedLinuxVMArtifactsParams struct {
	ISOPath   string
	ChildVHDX string
	DeleteISO bool
	DeleteVHD bool
}

type ConfigureExistingLinuxVMParams added in v0.7.0

type ConfigureExistingLinuxVMParams struct {
	Name             string
	Metadata         LinuxVMMetadata
	Ownership        LinuxVMOwnership
	MemoryMB         float64
	CPUCount         float64
	DynamicMemory    bool
	DynamicMinMB     float64
	DynamicMaxMB     float64
	DynamicBufferPct float64
}

type CreateIsolatedPrivateSwitchParams

type CreateIsolatedPrivateSwitchParams struct {
	Guard              IsolatedMutationGuard
	OrchestratorVMGUID string
	Metadata           IsolatedNetworkMetadata
}

type CreateLinuxVMParams added in v0.7.0

type CreateLinuxVMParams struct {
	Name                      string
	VMLocation                string
	ParentVHDX                string
	ChildVHDX                 string
	ISOPath                   string
	VSwitch                   string
	MemoryMB                  float64
	CPUCount                  float64
	DynamicMemory             bool
	DynamicMinMB              float64
	DynamicMaxMB              float64
	DynamicBufferPct          float64
	DiskSizeGB                float64
	MinHostReservePct         float64
	AllowHostResourcePressure bool
	ManagedMetadata           string
}

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
	MinHostReservePct                 float64
	AllowHostResourcePressure         bool
	ExposeVirtualizationExtensions    bool
	VirtualizationBasedSecurityOptOut bool
	CreationOwnershipMarker           string
	ManagedMetadata                   string
}

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 DeleteIsolatedOrchestratorVMParams

type DeleteIsolatedOrchestratorVMParams struct {
	Guard              IsolatedMutationGuard
	OrchestratorVMGUID string
	HyperVName         string
	ExpectedGeneration int64
	ManagedRoot        string
	ExpectedParentVHDX string
	ForceStop          bool
	DeleteStorage      bool
}

type DeleteIsolatedPrivateSwitchParams

type DeleteIsolatedPrivateSwitchParams struct {
	Guard              IsolatedMutationGuard
	OrchestratorVMGUID string
	NetworkID          string
	SwitchName         string
	ExpectedSwitchGUID string
	ExpectedGeneration int64
}

type DeleteIsolatedVMParams

type DeleteIsolatedVMParams struct {
	Guard              IsolatedMutationGuard
	OrchestratorVMGUID string
	VMName             string
	ExpectedVMID       string
	ExpectedVMGUID     string
	ExpectedAdapterID  string
	ExpectedVHDPath    string
	ExpectedVMPath     string
	ExpectedCIDATAPath string
	ExpectedOwnership  string
	DeleteStorage      bool
}

type DeleteVMParams added in v0.6.1

type DeleteVMParams struct {
	Name               string
	ManagedRoot        string
	DryRun             bool
	ForceStop          bool
	DeleteStorage      bool
	ExpectedParentVHDX string
	ExpectedVMGUID     string
}

type InspectIsolatedVMParams

type InspectIsolatedVMParams struct {
	VMName       string
	ExpectedVMID string
	ExpectedGUID string
}

type IsolatedAdapterMetadata

type IsolatedAdapterMetadata struct {
	SchemaVersion  int    `json:"schema_version"`
	PhysicalHostID string `json:"physical_host_id"`
	OrchestratorID string `json:"orchestrator_id"`
	NetworkID      string `json:"network_id"`
	ResourceID     string `json:"resource_id"`
	ResourceType   string `json:"resource_type"`
	OwnerMarker    string `json:"owner_marker"`
	HostFence      int64  `json:"host_fence"`
	MutationID     string `json:"mutation_id"`
	Generation     int64  `json:"generation"`
	State          string `json:"state"`
	VMGUID         string `json:"vm_guid"`
	AdapterName    string `json:"adapter_name"`
	AdapterID      string `json:"adapter_id,omitempty"`
	MAC            string `json:"mac"`
	SwitchGUID     string `json:"switch_guid"`
}

type IsolatedAdapterMutationResult

type IsolatedAdapterMutationResult struct {
	Action      string `json:"action"`
	ResourceID  string `json:"resource_id"`
	VMGUID      string `json:"vm_guid"`
	AdapterName string `json:"adapter_name"`
	AdapterID   string `json:"adapter_id"`
	SwitchGUID  string `json:"switch_guid"`
	MAC         string `json:"mac"`
	Generation  int64  `json:"generation"`
}

func ParseIsolatedAdapterMutationResult

func ParseIsolatedAdapterMutationResult(text string) (IsolatedAdapterMutationResult, error)

type IsolatedAdapterObservation

type IsolatedAdapterObservation struct {
	VMName        string                   `json:"vm_name"`
	VMGUID        string                   `json:"vm_guid"`
	Name          string                   `json:"name"`
	AdapterID     string                   `json:"adapter_id"`
	MAC           string                   `json:"mac"`
	SwitchName    string                   `json:"switch_name"`
	SwitchGUID    string                   `json:"switch_guid"`
	DynamicMAC    bool                     `json:"dynamic_mac"`
	OwnershipPath string                   `json:"ownership_path,omitempty"`
	Ownership     *IsolatedAdapterMetadata `json:"ownership,omitempty"`
}

type IsolatedAdapterRef

type IsolatedAdapterRef struct {
	NetworkID  string `json:"network_id"`
	AdapterID  string `json:"adapter_id"`
	MAC        string `json:"mac"`
	SwitchGUID string `json:"switch_guid"`
}

type IsolatedDiscoveryParams

type IsolatedDiscoveryParams struct {
	OrchestratorID       string
	OrchestratorVMGUID   string
	MaxSyntheticAdapters int
}

type IsolatedHostDiscovery

type IsolatedHostDiscovery struct {
	Host           IsolatedPhysicalHostObservation `json:"host"`
	Routes         []IsolatedRouteObservation      `json:"routes"`
	Capacity       *IsolatedNICCapacityObservation `json:"capacity,omitempty"`
	Switches       []IsolatedSwitchObservation     `json:"switches"`
	VMs            []IsolatedVMObservation         `json:"vms"`
	Adapters       []IsolatedAdapterObservation    `json:"adapters"`
	MetadataErrors []string                        `json:"metadata_errors"`
}

func ParseIsolatedHostDiscovery

func ParseIsolatedHostDiscovery(text string) (IsolatedHostDiscovery, error)

type IsolatedHostLeaseParams

type IsolatedHostLeaseParams struct {
	PhysicalHostID  string
	LeaseID         string
	LeaseSecret     string
	HolderIdentity  string
	OperationID     string
	DurationSeconds int
	Fence           int64
}

type IsolatedHostLeaseResult

type IsolatedHostLeaseResult struct {
	Status             string `json:"status"`
	Acquired           bool   `json:"acquired"`
	Renewed            bool   `json:"renewed"`
	Reclaimed          bool   `json:"reclaimed"`
	Released           bool   `json:"released"`
	LeaseID            string `json:"lease_id"`
	Fence              int64  `json:"fence"`
	ExpiresUTC         string `json:"expires_utc"`
	CurrentLeaseID     string `json:"current_lease_id,omitempty"`
	CurrentOperationID string `json:"current_operation_id,omitempty"`
	CurrentFence       int64  `json:"current_fence,omitempty"`
	CurrentExpiresUTC  string `json:"current_expires_utc,omitempty"`
}

func ParseIsolatedHostLeaseResult

func ParseIsolatedHostLeaseResult(text string) (IsolatedHostLeaseResult, error)

type IsolatedLockLevel

type IsolatedLockLevel int
const (
	IsolatedLockHost IsolatedLockLevel = iota + 1
	IsolatedLockOrchestrator
	IsolatedLockAllocation
	IsolatedLockNetwork
	IsolatedLockVM
	IsolatedLockChild
)

type IsolatedMetadataCleanupResult

type IsolatedMetadataCleanupResult struct {
	Action          string `json:"action"`
	OrchestratorID  string `json:"orchestrator_id"`
	NetworkID       string `json:"network_id,omitempty"`
	FilesRemoved    int    `json:"files_removed"`
	RootRemoved     bool   `json:"root_removed"`
	MetadataExisted bool   `json:"metadata_existed"`
}

func ParseIsolatedMetadataCleanupResult

func ParseIsolatedMetadataCleanupResult(text string) (IsolatedMetadataCleanupResult, error)

type IsolatedMutationGuard

type IsolatedMutationGuard struct {
	PhysicalHostID   string
	LeaseID          string
	LeaseSecret      string
	Fence            int64
	OrchestratorID   string
	OperationID      string
	MutationID       string
	ResourceType     string
	ResourceID       string
	Action           string
	CascadeAuthority *CascadeAuthority
}

type IsolatedNICCapacityObservation

type IsolatedNICCapacityObservation struct {
	VMGUID                 string `json:"vm_guid"`
	MaxSyntheticAdapters   int    `json:"max_synthetic_adapters"`
	MainAdapters           int    `json:"main_adapters"`
	ManagedPrivateAdapters int    `json:"managed_private_adapters"`
	OtherAdapters          int    `json:"other_adapters"`
	AvailablePrivateSlots  int    `json:"available_private_slots"`
}

type IsolatedNetworkMetadata

type IsolatedNetworkMetadata struct {
	SchemaVersion         int    `json:"schema_version"`
	PhysicalHostID        string `json:"physical_host_id"`
	OrchestratorID        string `json:"orchestrator_id"`
	NetworkID             string `json:"network_id"`
	OwnerMarker           string `json:"owner_marker"`
	HostFence             int64  `json:"host_fence"`
	MutationID            string `json:"mutation_id"`
	Generation            int64  `json:"generation"`
	State                 string `json:"state"`
	SwitchName            string `json:"switch_name"`
	SwitchGUID            string `json:"switch_guid,omitempty"`
	OrchestratorVMGUID    string `json:"orchestrator_vm_guid,omitempty"`
	OrchestratorAdapter   string `json:"orchestrator_adapter_name,omitempty"`
	OrchestratorAdapterID string `json:"orchestrator_adapter_id,omitempty"`
	OrchestratorMAC       string `json:"orchestrator_mac,omitempty"`
}

IsolatedNetworkMetadata is the host-side ownership record for one private switch and its orchestrator adapter.

func ParseIsolatedNetworkMetadata

func ParseIsolatedNetworkMetadata(data string) (IsolatedNetworkMetadata, error)

type IsolatedOrchestratorMetadata

type IsolatedOrchestratorMetadata struct {
	SchemaVersion    int                  `json:"schema_version"`
	PhysicalHostID   string               `json:"physical_host_id"`
	OrchestratorID   string               `json:"orchestrator_id"`
	OwnerMarker      string               `json:"owner_marker"`
	HostFence        int64                `json:"host_fence"`
	LifecycleState   string               `json:"lifecycle_state"`
	ManagedRoot      string               `json:"managed_root"`
	ExpectedVHDPaths []string             `json:"expected_vhd_paths"`
	NodeName         string               `json:"node_name"`
	VMGUID           string               `json:"vm_guid"`
	Generation       int64                `json:"generation"`
	PrivateAdapters  []IsolatedAdapterRef `json:"private_adapters,omitempty"`
	CascadeAuthority *CascadeAuthority    `json:"cascade_authority,omitempty"`
}

IsolatedOrchestratorMetadata is persisted in the orchestrator VM Notes. Physical IDs and infrastructure IDs are immutable reconciliation keys; display names are deliberately absent.

func ParseIsolatedOrchestratorMetadata

func ParseIsolatedOrchestratorMetadata(notes string) (IsolatedOrchestratorMetadata, error)

type IsolatedPhysicalHostObservation

type IsolatedPhysicalHostObservation struct {
	PhysicalHostID    string `json:"physical_host_id"`
	MachineGUID       string `json:"machine_guid"`
	SMBIOSUUID        string `json:"smbios_uuid"`
	ComputerName      string `json:"computer_name"`
	OSCaption         string `json:"os_caption"`
	OSVersion         string `json:"os_version"`
	OSArchitecture    string `json:"os_architecture"`
	PowerShellVersion string `json:"powershell_version"`
	HyperVAvailable   bool   `json:"hyperv_available"`
}

func ParsePhysicalHostIdentityObservation

func ParsePhysicalHostIdentityObservation(text string) (IsolatedPhysicalHostObservation, error)

type IsolatedResourceLockKey

type IsolatedResourceLockKey struct {
	Level IsolatedLockLevel
	Key   string
}

func AllocationLockKey

func AllocationLockKey(orchestratorID string) (IsolatedResourceLockKey, error)

func ChildLockKey

func ChildLockKey(kind, id string) (IsolatedResourceLockKey, error)

func HostOrchestratorCreateLockKey

func HostOrchestratorCreateLockKey(physicalHostID string) (IsolatedResourceLockKey, error)

func NetworkLockKey

func NetworkLockKey(networkID string) (IsolatedResourceLockKey, error)

func OrchestratorLockKey

func OrchestratorLockKey(orchestratorID string) (IsolatedResourceLockKey, error)

func VMLockKey

func VMLockKey(vmID string) (IsolatedResourceLockKey, error)

func (IsolatedResourceLockKey) CanAcquireAfter

func (k IsolatedResourceLockKey) CanAcquireAfter(parent IsolatedResourceLockKey) bool

type IsolatedRouteObservation

type IsolatedRouteObservation struct {
	DestinationPrefix string `json:"destination_prefix"`
	InterfaceIndex    int    `json:"interface_index"`
	InterfaceAlias    string `json:"interface_alias"`
	NextHop           string `json:"next_hop"`
	RouteMetric       int    `json:"route_metric"`
}

type IsolatedSwitchMutationResult

type IsolatedSwitchMutationResult struct {
	Action       string `json:"action"`
	NetworkID    string `json:"network_id"`
	Name         string `json:"name"`
	SwitchGUID   string `json:"switch_guid"`
	Type         string `json:"type"`
	HostNICCount int    `json:"host_nic_count"`
	Generation   int64  `json:"generation"`
}

func ParseIsolatedSwitchMutationResult

func ParseIsolatedSwitchMutationResult(text string) (IsolatedSwitchMutationResult, error)

type IsolatedSwitchObservation

type IsolatedSwitchObservation struct {
	Name              string                   `json:"name"`
	SwitchGUID        string                   `json:"switch_guid"`
	Type              string                   `json:"type"`
	AllowManagementOS bool                     `json:"allow_management_os"`
	HostNICCount      int                      `json:"host_nic_count"`
	ConnectedAdapters int                      `json:"connected_adapters"`
	OwnershipPath     string                   `json:"ownership_path,omitempty"`
	Ownership         *IsolatedNetworkMetadata `json:"ownership,omitempty"`
}

type IsolatedVMMetadata

type IsolatedVMMetadata struct {
	SchemaVersion    int               `json:"schema_version"`
	PhysicalHostID   string            `json:"physical_host_id"`
	OrchestratorID   string            `json:"orchestrator_id"`
	NetworkID        string            `json:"network_id"`
	VMID             string            `json:"vm_id"`
	RelayID          string            `json:"relay_id,omitempty"`
	OwnerMarker      string            `json:"owner_marker"`
	HostFence        int64             `json:"host_fence"`
	LifecycleState   string            `json:"lifecycle_state"`
	ManagedRoot      string            `json:"managed_root"`
	ExpectedVHDPaths []string          `json:"expected_vhd_paths"`
	NodeName         string            `json:"node_name"`
	IPv4             string            `json:"ipv4"`
	MAC              string            `json:"mac"`
	SwitchGUID       string            `json:"switch_guid"`
	VMGUID           string            `json:"vm_guid"`
	AdapterID        string            `json:"adapter_id"`
	Incarnation      int64             `json:"incarnation"`
	Generation       int64             `json:"generation"`
	CascadeAuthority *CascadeAuthority `json:"cascade_authority,omitempty"`
}

IsolatedVMMetadata is persisted in an isolated guest VM's Notes.

func ParseIsolatedVMMetadata

func ParseIsolatedVMMetadata(notes string) (IsolatedVMMetadata, error)

type IsolatedVMMutationResult

type IsolatedVMMutationResult struct {
	Action          string `json:"action"`
	VMID            string `json:"vm_id"`
	VMName          string `json:"vm_name"`
	VMGUID          string `json:"vm_guid"`
	AdapterID       string `json:"adapter_id"`
	SwitchGUID      string `json:"switch_guid"`
	MAC             string `json:"mac"`
	TimeSyncEnabled bool   `json:"time_sync_enabled"`
	State           string `json:"state"`
	VHDPath         string `json:"vhd_path,omitempty"`
	VMPath          string `json:"vm_path,omitempty"`
	DeletedStorage  bool   `json:"deleted_storage,omitempty"`
}

func ParseIsolatedVMMutationResult

func ParseIsolatedVMMutationResult(data string) (IsolatedVMMutationResult, error)

type IsolatedVMObservation

type IsolatedVMObservation struct {
	Name           string `json:"name"`
	VMGUID         string `json:"vm_guid"`
	State          string `json:"state"`
	MetadataKind   string `json:"metadata_kind,omitempty"`
	PhysicalHostID string `json:"physical_host_id,omitempty"`
	OrchestratorID string `json:"orchestrator_id,omitempty"`
	NetworkID      string `json:"network_id,omitempty"`
	ResourceID     string `json:"resource_id,omitempty"`
	HostFence      int64  `json:"host_fence,omitempty"`
	Generation     int64  `json:"generation,omitempty"`
	LifecycleState string `json:"lifecycle_state,omitempty"`
}

type LinuxImageBuilderAttachParams added in v0.7.0

type LinuxImageBuilderAttachParams struct {
	VMName     string
	VHDXPath   string
	StatePath  string
	DiskSizeGB int
}

type LinuxImageBuilderDetachParams added in v0.7.0

type LinuxImageBuilderDetachParams struct {
	VMName    string
	VHDXPath  string
	StatePath string
	Retain    bool
	Reason    string
}

type LinuxImageBuilderLockParams added in v0.7.0

type LinuxImageBuilderLockParams struct {
	Key        string
	Owner      string
	StaleAfter int
}

type LinuxImageBuilderMetadata added in v0.7.0

type LinuxImageBuilderMetadata struct {
	SchemaVersion      int    `json:"schema_version"`
	Target             string `json:"target"`
	Profile            string `json:"profile"`
	ProfileFingerprint string `json:"profile_fingerprint"`
	VMName             string `json:"vm_name"`
	NodeName           string `json:"node_name"`
}

type LinuxImageBuilderTransformParams added in v0.7.0

type LinuxImageBuilderTransformParams struct {
	StatePath              string
	ExpectedSizeBytes      int64
	ExpectedTargetLocation int
}

type LinuxImageConvertParams added in v0.7.0

type LinuxImageConvertParams struct {
	SourceArchive   string
	DestinationVHDX string
	StatePath       string
	StageDir        string
	DiskSizeGB      int
}

type LinuxImageDownloadParams added in v0.7.0

type LinuxImageDownloadParams struct {
	CacheRoot  string
	StagingID  string
	DiskSizeGB int
}

type LinuxImageLockParams added in v0.7.0

type LinuxImageLockParams struct {
	CacheRoot string
	CacheKey  string
	Owner     string
}

type LinuxImagePublishParams added in v0.7.0

type LinuxImagePublishParams struct {
	StagedVHDX   string
	FinalVHDX    string
	MetadataPath string
	StatePath    string
	Metadata     linuximage.ImageMetadata
}

type LinuxImageVerifyParams added in v0.7.0

type LinuxImageVerifyParams struct {
	CacheRoot         string
	ExpectedImageHash string
	CacheKey          string
	DiskSizeGB        int
	Verification      linuximage.VerificationState
}

type LinuxVMLockParams added in v0.7.0

type LinuxVMLockParams struct {
	Key        string
	Owner      string
	StaleAfter int
}

type LinuxVMMetadata added in v0.7.0

type LinuxVMMetadata struct {
	SchemaVersion     int    `json:"schema_version"`
	GuestOS           string `json:"guest_os"`
	VMName            string `json:"vm_name"`
	NodeName          string `json:"node_name"`
	ManagedRoot       string `json:"managed_root"`
	ParentVHDX        string `json:"parent_vhdx"`
	ChildVHDX         string `json:"child_vhdx"`
	ExpectedCIDATAISO string `json:"expected_cidata_iso"`
	CleanupPhase      string `json:"cleanup_phase"`
	Registered        bool   `json:"registered"`
}

type LinuxVMOwnership added in v0.7.0

type LinuxVMOwnership struct {
	SchemaVersion int    `json:"schema_version"`
	VMName        string `json:"vm_name"`
	ManagedRoot   string `json:"managed_root"`
	VMLocation    string `json:"vm_location"`
	ChildVHDX     string `json:"child_vhdx"`
	ISOPath       string `json:"iso_path"`
	StageDir      string `json:"stage_dir"`
}

type LinuxVMOwnershipParams added in v0.7.0

type LinuxVMOwnershipParams struct {
	Ownership        LinuxVMOwnership
	StageDirectories []string
}

type NIC

type NIC struct {
	Name                 string `json:"name"`
	InterfaceGUID        string `json:"interface_guid"`
	InterfaceIndex       int    `json:"interface_index"`
	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.

func ParseNICs

func ParseNICs(jsonText string) ([]NIC, error)

ParseNICs parses the JSON array emitted by BuildListNicsScript. PowerShell emits a bare object (not an array) for a single row; ParseNICs handles both.

type RebindIsolatedParentFenceParams

type RebindIsolatedParentFenceParams struct {
	Guard                 IsolatedMutationGuard
	OrchestratorVMGUID    string
	ExpectedPreviousFence int64
	ExpectedGeneration    int64
	PlanRevision          string
	PlanHash              string
}

type ReconcileIsolatedAdapterMetadataParams

type ReconcileIsolatedAdapterMetadataParams struct {
	Guard              IsolatedMutationGuard
	NetworkID          string
	ResourceType       string
	ResourceID         string
	OrchestratorVMGUID string
	VMGUID             string
	AdapterName        string
	ExpectedAdapterID  string
	SwitchName         string
	ExpectedSwitchGUID string
	ExpectedMAC        string
	ExpectedGeneration int64
}

type ReconcileLinuxVMArtifactsParams added in v0.7.0

type ReconcileLinuxVMArtifactsParams struct {
	Name      string
	Ownership LinuxVMOwnership
}

type ReconcileStaleIsolatedMetadataParams

type ReconcileStaleIsolatedMetadataParams struct {
	Guard              IsolatedMutationGuard
	OrchestratorVMGUID string
	HyperVName         string
	LifecycleState     string
}

type RemoveIsolatedNICParams

type RemoveIsolatedNICParams struct {
	Guard              IsolatedMutationGuard
	NetworkID          string
	ResourceType       string
	ResourceID         string
	OrchestratorVMGUID string
	VMGUID             string
	AdapterName        string
	ExpectedAdapterID  string
	ExpectedSwitchGUID string
	ExpectedMAC        string
	ExpectedGeneration int64
}

type ResourceSafetyParams added in v0.6.2

type ResourceSafetyParams struct {
	MemoryMB                  float64
	StoragePath               string
	ReserveVHDPath            string
	ReserveRemainingGrowth    bool
	StorageReserveBytes       int64
	MinHostReservePct         float64
	AllowHostResourcePressure bool
}

type SetIsolatedParentLifecycleParams

type SetIsolatedParentLifecycleParams struct {
	Guard              IsolatedMutationGuard
	OrchestratorVMGUID string
	ExpectedGeneration int64
	NewGeneration      int64
	NewState           string
	CascadeAuthority   *CascadeAuthority
}

type StartIsolatedVMParams

type StartIsolatedVMParams struct {
	VMName       string
	ExpectedVMID string
	ExpectedGUID string
	ExpectedIPv4 string
}

type UncertainCreateDecision

type UncertainCreateDecision string
const (
	UncertainCreateRetry    UncertainCreateDecision = "retry"
	UncertainCreateAdopt    UncertainCreateDecision = "adopt"
	UncertainCreateConflict UncertainCreateDecision = "conflict"
)

type VSwitch

type VSwitch struct {
	Name              string `json:"name"`
	ID                string `json:"id"`
	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

func ParseVSwitches(jsonText string) ([]VSwitch, error)

ParseVSwitches parses the JSON emitted by BuildListVSwitchesScript.

Directories

Path Synopsis
Package unattend renders Windows answer files (unattend.xml / Autounattend.xml) and builds the PowerShell injection scripts.
Package unattend renders Windows answer files (unattend.xml / Autounattend.xml) and builds the PowerShell injection scripts.

Jump to

Keyboard shortcuts

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