source

package
v0.6.9 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: Apache-2.0 Imports: 48 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewVMSource = func(s api.Source) (Source, error) {
	switch s.SourceType {
	case api.SOURCETYPE_VMWARE:
		return newInternalVMwareSourceFrom(s)
	default:
		return nil, fmt.Errorf("Unknown source type %q", s.SourceType)
	}
}

Functions

func IsVMwareNotFoundErr added in v0.6.3

func IsVMwareNotFoundErr(err error) bool

Types

type InternalNSXSource

type InternalNSXSource struct {
	InternalSource            `yaml:",inline"`
	InternalNSXSourceSpecific `yaml:",inline"`
}

func NewInternalNSXSourceFrom

func NewInternalNSXSourceFrom(apiSource api.Source) (*InternalNSXSource, error)

func (*InternalNSXSource) AddSegmentData

AddSegmentData populates the segment data with firewall rules, and adds the VMs from the given set that exist on the segment.

func (*InternalNSXSource) Connect

func (s *InternalNSXSource) Connect(ctx context.Context) error

Connect verifies the NSX server cert against the trusted fingerprint, and fetches the NSX Manager version.

func (*InternalNSXSource) DoBasicConnectivityCheck

func (s *InternalNSXSource) DoBasicConnectivityCheck() (api.ExternalConnectivityStatus, *x509.Certificate)

DoBasicConnectivityCheck performs a connectivity check and verifies the server certificate against the trusted fingerprint.

func (*InternalNSXSource) FetchSourceData

func (s *InternalNSXSource) FetchSourceData(ctx context.Context) error

func (*InternalNSXSource) GetComputeManagers

func (s *InternalNSXSource) GetComputeManagers(ctx context.Context) ([]internalAPI.NSXComputeManager, error)

GetComputeManagers gets all compute managers registered with the NSX Manager.

func (*InternalNSXSource) GetEdgeNodes

GetEdgeNodes fetches all edge transport nodes of the NSX Manager.

func (*InternalNSXSource) GetSecurityPolicies

func (s *InternalNSXSource) GetSecurityPolicies(ctx context.Context) ([]internalAPI.NSXSecurityPolicy, error)

GetSecurityPolicies fetches all security policies for all domains.

func (*InternalNSXSource) GetSegment

GetSegment fetches a segment by its segment path, and includes any VMs from the supplied list if their VIFs use a logical port on the segment.

func (*InternalNSXSource) GetSegments

func (s *InternalNSXSource) GetSegments(ctx context.Context, populateData bool) ([]internalAPI.NSXSegment, error)

GetSegments fetches all segments, their VMs, and gateway policies.

func (*InternalNSXSource) GetTransportZone

func (s *InternalNSXSource) GetTransportZone(ctx context.Context, zoneUUID uuid.UUID) (*internalAPI.NSXTransportZone, error)

GetTransportZone fetches a transport zone by its UUID.

func (*InternalNSXSource) GetVMs

GetVMs fetches all VMs and their VIFs.

type InternalNSXSourceSpecific

type InternalNSXSourceSpecific struct {
	internalAPI.NSXSourceProperties `yaml:",inline"`
	// contains filtered or unexported fields
}

type InternalSource

type InternalSource struct {
	api.Source `yaml:",inline"`
	// contains filtered or unexported fields
}

func (*InternalSource) Connect

func (s *InternalSource) Connect(ctx context.Context) error

func (*InternalSource) DeleteVMSnapshot

func (s *InternalSource) DeleteVMSnapshot(ctx context.Context, vmName string, snapshotName string) error

func (*InternalSource) Disconnect

func (s *InternalSource) Disconnect(ctx context.Context) error

func (*InternalSource) DoBasicConnectivityCheck

func (s *InternalSource) DoBasicConnectivityCheck() (api.ExternalConnectivityStatus, *x509.Certificate)

func (*InternalSource) GetAllVMs

func (*InternalSource) GetName

func (s *InternalSource) GetName() string

func (*InternalSource) ImportDisks

func (s *InternalSource) ImportDisks(ctx context.Context, vmName string, statusCallback func(string, bool)) error

func (*InternalSource) IsConnected

func (s *InternalSource) IsConnected() bool

