vsphere

package
v1.29.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 License: Apache-2.0 Imports: 35 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(dst interface{}, src interface{}) error

Copy Make a deep copy from src into dst.

func ToCIDR

func ToCIDR(address, netmask string) string

ToCIDR returns address in cidr format ww.xx.yy.zz/NN

Types

type Client

type Client struct {
	Client        *govmomi.Client
	Configuration *Configuration
}

Client Client wrapper

func (*Client) Datacenter

func (c *Client) Datacenter(ref types.ManagedObjectReference) *object.Datacenter

Datacenter return a Datacenter

func (*Client) Datastore

func (c *Client) Datastore(ref types.ManagedObjectReference) *object.Datastore

Datastore create govmomi Datastore object

func (*Client) GetClient

func (c *Client) GetClient() *govmomi.Client

GetClient return client

func (*Client) GetDatacenter

func (c *Client) GetDatacenter(ctx *context.Context, name string) (*Datacenter, error)

GetDatacenter return the datacenter

func (*Client) VimClient

func (c *Client) VimClient() *vim25.Client

VimClient return vim25 client

func (*Client) VirtualMachine

func (c *Client) VirtualMachine(ref types.ManagedObjectReference) *object.VirtualMachine

VirtualMachine map govmomi VirtualMachine

type Configuration

type Configuration struct {
	URL           string        `json:"url"`
	UserName      string        `json:"uid"`
	Password      string        `json:"password"`
	Insecure      bool          `json:"insecure"`
	DataCenter    string        `json:"dc"`
	DataStore     string        `json:"datastore"`
	Resource      string        `json:"resource-pool"`
	VMBasePath    string        `json:"vmFolder"`
	Timeout       time.Duration `json:"timeout"`
	TemplateName  string        `json:"template-name"`
	Template      bool          `json:"template"`
	LinkedClone   bool          `json:"linked"`
	AllowUpgrade  bool          `json:"allow-upgrade"`
	Customization string        `json:"customization"`
	Network       *Network      `json:"network"`
	TestMode      bool          `json:"-"`
}

Configuration declares vsphere connection info

func (*Configuration) Clone

func (conf *Configuration) Clone(nodeIndex int) (*Configuration, error)

Clone duplicate the conf, change ip address in network config if needed

func (*Configuration) Copy added in v1.20.14

func (conf *Configuration) Copy() *Configuration

Create a shadow copy

func (*Configuration) Create

func (conf *Configuration) Create(name string, userName, authKey string, cloudInit interface{}, network *Network, annotation string, expandHardDrive bool, memory, cpus, disk, nodeIndex int) (*VirtualMachine, error)

Create will create a named VM not powered memory and disk are in megabytes

func (*Configuration) CreateWithContext

func (conf *Configuration) CreateWithContext(ctx *context.Context, name string, userName, authKey string, cloudInit interface{}, network *Network, annotation string, expandHardDrive bool, memory, cpus, disk, nodeIndex int) (*VirtualMachine, error)

CreateWithContext will create a named VM not powered memory and disk are in megabytes

func (*Configuration) Delete

func (conf *Configuration) Delete(name string) error

Delete a VM by name

func (*Configuration) DeleteWithContext

func (conf *Configuration) DeleteWithContext(ctx *context.Context, name string) error

DeleteWithContext a VM by name

func (*Configuration) Exists added in v1.25.6

func (conf *Configuration) Exists(name string) bool

func (*Configuration) ExistsWithContext added in v1.25.6

func (conf *Configuration) ExistsWithContext(ctx *context.Context, name string) bool

ExistsWithContext return the current status of VM by name

func (*Configuration) FindInterfaceByName added in v1.21.8

func (conf *Configuration) FindInterfaceByName(networkName string) *NetworkInterface

func (*Configuration) FindPreferredIPAddress added in v1.21.8

func (conf *Configuration) FindPreferredIPAddress(interfaces []NetworkInterface) string

func (*Configuration) GetClient

func (conf *Configuration) GetClient(ctx *context.Context) (*Client, error)

GetClient create a new govomi client

func (*Configuration) GetHostSystem added in v1.20.14

func (conf *Configuration) GetHostSystem(name string) (string, error)

