bootstrap

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package bootstrap provides the main public API for VM bootstrapping.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteNode added in v0.2.0

func DeleteNode(ctx context.Context, cfg *VMConfig) error

DeleteNode deletes an existing node by cfg.Name from vCenter. It is idempotent: if the node does not exist, it returns nil.

func NodeExists added in v0.2.0

func NodeExists(ctx context.Context, cfg *VMConfig) (bool, error)

NodeExists reports whether a node with cfg.Name exists in cfg.Datacenter.

func UpgradeTalosNode added in v0.2.0

func UpgradeTalosNode(ctx context.Context, cfg *TalosNodeUpdateConfig) error

UpgradeTalosNode upgrades a Talos node using talosctl.

Types

type TalosNodeUpdateConfig added in v0.2.0

type TalosNodeUpdateConfig struct {
	NodeIP         string
	Endpoint       string
	Version        string
	Talosconfig    string
	TalosctlPath   string
	Preserve       bool
	Insecure       bool
	AdditionalArgs []string
}

TalosNodeUpdateConfig controls talosctl-based node upgrades.

type TalosProfile added in v0.2.0

type TalosProfile struct {
	Version     string
	SchematicID string
}

TalosProfile contains Talos-specific settings for profile mode.

type UbuntuProfile added in v0.2.0

type UbuntuProfile struct {
	Version string
}

UbuntuProfile contains Ubuntu-specific settings for profile mode.

type VM

type VM struct {
	Name          string                       // VM name
	IPAddress     string                       // Assigned IP address
	MACAddress    string                       // Assigned MAC address (auto or static)
	ManagedObject types.ManagedObjectReference // govmomi VM reference
	SSHReady      bool                         // SSH port 22 accessible
	Hostname      string                       // Configured hostname
	// vCenter connection data for post-create operations (Verify/PowerOn/PowerOff/Delete).
	// These fields are intentionally not serialized.
	VCenterHost     string `json:"-"`
	VCenterPort     int    `json:"-"`
	VCenterUser     string `json:"-"`
	VCenterPass     string `json:"-"`
	VCenterInsecure bool   `json:"-"`
}

VM represents a bootstrapped virtual machine.

func Bootstrap

func Bootstrap(ctx context.Context, cfg *VMConfig) (*VM, error)

Bootstrap creates and configures a complete VM in vCenter. Returns VM object ONLY after: - VM created in vCenter - Profile provisioning completed - Optional SSH verification completed (Ubuntu profile)

func BootstrapWithLogger

func BootstrapWithLogger(ctx context.Context, cfg *VMConfig, logger *slog.Logger) (*VM, error)

BootstrapWithLogger creates and configures a VM with custom logger.

func CreateNode added in v0.2.0

func CreateNode(ctx context.Context, cfg *VMConfig) (*VM, error)

CreateNode provisions a new node using the selected OS profile.

func CreateNodeWithLogger added in v0.2.0

func CreateNodeWithLogger(ctx context.Context, cfg *VMConfig, logger *slog.Logger) (*VM, error)

CreateNodeWithLogger provisions a new node with a custom logger.

func CreateTalosNodeFromOVA added in v0.2.0

func CreateTalosNodeFromOVA(ctx context.Context, cfg *VMConfig, logger *slog.Logger) (*VM, error)

CreateTalosNodeFromOVA deploys a Talos VMware OVA and powers the VM on.

func RecreateNode added in v0.2.0

func RecreateNode(ctx context.Context, cfg *VMConfig) (*VM, error)

RecreateNode deletes the existing node (if present) and creates it again.

func RecreateNodeWithLogger added in v0.2.0

func RecreateNodeWithLogger(ctx context.Context, cfg *VMConfig, logger *slog.Logger) (*VM, error)

RecreateNodeWithLogger deletes the existing node (if present) and creates it again.

func (*VM) Delete

func (vm *VM) Delete(ctx context.Context) error

Delete powers off the VM if needed and removes it from vCenter.

func (*VM) PowerOff

func (vm *VM) PowerOff(ctx context.Context) error

PowerOff powers off the VM and waits for completion.

func (*VM) PowerOn

func (vm *VM) PowerOn(ctx context.Context) error

PowerOn powers on the VM and waits for completion.

func (*VM) Verify

func (vm *VM) Verify(ctx context.Context) error

Verify performs a basic health check: VM powered on, VMware Tools running (if available), hostname matches (if available), and SSH port is reachable (if IP is set).

type VMConfig

