vmware

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 30 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Conversion of VMware machines with the real virt-v2v binary (ADR-0061), and adoption of the result as a VirtoMir machine. Experimental, not tested on hardware: the command line follows the virt-v2v 2.x documentation, but no real vCenter or ESXi host has been migrated through this code yet.

The exec pattern follows internal/offsite (restic: an Exec func field, the real runner streaming stdout line by line with stderr captured); the pool and disk handling follows internal/virt/ova.go (OVA import: images land in a directory pool, and a failure leaves nothing behind).

VMware inventory reader for the migration UI (ADR-0061).

The inventory is taken with govmomi (github.com/vmware/govmomi v0.56.0, © Broadcom, Apache-2.0 — its simulator package used by the tests carries the same license). govmomi is imported only by internal/vmware; the libvirt dependency is untouched.

One SOAP session per List call: log in, collect, log out (defer). The credentials never appear in the URL that is kept around or in any error: they ride on a private url.URL copy used only to dial and sign in, and every error is wrapped so err.Error() can never contain the password.

Package vmware reads the inventory of a VMware environment — a vCenter or a standalone ESXi host — so its machines can be migrated to VirtoMir (ADR-0061). Inventory is taken with govmomi; conversion (convert.go) executes the real virt-v2v binary — experimental, not tested on hardware.

The vCenter/ESXi password stays on the host (<state-dir>/vmware.json, 0600) and never reaches a log: Connection's String method redacts it (slog and fmt print a Connection through it), and nothing in this package logs the password either. The API only ever shows that it is set.

Wave migration of multiple VMware machines in parallel (ADR-0061).

A wave runs conversions under a concurrency limit, reporting per-item progress and an overall "N of M done" summary string to the jobs framework. Partial failures leave the completed machines defined in VirtoMir and allow retrying just the failed ones.

Index

Constants

View Source
const KeepWaves = 20

KeepWaves is the maximum number of waves remembered in memory.

View Source
const Secret = "••••••••"

Secret is what the API shows instead of the stored password; sending it back keeps it.

Variables

View Source
var (
	ErrInvalid = errors.New("invalid")
	ErrRefused = errors.New("refused")
)

Functions

This section is empty.

Types

type Connection

type Connection struct {
	// URL is the HTTPS address of the vCenter or ESXi host, e.g. https://vcenter.example.com.
	URL string `json:"url,omitempty"`
	// Username signs in to vCenter/ESXi, e.g. administrator@vsphere.local or root.
	Username string `json:"username,omitempty"`
	// Password of that user; it never leaves the host and never reaches a log.
	Password string `json:"password,omitempty"`
	// Thumbprint pins the host's TLS certificate: its SHA-1 or SHA-256 fingerprint in
	// hex, with or without colons. With Insecure it takes the place of CA verification.
	Thumbprint string `json:"thumbprint,omitempty"`
	// Insecure skips CA verification, but only together with a thumbprint — the
	// connection is then pinned to exactly that certificate instead.
	Insecure bool `json:"insecure,omitempty"`
	// ESXi marks a standalone ESXi host rather than a vCenter; conversion then talks to
	// the host itself (esx://) instead of through vCenter (vpx://).
	ESXi bool `json:"esxi,omitempty"`
}

Connection is how VirtoMir reaches a VMware environment: vCenter or standalone ESXi (ADR-0061).

func (Connection) Configured

func (c Connection) Configured() bool

Configured reports whether a connection is fully set.

func (Connection) String

func (c Connection) String() string

String redacts the password, so a Connection printed with slog (or fmt) can never show it.

type ConvertOpts

type ConvertOpts struct {
	// PoolPath is the directory of the storage pool the disks land in (virt-v2v -os).
	PoolPath string `json:"poolPath"`
	// NetworkMap maps each VMware port group the VM's NICs use to a libvirt network
	// name; virt-v2v rewrites the interfaces accordingly (--network <group>:<network>).
	NetworkMap map[string]string `json:"networkMap,omitempty"`
	// Name of the machine in VirtoMir; the VMware VM's name when empty.
	Name string `json:"name,omitempty"`
	// VirtioISO is a directory or ISO with Windows virtio drivers (--inject-drivers);
	// virt-v2v injects the drivers it finds itself when it is empty.
	VirtioISO string `json:"virtioIso,omitempty"`
}