func (*InternalSource) PowerOffVM

func (s *InternalSource) PowerOffVM(ctx context.Context, vmName string) error

func (*InternalSource) Timeout added in v0.6.0

func (s *InternalSource) Timeout() time.Duration

func (*InternalSource) WithAdditionalRootCertificate

func (s *InternalSource) WithAdditionalRootCertificate(rootCert *x509.Certificate)

type InternalVMwareSource

type InternalVMwareSource struct {
	InternalSource               `yaml:",inline"`
	InternalVMwareSourceSpecific `yaml:",inline"`
}

func (*InternalVMwareSource) Connect

func (s *InternalVMwareSource) Connect(ctx context.Context) error

func (*InternalVMwareSource) DeleteVMSnapshot

func (s *InternalVMwareSource) DeleteVMSnapshot(ctx context.Context, vmName string, snapshotName string) error

func (*InternalVMwareSource) Disconnect

func (s *InternalVMwareSource) Disconnect(ctx context.Context) error

func (*InternalVMwareSource) DoBasicConnectivityCheck

func (s *InternalVMwareSource) DoBasicConnectivityCheck() (api.ExternalConnectivityStatus, *x509.Certificate)

func (*InternalVMwareSource) Dump added in v0.6.2

func (*InternalVMwareSource) EnableBackgroundImport added in v0.6.5

func (s *InternalVMwareSource) EnableBackgroundImport(ctx context.Context, instUUID uuid.UUID) error

EnableBackgroundImport powers off the VM, deletes all snapshots, then turns on change tracking and powers back on the VM, if it was initially powered on.

func (*InternalVMwareSource) GetAllVMs

func (*InternalVMwareSource) GetBackgroundImport added in v0.5.0

func (s *InternalVMwareSource) GetBackgroundImport(ctx context.Context, instUUID uuid.UUID) (bool, error)

GetBackgroundImport returns the background import support property of an instance by its UUID.

func (*InternalVMwareSource) GetNSXManagerIP

func (s *InternalVMwareSource) GetNSXManagerIP(ctx context.Context) (string, error)

func (*InternalVMwareSource) ImportDisks

func (s *InternalVMwareSource) ImportDisks(ctx context.Context, vmName string, sdkPath string, disks []api.InstancePropertiesDisk, statusCallback func(string, bool)) error

func (*InternalVMwareSource) IsRunning added in v0.6.1

func (s *InternalVMwareSource) IsRunning(ctx context.Context, vmLocation string) (bool, error)

func (*InternalVMwareSource) PowerOffVM

func (s *InternalVMwareSource) PowerOffVM(ctx context.Context, vmName string) error

func (*InternalVMwareSource) PowerOnVM

func (s *InternalVMwareSource) PowerOnVM(ctx context.Context, vmLocation string) error

func (*InternalVMwareSource) VerifyBackgroundImport added in v0.5.0

func (s *InternalVMwareSource) VerifyBackgroundImport(ctx context.Context, instances migration.Instances) (migration.Instances, error)

VerifyBackgroundImport checks each supported disk for each VM for a corresponding ctk file for each VM that reports to support background import. Returns the updated instance objects.

func (*InternalVMwareSource) WithAdditionalRootCertificate

func (s *InternalVMwareSource) WithAdditionalRootCertificate(rootCert *x509.Certificate)

type InternalVMwareSourceSpecific

type InternalVMwareSourceSpecific struct {
	api.VMwareProperties `yaml:",inline"`
	// contains filtered or unexported fields
}

type PaginationResponse

type PaginationResponse struct {
	Results []any  `json:"results"`
	Count   int    `json:"result_count"`
	Cursor  string `json:"cursor"`
}

PaginationResponse handles paginated API responses.

type Source