GetHostSystem return the host where the virtual machine leave

func (*Configuration) GetHostSystemWithContext added in v1.20.14

func (conf *Configuration) GetHostSystemWithContext(ctx *context.Context, name string) (string, error)

func (*Configuration) PowerOff

func (conf *Configuration) PowerOff(name string) error

PowerOff power off a VM by name

func (*Configuration) PowerOffWithContext

func (conf *Configuration) PowerOffWithContext(ctx *context.Context, name string) error

PowerOffWithContext power off a VM by name

func (*Configuration) PowerOn

func (conf *Configuration) PowerOn(name string) error

PowerOn power on a VM by name

func (*Configuration) PowerOnWithContext

func (conf *Configuration) PowerOnWithContext(ctx *context.Context, name string) error

PowerOnWithContext power on a VM by name

func (*Configuration) RetrieveNetworkInfos added in v1.20.14

func (conf *Configuration) RetrieveNetworkInfos(name string, nodeIndex int) error

func (*Configuration) RetrieveNetworkInfosWithContext added in v1.20.14

func (conf *Configuration) RetrieveNetworkInfosWithContext(ctx *context.Context, name string, nodeIndex int) error

func (*Configuration) SetAutoStart added in v1.20.5

func (conf *Configuration) SetAutoStart(esxi, name string, startOrder int) error

SetAutoStart set autostart for the VM

func (*Configuration) SetAutoStartWithContext added in v1.20.5

func (conf *Configuration) SetAutoStartWithContext(ctx *context.Context, esxi, name string, startOrder int) error

SetAutoStartWithContext set autostart for the VM

func (*Configuration) ShutdownGuest

func (conf *Configuration) ShutdownGuest(name string) error

ShutdownGuest power off a VM by name

func (*Configuration) ShutdownGuestWithContext

func (conf *Configuration) ShutdownGuestWithContext(ctx *context.Context, name string) error

ShutdownGuestWithContext power off a VM by name

func (*Configuration) Status

func (conf *Configuration) Status(name string) (*Status, error)

Status return the current status of VM by name

func (*Configuration) StatusWithContext

func (conf *Configuration) StatusWithContext(ctx *context.Context, name string) (*Status, error)

StatusWithContext return the current status of VM by name

func (*Configuration) UUID added in v1.24.6

func (conf *Configuration) UUID(name string) (string, error)

UUID get VM UUID by name

func (*Configuration) UUIDWithContext added in v1.24.6

func (conf *Configuration) UUIDWithContext(ctx *context.Context, name string) (string, error)

UUID get VM UUID by name

func (*Configuration) VirtualMachine

func (conf *Configuration) VirtualMachine(name string) (*VirtualMachine, error)

VirtualMachine Retrieve VM by name

func (*Configuration) VirtualMachineList

func (conf *Configuration) VirtualMachineList() ([]*VirtualMachine, error)

VirtualMachineList return all VM for the current datastore

func (*Configuration) VirtualMachineListWithContext

func (conf *Configuration) VirtualMachineListWithContext(ctx *context.Context) ([]*VirtualMachine, error)

VirtualMachineListWithContext return all VM for the current datastore

func (*Configuration) VirtualMachineWithContext

func (conf *Configuration) VirtualMachineWithContext(ctx *context.Context, name string) (*VirtualMachine, error)

VirtualMachineWithContext Retrieve VM by name

func (*Configuration) WaitForIP

func (conf *Configuration) WaitForIP(name string) (string, error)

WaitForIP wait ip a VM by name

func (*Configuration) WaitForIPWithContext

func (conf *Configuration) WaitForIPWithContext(ctx *context.Context, name string) (string, error)

WaitForIPWithContext wait ip a VM by name

func (*Configuration) WaitForToolsRunning added in v1.15.11

func (conf *Configuration) WaitForToolsRunning(name string) (bool, error)

WaitForToolsRunning wait vmware tools is running a VM by name

func (*Configuration) WaitForToolsRunningWithContext added in v1.15.11

func (conf *Configuration) WaitForToolsRunningWithContext(ctx *context.Context, name string) (bool, error)

