scripts

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MPL-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package scripts embeds the PowerShell scripts the provider runs against the host. The typed Hyper-V client (internal/hyperv) reads from these embedded filesystems and concatenates common/preamble.ps1 to the top of each resource script per the §5 contract.

Directory layout (one subdir per resource family):

common/preamble.ps1     — concatenated to every script (§5)
vswitch/get.ps1         — Get-VMSwitch wrapper        (M1)
vswitch/new.ps1         — New-VMSwitch wrapper        (M1)
vswitch/set.ps1         — Set-VMSwitch wrapper        (M1)
vswitch/remove.ps1      — Remove-VMSwitch wrapper     (M1)
... etc.

Index

Constants

This section is empty.

Variables

View Source
var Common embed.FS

Common holds preamble and shared helpers — exposed because the typed client prepends preamble.ps1 to every resource-script body before sending it through the connection layer.

View Source
var ImageFile embed.FS

ImageFile holds the verb scripts for hyperv_image_file (M4). No "set" verb -- every image_file schema field is RequiresReplace, so Update is a Go-side no-op with no PS round-trip.

View Source
var NatStaticMapping embed.FS

NatStaticMapping holds the four verb scripts for hyperv_nat_static_mapping plus the shared _retry.ps1 helper prepended to new/set on the Go side (mirror of the vm/read-result.ps1 pattern). Pester *.Tests.ps1 and the _test_helpers.ps1 stub file are deliberately excluded from the embed glob.

View Source
var NetNat embed.FS

NetNat holds the verb scripts for orphan-NetNat cleanup. The only verb needed today is a combined list+remove `sweep` used by the acceptance-test sweeper -- splitting it into separate list and remove scripts would double the SSH cost for zero benefit. Multiple NetNats can coexist on a host; the sweeper handles all matches in one pass. Production CRUD on NetNat lives inside vswitch/{new,remove}.ps1 and nat_static_mapping/*.ps1; this package is sweep-only.

View Source
var VHD embed.FS

VHD holds the verb scripts for hyperv_vhd (M4). The "set" verb only resizes -- every other attribute is RequiresReplace at the schema layer.

VM holds the verb scripts for hyperv_vm. Beyond the four base verbs (get/new/set/remove) there are per-attachment add/remove scripts:

  • add-hard-disk-drive / remove-hard-disk-drive (M4)
  • add-network-adapter / remove-network-adapter (next M4 commit)
  • add-dvd-drive / remove-dvd-drive (next M4 commit)

The attachment scripts deliberately don't get fold into set.ps1 -- each attach/detach is a separate cmdlet on the host (Add-VMHardDiskDrive, Add-VMNetworkAdapter, etc.) and the Go-side reconciliation in Update is much cleaner when each cmdlet has its own script with its own per-cmdlet error mapping than when set.ps1 has to disambiguate which of N internal failures fired.

View Source
var Vswitch embed.FS

Vswitch holds the four verb scripts for hyperv_virtual_switch. The typed client reads each by path and concatenates the preamble before invoking. Pester *.Tests.ps1 and the _test_helpers.ps1 stub file are deliberately excluded from the embed glob — production Go has no use for them.

Functions

func ImageFileScript

func ImageFileScript(verb string) ([]byte, error)

ImageFileScript returns the contents of image_file/<verb>.ps1 (verb in {get, new, remove, sweep}).

func NatStaticMappingRetry added in v0.3.0

func NatStaticMappingRetry() ([]byte, error)

NatStaticMappingRetry returns nat_static_mapping/_retry.ps1, the shared Invoke-WithDupNameRetry helper. The Go-side hyperv.Client prepends its body to the new and set verb scripts at runtime, replacing what used to be two inline copies of the same function.

func NatStaticMappingScript added in v0.3.0

func NatStaticMappingScript(verb string) ([]byte, error)

NatStaticMappingScript returns the contents of nat_static_mapping/<verb>.ps1 (verb in {get, new, set, remove}).

func NetNatScript added in v0.3.0

func NetNatScript(verb string) ([]byte, error)

NetNatScript returns the contents of netnat/<verb>.ps1. Today the only verb is "sweep"; the function shape mirrors VswitchScript so the call sites stay consistent if more verbs land later.

func Preamble

func Preamble() ([]byte, error)

Preamble returns the contents of common/preamble.ps1. Convenience wrapper so callers don't have to repeat the path string.

func VHDScript

func VHDScript(verb string) ([]byte, error)

VHDScript returns the contents of vhd/<verb>.ps1 (verb in {get, new, set, remove}).

func VMReadResult

func VMReadResult() ([]byte, error)

VMReadResult returns vm/read-result.ps1, the canonical Read-HypervVMResult function shared by the four VM read-emitting scripts (get/new/set/set-state). The Go-side hyperv.Client prepends its body to those scripts at runtime, replacing what used to be four inline copies of the same function.

func VMScript

func VMScript(verb string) ([]byte, error)

VMScript returns the contents of vm/<verb>.ps1.

`verb` is the file name without extension. For multi-word verbs use the hyphenated form ("add-hard-disk-drive"). The base verbs are get/new/set/remove; attachment verbs add the specific cmdlet name.

func VswitchScript

func VswitchScript(verb string) ([]byte, error)

VswitchScript returns the contents of vswitch/<verb>.ps1 (verb in {get, new, set, remove}). Centralizes the path joining so callers don't repeat the "vswitch/" prefix and a typo'd verb fails loudly at startup (via embed_test.go) rather than at first apply.

Types

This section is empty.

Jump to

Keyboard shortcuts

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