ConvertOpts is one migration.

type Converter

type Converter struct {
	// contains filtered or unexported fields
}

Converter migrates VMware machines: it runs virt-v2v and defines the result through the libvirt client. exec and look are replaceable in tests.

func NewConverter

func NewConverter(client *virt.Client) *Converter

NewConverter migrates with the real virt-v2v and defines through client.

func (*Converter) Convert

func (s *Converter) Convert(ctx context.Context, c Connection, vm VM, opts ConvertOpts, report func(string)) (string, error)

Convert migrates one VMware machine with virt-v2v and adopts the result: the disks land as images in the pool directory, the produced definition is renamed to opts.Name and defined through the libvirt client (virt.Client.AdoptDomain, the same way a machine moved from another host is defined). It returns the new machine's UUID, so the caller records the owner and lets the configuration history capture the first version — exactly what a create through the API does (internal/api/domains.go).

The VMware password reaches virt-v2v only through a 0600 password file that is gone when Convert returns; it is never on the command line and never in an error. On a failure after partial output, the disk files virt-v2v already wrote are removed and the pool refreshed, so a retried migration starts clean.

func (*Converter) Preflight

func (s *Converter) Preflight(ctx context.Context, c Connection, vm VM, poolFreeBytes uint64) error

Preflight checks everything that would stop a migration before it starts, and returns every failed check at once. A Windows guest without a provided virtio driver ISO is not one of them: virt-v2v injects the drivers it finds itself (Convert reports a note about it instead).

type Datacenter

type Datacenter struct {
	Name string `json:"name"`
}

Datacenter is one vCenter datacenter.

type ESXHost

type ESXHost struct {
	Name       string `json:"name"`
	Datacenter string `json:"datacenter"`
}

ESXHost is one ESXi host and the datacenter it belongs to.

type Exec

type Exec func(ctx context.Context, env []string, args []string, onLine func(string)) (stdout []byte, err error)

Exec runs virt-v2v with the given environment; lines of stdout go to onLine as they come. env is nil today — the password travels in a password file, never the environment — and exists so the shape matches internal/offsite.

type GovmomiLister

type GovmomiLister struct{}

GovmomiLister is the Lister that talks to a real vCenter or ESXi host.

func (GovmomiLister) List

List reads the inventory: datacenters, their hosts and the VMs on them.

type Inventory

type Inventory struct {
	Datacenters []Datacenter `json:"datacenters"`
	Hosts       []ESXHost    `json:"hosts"`
	VMs         []VM         `json:"vms"`
}

Inventory is everything one List call sees.

type Issues

type Issues []string

Issues lists every failed pre-flight check in one error, so the API can show them all at once (errors.As yields the []string itself). They count as invalid input.

func (Issues) Error

func (e Issues) Error() string

func (Issues) Is

func (e Issues) Is(target error) bool

type Lister

type Lister interface {
	List(ctx context.Context, c Connection) (Inventory, error)
}

Lister reads the inventory of a VMware environment over c.

type LookPath

type LookPath func(bin string) (string, error)

LookPath reports whether a binary is installed (exec.LookPath shape).

type OneConverter

type OneConverter interface {
	ConvertOne(ctx context.Context, conn Connection, vmID string, report func(string)) error
}

OneConverter converts single VMs from VMware to VirtoMir.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry tracks recent VMware migration waves in memory, newest first.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty wave registry.

func (*Registry) Get

func (r *Registry) Get(id string) (Wave, bool)

Get returns a snapshot of the wave with id, or false if not found.

func (*Registry) List

func (r *Registry) List() []Wave

List returns all known waves, newest first.

func (*Registry) Retry

func (r *Registry) Retry(ctx context.Context, waveID string, conv OneConverter, report func(string)) (Wave, error)