type VMConfig struct {
	// === vCenter Connection ===
	VCenterHost     string // vCenter hostname or IP (e.g., "vcenter.example.com")
	VCenterUsername string // vCenter username (e.g., "[email protected]")
	VCenterPassword string // vCenter password (encrypted/plain - user's responsibility)
	VCenterPort     int    // vCenter port (default: 443)
	VCenterInsecure bool   // Skip TLS verification (not recommended for production)

	// === VM Specifications ===
	Name              string // VM name (e.g., "web-server-01")
	CPUs              int    // Number of CPUs (e.g., 4)
	MemoryMB          int    // Memory in MB (e.g., 8192)
	DiskSizeGB        int    // OS disk size in GB (e.g., 40)
	DataDiskSizeGB    *int   // Optional data disk size in GB (e.g., 500) - nil = not created
	DataDiskMountPath string // Mount point for data disk (e.g., "/data") - required if DataDiskSizeGB set

	// === Network Configuration ===
	NetworkName      string   // Network name (e.g., "LAN_Management")
	NetworkInterface string   // Guest NIC name (e.g., "ens192")
	MACAddress       string   // Optional static MAC address (e.g., "00:50:56:aa:bb:cc")
	IPAddress        string   // Static IP address (e.g., "192.168.1.10")
	Netmask          string   // Network mask (e.g., "255.255.255.0")
	Gateway          string   // Default gateway (e.g., "192.168.1.1")
	DNS              []string // DNS servers (e.g., ["8.8.8.8", "8.8.4.4"])

	// === VM Placement ===
	Datacenter   string // Datacenter name (e.g., "DC1")
	Folder       string // VM folder path (e.g., "Production/WebServers")
	ResourcePool string // Resource pool path (e.g., "WebTier")
	Datastore    string // VM datastore name (e.g., "VMwareSSD01")
	ISODatastore string // Datastore for ISO uploads (e.g., "VMwareStorage01"); falls back to Datastore if empty
	// vCenter Content Library used for Talos OVA cache/deploy.
	// Name is used when ID is empty; ID is preferred when both are set.
	ContentLibrary   string
	ContentLibraryID string

	// === OS & User Configuration ===
	// OS profile used for VM provisioning (default: "ubuntu").
	Profile string
	// Profile-specific options.
	Profiles      VMProfiles
	Username      string   // SSH user to create (e.g., "sysadmin")
	SSHPublicKeys []string // SSH public keys (one or more)
	Password      string   // Optional plain text password (auto-hashed with bcrypt before use)
	PasswordHash  string   // Optional pre-computed password hash (bcrypt); overrides Password if both set
	// Allow SSH password authentication (default: false). Requires Password or PasswordHash.
	AllowPasswordSSH bool
	// Skip SSH verification during bootstrap (default: false).
	SkipSSHVerify bool
	// Keep VM/ISO on bootstrap failure for debugging (default: false).
	SkipCleanupOnError bool

	// === Advanced Options ===
	Timezone   string // System timezone (default: "UTC")
	Locale     string // System locale (default: "en_US.UTF-8")
	SwapSizeGB *int   // Swap size in GB (default from configs/defaults.yaml)
	Firmware   string // Firmware type: "bios" or "efi" (default: "bios")
}

VMConfig defines the complete configuration for VM bootstrap.

func (*VMConfig) EffectiveOSSchematicID added in v0.2.0

func (cfg *VMConfig) EffectiveOSSchematicID() string

EffectiveOSSchematicID returns schematic/build identifier for selected OS profile.

func (*VMConfig) EffectiveOSVersion added in v0.2.0

func (cfg *VMConfig) EffectiveOSVersion() string

EffectiveOSVersion returns OS version for the selected profile.

func (*VMConfig) EffectiveProfile added in v0.2.0

func (cfg *VMConfig) EffectiveProfile() string

EffectiveProfile returns normalized profile name.

func (*VMConfig) EffectiveTalosVersion added in v0.2.0

func (cfg *VMConfig) EffectiveTalosVersion() string

EffectiveTalosVersion returns Talos version from profile config.

func (*VMConfig) EffectiveUbuntuVersion added in v0.2.0

func (cfg *VMConfig) EffectiveUbuntuVersion() string

EffectiveUbuntuVersion returns Ubuntu version from profile config.

func (*VMConfig) SetDefaults

func (cfg *VMConfig) SetDefaults()

SetDefaults sets default values for optional fields from configs/defaults.yaml.

func (*VMConfig) Validate

func (cfg *VMConfig) Validate() error

Validate checks if the VM configuration is valid.

type VMProfiles added in v0.2.0

type VMProfiles struct {
	Ubuntu UbuntuProfile
	Talos  TalosProfile
}

VMProfiles contains profile-specific settings.

Jump to

Keyboard shortcuts

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