WaitForToolsRunningWithContext wait vmware tools is running a VM by name

type Datacenter

type Datacenter struct {
	Ref    types.ManagedObjectReference
	Name   string
	Client *Client
}

Datacenter represent a datacenter

func (*Datacenter) Datacenter

func (dc *Datacenter) Datacenter(ctx *context.Context) *object.Datacenter

Datacenter return a Datacenter

func (*Datacenter) GetDatastore

func (dc *Datacenter) GetDatastore(ctx *context.Context, name string) (*Datastore, error)

GetDatastore retrieve named datastore

func (*Datacenter) GetHostAutoStartManager added in v1.20.5

func (dc *Datacenter) GetHostAutoStartManager(ctx *context.Context, esxi string) (*HostAutoStartManager, error)

GetHostAutoStartManager return the HostAutoStartManager

func (*Datacenter) GetHostSystem added in v1.20.5

func (dc *Datacenter) GetHostSystem(ctx *context.Context, esxi string) (*object.HostSystem, error)

GetHostSystem return the default hostsystem

func (*Datacenter) NewFinder

func (dc *Datacenter) NewFinder(ctx *context.Context) *find.Finder

NewFinder create a finder

func (*Datacenter) VimClient

func (dc *Datacenter) VimClient() *vim25.Client

VimClient return the VIM25 client

type Datastore

type Datastore struct {
	Ref        types.ManagedObjectReference
	Name       string
	Datacenter *Datacenter
}

Datastore datastore wrapper

func (*Datastore) CreateVirtualMachine

func (ds *Datastore) CreateVirtualMachine(ctx *context.Context, name, templateName, vmFolder, resourceName string, template bool, linkedClone bool, network *Network, customization string, nodeIndex int) (*VirtualMachine, error)

CreateVirtualMachine create a new virtual machine

func (*Datastore) Datastore

func (ds *Datastore) Datastore(ctx *context.Context) *object.Datastore

Datastore create govmomi Datastore object

func (*Datastore) List

func (ds *Datastore) List(ctx *context.Context) ([]*VirtualMachine, error)

List list VM inside the datastore

func (*Datastore) ListPath

ListPath return object list matching path

func (*Datastore) VimClient

func (ds *Datastore) VimClient() *vim25.Client

VimClient return the VIM25 client

func (*Datastore) VirtualMachine

func (ds *Datastore) VirtualMachine(ctx *context.Context, name string) (*VirtualMachine, error)

VirtualMachine retrieve the specified virtual machine

type GuestInfos

type GuestInfos map[string]string

GuestInfos the guest infos Must not start with `guestinfo.`

type HostAutoStartManager added in v1.20.5

type HostAutoStartManager struct {
	Ref        types.ManagedObjectReference
	Datacenter *Datacenter
}

func (*HostAutoStartManager) SetAutoStart added in v1.20.5

func (h *HostAutoStartManager) SetAutoStart(ctx *context.Context, datastore, name string, startOrder int) error

type Nameserver

type Nameserver struct {
	Search    []string `json:"search,omitempty" yaml:"search,omitempty"`
	Addresses []string `json:"addresses,omitempty" yaml:"addresses,omitempty"`
}

Nameserver declaration

type Network

type Network struct {
	Domain     string              `json:"domain,omitempty" yaml:"domain,omitempty"`
	Interfaces []*NetworkInterface `json:"interfaces,omitempty" yaml:"interfaces,omitempty"`
	DNS        *NetworkResolv      `json:"dns,omitempty" yaml:"dns,omitempty"`
}

Network describes a card adapter

func (*Network) Devices

func (net *Network) Devices(ctx *context.Context, devices object.VirtualDeviceList, dc *Datacenter, nodeIndex int) (object.VirtualDeviceList, error)

Devices return all devices

func (*Network) GetCloudInitNetwork

func (net *Network) GetCloudInitNetwork(nodeIndex int) *NetworkDeclare

GetCloudInitNetwork create cloud-init object

func (*Network) GetDeclaredExistingInterfaces

func (net *Network) GetDeclaredExistingInterfaces() []*NetworkInterface

GetDeclaredExistingInterfaces return the declared existing interfaces