type Source interface {
	// Connects to the source, using any source-specific details when the object was created.
	//
	// Returns an error if unable to connect (unable to reach remote host, bad credentials, etc).
	Connect(ctx context.Context) error

	// Performs a basic HTTP connectivity test to the source.
	//
	// Returns a status flag indicating the status and if a TLS certificate error occurred a copy of the untrusted TLS certificate.
	DoBasicConnectivityCheck() (api.ExternalConnectivityStatus, *x509.Certificate)

	// Disconnects from the source.
	//
	// Returns an error if there was a problem disconnecting from the source.
	Disconnect(ctx context.Context) error

	// WithAdditionalRootCertificate accepts an additional certificate, which
	// is added to the default CertPool used to validate server certificates
	// while connecting to the Source using TLS.
	WithAdditionalRootCertificate(rootCert *x509.Certificate)

	// Returns whether currently connected to the source or not.
	IsConnected() bool

	// Timeout for connections to the source.
	Timeout() time.Duration

	// Returns the human-readable name for this source.
	GetName() string

	// Returns an array of all VMs available from the source, encoded as Instances.
	//
	// Returns an error if there is a problem fetching VMs or their properties.
	GetAllVMs(ctx context.Context, sourceSpecificIDs ...string) (migration.Instances, migration.Networks, migration.Warnings, error)

	// Deletes a given snapshot, if it exists, from the specified VM.
	//
	// Returns an error if there is a problem deleting the snapshot.
	DeleteVMSnapshot(ctx context.Context, vmName string, snapshotName string) error

	// Initiates a disk import cycle from the source to the locally running VM.
	//
	// Important: This should only be called from the migration manager worker, as it will attempt to
	// directly write to raw disk devices, overwriting any data that might already be present.
	//
	// Returns an error if there is a problem importing the disk(s).
	ImportDisks(ctx context.Context, vmName string, sdkPath string, disks []api.InstancePropertiesDisk, statusCallback func(string, bool)) error

	// IsRunning returns whether the VM is running.
	IsRunning(ctx context.Context, vmName string) (bool, error)

	// Powers off a VM.
	//
	// Returns an error if there was a problem shutting down the VM.
	PowerOffVM(ctx context.Context, vmName string) error

	// Powers on a VM.
	//
	// Returns an error if there was a problem starting the VM.
	PowerOnVM(ctx context.Context, vmName string) error

	// Dump source data.
	Dump(ctx context.Context) error

	// VerifyBackgroundImport checks each supported disk for each VM to verify whether background import is supported, returning the list of UUIDs that fail the check.
	VerifyBackgroundImport(ctx context.Context, instances migration.Instances) (migration.Instances, error)

	// GetBackgroundImport returns the background import support property of an instance by its UUID.
	GetBackgroundImport(ctx context.Context, instUUID uuid.UUID) (bool, error)

	// EnableBackgroundImport enables background import support for the instance by its UUID.
	EnableBackgroundImport(ctx context.Context, instUUID uuid.UUID) error
}

Source interface definition for all migration manager sources.

type SourceMock

type SourceMock struct {
	// ConnectFunc mocks the Connect method.
	ConnectFunc func(ctx context.Context) error

	// DeleteVMSnapshotFunc mocks the DeleteVMSnapshot method.
	DeleteVMSnapshotFunc func(ctx context.Context, vmName string, snapshotName string) error

	// DisconnectFunc mocks the Disconnect method.
	DisconnectFunc func(ctx context.Context) error

	// DoBasicConnectivityCheckFunc mocks the DoBasicConnectivityCheck method.
	DoBasicConnectivityCheckFunc func() (api.ExternalConnectivityStatus, *x509.Certificate)

	// DumpFunc mocks the Dump method.
	DumpFunc func(ctx context.Context) error

	// EnableBackgroundImportFunc mocks the EnableBackgroundImport method.
	EnableBackgroundImportFunc func(ctx context.Context, instUUID uuid.UUID) error

	// GetAllVMsFunc mocks the GetAllVMs method.
	GetAllVMsFunc func(ctx context.Context, sourceSpecificIDs ...string) (migration.Instances, migration.Networks, migration.Warnings, error)

	// GetBackgroundImportFunc mocks the GetBackgroundImport method.
	GetBackgroundImportFunc func(ctx context.Context, instUUID uuid.UUID) (bool, error)

	// GetNameFunc mocks the GetName method.
	GetNameFunc func() string

	// ImportDisksFunc mocks the ImportDisks method.
	ImportDisksFunc func(ctx context.Context, vmName string, sdkPath string, disks []api.InstancePropertiesDisk, statusCallback func(string, bool)) error

	// IsConnectedFunc mocks the IsConnected method.
	IsConnectedFunc func() bool

	// IsRunningFunc mocks the IsRunning method.
	IsRunningFunc func(ctx context.Context, vmName string) (bool, error)

	// PowerOffVMFunc mocks the PowerOffVM method.
	PowerOffVMFunc func(ctx context.Context, vmName string) error

	// PowerOnVMFunc mocks the PowerOnVM method.
	PowerOnVMFunc func(ctx context.Context, vmName string) error

	// TimeoutFunc mocks the Timeout method.
	TimeoutFunc func() time.Duration

	// VerifyBackgroundImportFunc mocks the VerifyBackgroundImport method.
	VerifyBackgroundImportFunc func(ctx context.Context, instances migration.Instances) (migration.Instances, error)

	// WithAdditionalRootCertificateFunc mocks the WithAdditionalRootCertificate method.
	WithAdditionalRootCertificateFunc func(rootCert *x509.Certificate)
	// contains filtered or unexported fields
}

