source

package
v0.0.0-pre.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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) GetAllNetworks

func (s *InternalSource) GetAllNetworks(ctx context.Context) ([]api.Network, error)

func (*InternalSource) GetAllVMs

func (*InternalSource) GetDatabaseID

func (s *InternalSource) GetDatabaseID() (int, error)

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) SetInsecureTLS

func (s *InternalSource) SetInsecureTLS(insecure bool) error

func (*InternalSource) WithAdditionalRootCertificate

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

type InternalVMwareSource

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

func NewInternalVMwareSourceFrom

func NewInternalVMwareSourceFrom(apiSource api.Source) (*InternalVMwareSource, error)

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) GetAllNetworks

func (s *InternalVMwareSource) GetAllNetworks(ctx context.Context) ([]api.Network, error)

func (*InternalVMwareSource) GetAllVMs

func (*InternalVMwareSource) ImportDisks

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

func (*InternalVMwareSource) PowerOffVM

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

func (*InternalVMwareSource) SetInsecureTLS

func (s *InternalVMwareSource) SetInsecureTLS(insecure bool) error

func (*InternalVMwareSource) WithAdditionalRootCertificate

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

type InternalVMwareSourceSpecific

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

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

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

	// Toggles whether TLS verification should be skipped or not.
	//
	// As this can enable MITM-style attacks, in general this SHOULD NOT be used.
	//
	// Returns an error if called while connected to a source.
	SetInsecureTLS(insecure bool) 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 *tls.Certificate)

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

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

	// Returns a unique ID for this source that can be used when interacting with the database.
	//
	// Attempting to get an ID for a freshly-created source that hasn't yet been added to the database
	// via AddSsource() or retrieved via GetSource()/GetAllSources() will return an error.
	GetDatabaseID() (int, error)

	// 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) (migration.Instances, error)

	// Returns an array of all networks available from the source, encoded as Networks.
	//
	// Returns an error if there is a problem fetching networks or their properties.
	GetAllNetworks(ctx context.Context) ([]api.Network, 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, statusCallback func(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
}

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

	// GetAllNetworksFunc mocks the GetAllNetworks method.
	GetAllNetworksFunc func(ctx context.Context) ([]api.Network, error)

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

	// GetDatabaseIDFunc mocks the GetDatabaseID method.
	GetDatabaseIDFunc func() (int, error)

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

	// ImportDisksFunc mocks the ImportDisks method.
	ImportDisksFunc func(ctx context.Context, vmName string, statusCallback func(string, bool)) error

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

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

	// SetInsecureTLSFunc mocks the SetInsecureTLS method.
	SetInsecureTLSFunc func(insecure bool) error

	// WithAdditionalRootCertificateFunc mocks the WithAdditionalRootCertificate method.
	WithAdditionalRootCertificateFunc func(rootCert *tls.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")
		},
		GetAllNetworksFunc: func(ctx context.Context) ([]api.Network, error) {
			panic("mock out the GetAllNetworks method")
		},
		GetAllVMsFunc: func(ctx context.Context) (migration.Instances, error) {
			panic("mock out the GetAllVMs method")
		},
		GetDatabaseIDFunc: func() (int, error) {
			panic("mock out the GetDatabaseID method")
		},
		GetNameFunc: func() string {
			panic("mock out the GetName method")
		},
		ImportDisksFunc: func(ctx context.Context, vmName string, statusCallback func(string, bool)) error {
			panic("mock out the ImportDisks method")
		},
		IsConnectedFunc: func() bool {
			panic("mock out the IsConnected method")
		},
		PowerOffVMFunc: func(ctx context.Context, vmName string) error {
			panic("mock out the PowerOffVM method")
		},
		SetInsecureTLSFunc: func(insecure bool) error {
			panic("mock out the SetInsecureTLS method")
		},
		WithAdditionalRootCertificateFunc: func(rootCert *tls.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) GetAllNetworks

func (mock *SourceMock) GetAllNetworks(ctx context.Context) ([]api.Network, error)

GetAllNetworks calls GetAllNetworksFunc.

func (*SourceMock) GetAllNetworksCalls

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

GetAllNetworksCalls gets all the calls that were made to GetAllNetworks. Check the length with:

len(mockedSource.GetAllNetworksCalls())

func (*SourceMock) GetAllVMs

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

GetAllVMs calls GetAllVMsFunc.

func (*SourceMock) GetAllVMsCalls

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

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

len(mockedSource.GetAllVMsCalls())

func (*SourceMock) GetDatabaseID

func (mock *SourceMock) GetDatabaseID() (int, error)

GetDatabaseID calls GetDatabaseIDFunc.

func (*SourceMock) GetDatabaseIDCalls

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

GetDatabaseIDCalls gets all the calls that were made to GetDatabaseID. Check the length with:

len(mockedSource.GetDatabaseIDCalls())

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, statusCallback func(string, bool)) error

ImportDisks calls ImportDisksFunc.

func (*SourceMock) ImportDisksCalls

func (mock *SourceMock) ImportDisksCalls() []struct {
	Ctx            context.Context
	VmName         string
	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) 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) SetInsecureTLS

func (mock *SourceMock) SetInsecureTLS(insecure bool) error

SetInsecureTLS calls SetInsecureTLSFunc.

func (*SourceMock) SetInsecureTLSCalls

func (mock *SourceMock) SetInsecureTLSCalls() []struct {
	Insecure bool
}

SetInsecureTLSCalls gets all the calls that were made to SetInsecureTLS. Check the length with:

len(mockedSource.SetInsecureTLSCalls())

func (*SourceMock) WithAdditionalRootCertificate

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

WithAdditionalRootCertificate calls WithAdditionalRootCertificateFunc.

func (*SourceMock) WithAdditionalRootCertificateCalls

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

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

len(mockedSource.WithAdditionalRootCertificateCalls())

Jump to

Keyboard shortcuts

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