func (*Network) UpdateMacAddressTable added in v1.20.14

func (net *Network) UpdateMacAddressTable(nodeIndex int)

type NetworkAdapter

type NetworkAdapter struct {
	DHCP4         bool                      `json:"dhcp4,omitempty" yaml:"dhcp4,omitempty"`
	NicName       *string                   `json:"set-name,omitempty" yaml:"set-name,omitempty"`
	Match         *map[string]string        `json:"match,omitempty" yaml:"match,omitempty"`
	Gateway4      *string                   `json:"gateway4,omitempty" yaml:"gateway4,omitempty"`
	Addresses     *[]string                 `json:"addresses,omitempty" yaml:"addresses,omitempty"`
	Nameservers   *Nameserver               `json:"nameservers,omitempty" yaml:"nameservers,omitempty"`
	DHCPOverrides *map[string]interface{}   `json:"dhcp4-overrides,omitempty" yaml:"dhcp4-overrides,omitempty"`
	Routes        *[]v1alpha1.NetworkRoutes `json:"routes,omitempty" yaml:"routes,omitempty"`
}

NetworkAdapter wrapper

type NetworkConfig

type NetworkConfig struct {
	InstanceID    string          `json:"instance-id,omitempty" yaml:"instance-id,omitempty"`
	LocalHostname string          `json:"local-hostname,omitempty" yaml:"local-hostname,omitempty"`
	Hostname      string          `json:"hostname,omitempty" yaml:"hostname,omitempty"`
	Network       *NetworkDeclare `json:"network,omitempty" yaml:"network,omitempty"`
}

NetworkConfig wrapper

type NetworkDeclare

type NetworkDeclare struct {
	Version   int                        `json:"version,omitempty" yaml:"version,omitempty"`
	Ethernets map[string]*NetworkAdapter `json:"ethernets,omitempty" yaml:"ethernets,omitempty"`
}

NetworkDeclare wrapper

type NetworkInterface

type NetworkInterface struct {
	Primary     bool                     `json:"primary,omitempty" yaml:"primary,omitempty"`
	Existing    bool                     `json:"exists,omitempty" yaml:"exists,omitempty"`
	NetworkName string                   `json:"network,omitempty" yaml:"network,omitempty"`
	Adapter     string                   `json:"adapter,omitempty" yaml:"adapter,omitempty"`
	MacAddress  string                   `json:"mac-address,omitempty" yaml:"mac-address,omitempty"`
	NicName     string                   `json:"nic,omitempty" yaml:"nic,omitempty"`
	DHCP        bool                     `json:"dhcp,omitempty" yaml:"dhcp,omitempty"`
	UseRoutes   bool                     `default:"true" json:"use-dhcp-routes,omitempty" yaml:"use-dhcp-routes,omitempty"`
	IPAddress   string                   `json:"address,omitempty" yaml:"address,omitempty"`
	Netmask     string                   `json:"netmask,omitempty" yaml:"netmask,omitempty"`
	Gateway     string                   `json:"gateway,omitempty" yaml:"gateway,omitempty"`
	Routes      []v1alpha1.NetworkRoutes `json:"routes,omitempty" yaml:"routes,omitempty"`
	// contains filtered or unexported fields
}

NetworkInterface declare single interface

func (*NetworkInterface) AttachMacAddress added in v1.20.14

func (net *NetworkInterface) AttachMacAddress(address string, nodeIndex int)

func (*NetworkInterface) Change

func (net *NetworkInterface) Change(device types.BaseVirtualDevice, update types.BaseVirtualDevice)

Change applies update backing and hardware address changes to the given network device.

func (*NetworkInterface) ChangeAddress

func (net *NetworkInterface) ChangeAddress(card *types.VirtualEthernetCard, nodeIndex int) bool

ChangeAddress just the mac adress

func (*NetworkInterface) Device

func (net *NetworkInterface) Device(ctx *context.Context, dc *Datacenter, nodeIndex int) (types.BaseVirtualDevice, error)

Device return a device

func (*NetworkInterface) GetMacAddress

func (net *NetworkInterface) GetMacAddress(nodeIndex int) string

GetMacAddress return a macaddress