SourceMock is a mock implementation of Source.

func TestSomethingThatUsesSource(t *testing.T) {

	// make and configure a mocked Source
	mockedSource := &SourceMock{
		ConnectFunc: func(ctx context.Context) error {
			panic("mock out the Connect method")
		},
		DeleteVMSnapshotFunc: func(ctx context.Context, vmName string, snapshotName string) error {
			panic("mock out the DeleteVMSnapshot method")
		},
		DisconnectFunc: func(ctx context.Context) error {
			panic("mock out the Disconnect method")
		},
		DoBasicConnectivityCheckFunc: func() (api.ExternalConnectivityStatus, *x509.Certificate) {
			panic("mock out the DoBasicConnectivityCheck method")
		},
		DumpFunc: func(ctx context.Context) error {
			panic("mock out the Dump method")
		},
		EnableBackgroundImportFunc: func(ctx context.Context, instUUID uuid.UUID) error {
			panic("mock out the EnableBackgroundImport method")
		},
		GetAllVMsFunc: func(ctx context.Context, sourceSpecificIDs ...string) (migration.Instances, migration.Networks, migration.Warnings, error) {
			panic("mock out the GetAllVMs method")
		},
		GetBackgroundImportFunc: func(ctx context.Context, instUUID uuid.UUID) (bool, error) {
			panic("mock out the GetBackgroundImport method")
		},
		GetNameFunc: func() string {
			panic("mock out the GetName method")
		},
		ImportDisksFunc: func(ctx context.Context, vmName string, sdkPath string, disks []api.InstancePropertiesDisk, statusCallback func(string, bool)) error {
			panic("mock out the ImportDisks method")
		},
		IsConnectedFunc: func() bool {
			panic("mock out the IsConnected method")
		},
		IsRunningFunc: func(ctx context.Context, vmName string) (bool, error) {
			panic("mock out the IsRunning method")
		},
		PowerOffVMFunc: func(ctx context.Context, vmName string) error {
			panic("mock out the PowerOffVM method")
		},
		PowerOnVMFunc: func(ctx context.Context, vmName string) error {
			panic("mock out the PowerOnVM method")
		},
		TimeoutFunc: func() time.Duration {
			panic("mock out the Timeout method")
		},
		VerifyBackgroundImportFunc: func(ctx context.Context, instances migration.Instances) (migration.Instances, error) {
			panic("mock out the VerifyBackgroundImport method")
		},
		WithAdditionalRootCertificateFunc: func(rootCert *x509.Certificate)  {
			panic("mock out the WithAdditionalRootCertificate method")
		},
	}

	// use mockedSource in code that requires Source
	// and then make assertions.

}

func (*SourceMock) Connect

func (mock *SourceMock) Connect(ctx context.Context) error

Connect calls ConnectFunc.

func (*SourceMock) ConnectCalls

func (mock *SourceMock) ConnectCalls() []struct {
	Ctx context.Context
}

ConnectCalls gets all the calls that were made to Connect. Check the length with:

len(mockedSource.ConnectCalls())

func (*SourceMock) DeleteVMSnapshot

func (mock *SourceMock) DeleteVMSnapshot(ctx context.Context, vmName string, snapshotName string) error

DeleteVMSnapshot calls DeleteVMSnapshotFunc.