Retry re-runs only the failed items of an existing wave under the same concurrency rules.

func (*Registry) Start

func (r *Registry) Start(ctx context.Context, conn Connection, vmIDs []string, parallel int, conv OneConverter, report func(string)) (Wave, error)

Start launches a new migration wave, running ConvertOne for each VM under a semaphore clamped to 1..4 parallel workers (default 2). Returns an error only if every item failed.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store holds the connection settings in <state-dir>/vmware.json.

func Open

func Open(path string) (*Store, error)

Open loads <path>; a missing file is an empty configuration, not an error.

func (*Store) Config

func (s *Store) Config() Connection

Config returns the connection with the password replaced by Secret.

func (*Store) Configured

func (s *Store) Configured() bool

Configured reports whether a connection is stored.

func (*Store) Connection

func (s *Store) Connection() Connection

Connection returns the active connection settings, including the password. The password stays on the host and Connection.String redacts it.

func (*Store) SetConfig

func (s *Store) SetConfig(c Connection) error

SetConfig stores the connection. A password sent back as Secret keeps its stored value; a connection with an empty URL clears the stored one entirely.

func (*Store) Validate

func (s *Store) Validate(c Connection) error

Validate checks a connection as SetConfig would, without storing it. It rejects an empty URL (SetConfig with an empty URL clears the configuration instead) and an empty password — including one sent as an empty string over a stored one.

type VM

type VM struct {
	ID         string   `json:"id"`
	Name       string   `json:"name"`
	Datacenter string   `json:"datacenter"`
	Host       string   `json:"host"`
	PowerState string   `json:"powerState"`
	VCPUs      int      `json:"vcpus"`
	MemoryMiB  uint64   `json:"memoryMiB"`
	GuestOS    string   `json:"guestOs"`
	Disks      []VMDisk `json:"disks"`
	NICs       []VMNIC  `json:"nics"`
}

VM is a VMware machine seen by the migration UI.

type VMDisk

type VMDisk struct {
	Datastore     string `json:"datastore"`
	CapacityBytes uint64 `json:"capacityBytes"`
}

VMDisk is one virtual disk of a VM.

type VMNIC

type VMNIC struct {
	Network string `json:"network"`
	MAC     string `json:"mac"`
}

VMNIC is one network interface of a VM.

type Wave

type Wave struct {
	ID       string     `json:"id"`
	Items    []WaveItem `json:"items"`
	Parallel int        `json:"parallel"`
	Created  time.Time  `json:"created"`
	// contains filtered or unexported fields
}

Wave is a batch of VM conversions executed together.

type WaveConverter

type WaveConverter struct {
	Lister        Lister
	Converter     *Converter
	Opts          ConvertOpts
	PoolFreeBytes uint64
	// contains filtered or unexported fields
}

WaveConverter is the production OneConverter that resolves the VM from the inventory Lister, runs Preflight then Convert with virt-v2v.

func NewWaveConverter

func NewWaveConverter(conv *Converter, lister Lister, opts ConvertOpts) *WaveConverter

NewWaveConverter returns a OneConverter that lists inventory, preflights and converts with virt-v2v.

func (*WaveConverter) ConvertOne

func (c *WaveConverter) ConvertOne(ctx context.Context, conn Connection, vmID string, report func(string)) error

ConvertOne resolves the VM by ID or Name from inventory, runs Preflight, and executes Convert.

type WaveItem

type WaveItem struct {
	VMID    string        `json:"vmId"`
	Name    string        `json:"name"`
	State   WaveItemState `json:"state"`
	Message string        `json:"message,omitempty"`
}

WaveItem is one VM scheduled or processed in a migration wave.

type WaveItemState

type WaveItemState string

WaveItemState is the status of one VM in a migration wave.

const (
	WaveItemPending WaveItemState = "pending"
	WaveItemRunning WaveItemState = "running"
	WaveItemDone    WaveItemState = "done"
	WaveItemFailed  WaveItemState = "failed"
)

Jump to

Keyboard shortcuts

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