func (*NetworkInterface) MatchInterface

func (net *NetworkInterface) MatchInterface(ctx *context.Context, dc *Datacenter, card *types.VirtualEthernetCard) (bool, error)

MatchInterface return if this interface match the virtual device Due missing read permission, I can't create BackingInfo network card, so I use collected info to construct backing info

func (*NetworkInterface) NeedToReconfigure

func (net *NetworkInterface) NeedToReconfigure(nodeIndex int) bool

NeedToReconfigure tell that we must set the mac address

func (*NetworkInterface) Reference

Reference return the network reference

func (*NetworkInterface) SetMacAddress

func (net *NetworkInterface) SetMacAddress(nodeIndex int, device types.BaseVirtualDevice) types.BaseVirtualDevice

SetMacAddress put mac address in the device

type NetworkResolv

type NetworkResolv struct {
	Search     []string `json:"search,omitempty" yaml:"search,omitempty"`
	Nameserver []string `json:"nameserver,omitempty" yaml:"nameserver,omitempty"`
}

NetworkResolv /etc/resolv.conf

type Status

type Status struct {
	Interfaces []NetworkInterface
	Powered    bool
}

Status shortened vm status

type VirtualMachine

type VirtualMachine struct {
	Ref       types.ManagedObjectReference
	Name      string
	Datastore *Datastore
}

VirtualMachine virtual machine wrapper

func (*VirtualMachine) Configure

func (vm *VirtualMachine) Configure(ctx *context.Context, userName, authKey string, cloudInit interface{}, network *Network, annotation string, expandHardDrive bool, memory, cpus, disk, nodeIndex int, allowUpgrade bool) error

Configure set characteristic of VM a virtual machine

func (*VirtualMachine) Delete

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

Delete delete the virtual machine

func (*VirtualMachine) HostSystem added in v1.20.14

func (vm *VirtualMachine) HostSystem(ctx *context.Context) (string, error)

func (VirtualMachine) IsSimulatorRunning added in v1.24.3

func (vm VirtualMachine) IsSimulatorRunning(ctx *context.Context) bool

IsSimulatorRunning returns true if VMware Tools is currently running in the guest OS, and false otherwise.

func (VirtualMachine) IsToolsRunning

func (vm VirtualMachine) IsToolsRunning(ctx *context.Context) (bool, error)

IsToolsRunning returns true if VMware Tools is currently running in the guest OS, and false otherwise.

func (*VirtualMachine) ListAddresses added in v1.21.8

func (vm *VirtualMachine) ListAddresses(ctx *context.Context) ([]NetworkInterface, error)

func (*VirtualMachine) PowerOff

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

PowerOff power off a virtual machine

func (*VirtualMachine) PowerOn

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

PowerOn power on a virtual machine

func (*VirtualMachine) SetGuestInfo

func (vm *VirtualMachine) SetGuestInfo(ctx *context.Context, guestInfos *GuestInfos) error

SetGuestInfo change guest ingos

func (*VirtualMachine) ShutdownGuest

func (vm *VirtualMachine) ShutdownGuest(ctx *context.Context) error

ShutdownGuest power off a virtual machine

func (*VirtualMachine) Status

func (vm *VirtualMachine) Status(ctx *context.Context) (*Status, error)

Status refresh status virtual machine

func (*VirtualMachine) UUID added in v1.24.6

func (vm *VirtualMachine) UUID(ctx *context.Context) string

func (*VirtualMachine) VimClient

func (vm *VirtualMachine) VimClient() *vim25.Client

VimClient return the VIM25 client

func (*VirtualMachine) VirtualMachine

func (vm *VirtualMachine) VirtualMachine(ctx *context.Context) *object.VirtualMachine

VirtualMachine return govmomi virtual machine

func (*VirtualMachine) WaitForIP

func (vm *VirtualMachine) WaitForIP(ctx *context.Context) (string, error)

WaitForIP wait ip

func (*VirtualMachine) WaitForToolsRunning added in v1.15.11

func (vm *VirtualMachine) WaitForToolsRunning(ctx *context.Context) (bool, error)

WaitForToolsRunning wait vmware tool starts

Jump to

Keyboard shortcuts

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