func (*SourceMock) DeleteVMSnapshotCalls

func (mock *SourceMock) DeleteVMSnapshotCalls() []struct {
	Ctx          context.Context
	VmName       string
	SnapshotName string
}

DeleteVMSnapshotCalls gets all the calls that were made to DeleteVMSnapshot. Check the length with:

len(mockedSource.DeleteVMSnapshotCalls())

func (*SourceMock) Disconnect

func (mock *SourceMock) Disconnect(ctx context.Context) error

Disconnect calls DisconnectFunc.

func (*SourceMock) DisconnectCalls

func (mock *SourceMock) DisconnectCalls() []struct {
	Ctx context.Context
}

DisconnectCalls gets all the calls that were made to Disconnect. Check the length with:

len(mockedSource.DisconnectCalls())

func (*SourceMock) DoBasicConnectivityCheck

func (mock *SourceMock) DoBasicConnectivityCheck() (api.ExternalConnectivityStatus, *x509.Certificate)

DoBasicConnectivityCheck calls DoBasicConnectivityCheckFunc.

func (*SourceMock) DoBasicConnectivityCheckCalls

func (mock *SourceMock) DoBasicConnectivityCheckCalls() []struct {
}

DoBasicConnectivityCheckCalls gets all the calls that were made to DoBasicConnectivityCheck. Check the length with:

len(mockedSource.DoBasicConnectivityCheckCalls())

func (*SourceMock) Dump added in v0.6.2

func (mock *SourceMock) Dump(ctx context.Context) error

Dump calls DumpFunc.

func (*SourceMock) DumpCalls added in v0.6.2

func (mock *SourceMock) DumpCalls() []struct {
	Ctx context.Context
}

DumpCalls gets all the calls that were made to Dump. Check the length with:

len(mockedSource.DumpCalls())

func (*SourceMock) EnableBackgroundImport added in v0.6.5

func (mock *SourceMock) EnableBackgroundImport(ctx context.Context, instUUID uuid.UUID) error

EnableBackgroundImport calls EnableBackgroundImportFunc.

func (*SourceMock) EnableBackgroundImportCalls added in v0.6.5

func (mock *SourceMock) EnableBackgroundImportCalls() []struct {
	Ctx      context.Context
	InstUUID uuid.UUID
}

EnableBackgroundImportCalls gets all the calls that were made to EnableBackgroundImport. Check the length with:

len(mockedSource.EnableBackgroundImportCalls())

func (*SourceMock) GetAllVMs

func (mock *SourceMock) GetAllVMs(ctx context.Context, sourceSpecificIDs ...string) (migration.Instances, migration.Networks, migration.Warnings, error)

GetAllVMs calls GetAllVMsFunc.

func (*SourceMock) GetAllVMsCalls

func (mock *SourceMock) GetAllVMsCalls() []struct {
	Ctx               context.Context
	SourceSpecificIDs []string
}

GetAllVMsCalls gets all the calls that were made to GetAllVMs. Check the length with:

len(mockedSource.GetAllVMsCalls())

func (*SourceMock) GetBackgroundImport added in v0.5.0

func (mock *SourceMock) GetBackgroundImport(ctx context.Context, instUUID uuid.UUID) (bool, error)

GetBackgroundImport calls GetBackgroundImportFunc.

func (*SourceMock) GetBackgroundImportCalls added in v0.5.0

func (mock *SourceMock) GetBackgroundImportCalls() []struct {
	Ctx      context.Context
	InstUUID uuid.UUID
}

GetBackgroundImportCalls gets all the calls that were made to GetBackgroundImport. Check the length with:

len(mockedSource.GetBackgroundImportCalls())

func (*SourceMock) GetName

func (mock *SourceMock) GetName() string

GetName calls GetNameFunc.

func (*SourceMock) GetNameCalls

func (mock *SourceMock) GetNameCalls() []struct {
}

GetNameCalls gets all the calls that were made to GetName. Check the length with:

len(mockedSource.GetNameCalls())

func (*SourceMock) ImportDisks

func (mock *SourceMock) ImportDisks(ctx context.Context, vmName string, sdkPath string, disks []api.InstancePropertiesDisk, statusCallback func(string, bool)) error

ImportDisks calls ImportDisksFunc.

func (*SourceMock) ImportDisksCalls

func (mock *SourceMock) ImportDisksCalls() []struct {
	Ctx            context.Context
	VmName         string
	SdkPath        string
	Disks          []api.InstancePropertiesDisk
	StatusCallback func(string, bool)
}

ImportDisksCalls gets all the calls that were made to ImportDisks. Check the length with:

len(mockedSource.ImportDisksCalls())

func (*SourceMock) IsConnected

func (mock *SourceMock) IsConnected() bool

IsConnected calls IsConnectedFunc.

func (*SourceMock) IsConnectedCalls

func (mock *SourceMock) IsConnectedCalls() []struct {
}

IsConnectedCalls gets all the calls that were made to IsConnected. Check the length with:

len(mockedSource.IsConnectedCalls())

func (*SourceMock) IsRunning added in v0.6.1

func (mock *SourceMock) IsRunning(ctx context.Context, vmName string) (bool, error)

IsRunning calls IsRunningFunc.

func (*SourceMock) IsRunningCalls added in v0.6.1

func (mock *SourceMock) IsRunningCalls() []struct {
	Ctx    context.Context
	VmName string
}

IsRunningCalls gets all the calls that were made to IsRunning. Check the length with:

len(mockedSource.IsRunningCalls())

func (*SourceMock) PowerOffVM

func (mock *SourceMock) PowerOffVM(ctx context.Context, vmName string) error

PowerOffVM calls PowerOffVMFunc.

func (*SourceMock) PowerOffVMCalls

func (mock *SourceMock) PowerOffVMCalls() []struct {
	Ctx    context.Context
	VmName string
}

PowerOffVMCalls gets all the calls that were made to PowerOffVM. Check the length with:

len(mockedSource.PowerOffVMCalls())

func (*SourceMock) PowerOnVM added in v0.6.1

func (mock *SourceMock) PowerOnVM(ctx context.Context, vmName string) error

PowerOnVM calls PowerOnVMFunc.

func (*SourceMock) PowerOnVMCalls added in v0.6.1

func (mock *SourceMock) PowerOnVMCalls() []struct {
	Ctx    context.Context
	VmName string
}

PowerOnVMCalls gets all the calls that were made to PowerOnVM. Check the length with:

len(mockedSource.PowerOnVMCalls())

func (*SourceMock) Timeout added in v0.6.0

func (mock *SourceMock) Timeout() time.Duration

Timeout calls TimeoutFunc.

func (*SourceMock) TimeoutCalls added in v0.6.0

func (mock *SourceMock) TimeoutCalls() []struct {
}

TimeoutCalls gets all the calls that were made to Timeout. Check the length with:

len(mockedSource.TimeoutCalls())

func (*SourceMock) VerifyBackgroundImport added in v0.5.0

func (mock *SourceMock) VerifyBackgroundImport(ctx context.Context, instances migration.Instances) (migration.Instances, error)

VerifyBackgroundImport calls VerifyBackgroundImportFunc.

func (*SourceMock) VerifyBackgroundImportCalls added in v0.5.0

func (mock *SourceMock) VerifyBackgroundImportCalls() []struct {
	Ctx       context.Context
	Instances migration.Instances
}

VerifyBackgroundImportCalls gets all the calls that were made to VerifyBackgroundImport. Check the length with:

len(mockedSource.VerifyBackgroundImportCalls())

func (*SourceMock) WithAdditionalRootCertificate

func (mock *SourceMock) WithAdditionalRootCertificate(rootCert *x509.Certificate)

WithAdditionalRootCertificate calls WithAdditionalRootCertificateFunc.

func (*SourceMock) WithAdditionalRootCertificateCalls

func (mock *SourceMock) WithAdditionalRootCertificateCalls() []struct {
	RootCert *x509.Certificate
}

WithAdditionalRootCertificateCalls gets all the calls that were made to WithAdditionalRootCertificate. Check the length with:

len(mockedSource.WithAdditionalRootCertificateCalls())

type VersionResponse

type VersionResponse struct {
	Version string `json:"product_version"`
	Build   string `json:"product_build_number"`
}

VersionResponse is returned from the NSX API when fetching the version.

Jump to

Keyboard shortcuts

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