simulator

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2018 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Overview

Package simulator is a mock framework for the vSphere API.

See also: https://github.com/vmware/govmomi/blob/master/vcsim/README.md

Example

Example of extending the simulator to inject faults.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/vmware/govmomi"
	"github.com/vmware/govmomi/object"
	"github.com/vmware/govmomi/simulator"
	"github.com/vmware/govmomi/vim25/methods"
	"github.com/vmware/govmomi/vim25/soap"
	"github.com/vmware/govmomi/vim25/types"
)

// BusyVM changes the behavior of simulator.VirtualMachine
type BusyVM struct {
	*simulator.VirtualMachine
}

// Override simulator.VirtualMachine.PowerOffVMTask to inject faults
func (vm *BusyVM) PowerOffVMTask(req *types.PowerOffVM_Task) soap.HasFault {
	task := simulator.CreateTask(req.This, "powerOff", func(*simulator.Task) (types.AnyType, types.BaseMethodFault) {
		return nil, &types.TaskInProgress{}
	})

	return &methods.PowerOffVM_TaskBody{
		Res: &types.PowerOffVM_TaskResponse{
			Returnval: task.Run(),
		},
	}
}

// Add AcquireTicket method, not implemented by simulator.VirtualMachine
func (vm *BusyVM) AcquireTicket(req *types.AcquireTicket) soap.HasFault {
	body := &methods.AcquireTicketBody{}

	if req.TicketType != "mks" {
		body.Fault_ = simulator.Fault("", &types.InvalidArgument{})
	}

	body.Res = &types.AcquireTicketResponse{
		Returnval: types.VirtualMachineTicket{
			Ticket: "welcome 2 the machine",
		},
	}

	return body
}

// Example of extending the simulator to inject faults.
func main() {
	ctx := context.Background()
	model := simulator.VPX()

	defer model.Remove()
	_ = model.Create()

	s := model.Service.NewServer()
	defer s.Close()

	// NewClient connects to s.URL over https and invokes 2 SOAP methods (RetrieveServiceContent + Login)
	c, _ := govmomi.NewClient(ctx, s.URL, true)

	// Shortcut to choose any VM, rather than using the more verbose Finder or ContainerView.
	obj := simulator.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
	// Validate VM is powered on
	if obj.Runtime.PowerState != "poweredOn" {
		log.Fatal(obj.Runtime.PowerState)
	}

	// Wrap the existing vm object, using the same vm.Self (ManagedObjectReference) value as the Map key.
	simulator.Map.Put(&BusyVM{obj})

	vm := object.NewVirtualMachine(c.Client, obj.Reference())

	// Start a PowerOff task using the SOAP client.
	task, _ := vm.PowerOff(ctx)

	// Wait for task completion, expecting failure.
	err := task.Wait(ctx)
	if err == nil {
		log.Fatal("expected error")
	}

	// Invalid ticket type, expecting failure.
	_, err = vm.AcquireTicket(ctx, "pks")
	if err == nil {
		log.Fatal("expected error")
	}

	mks, _ := vm.AcquireTicket(ctx, "mks")

	fmt.Println(mks.Ticket, obj.Runtime.PowerState)
}
Output:

welcome 2 the machine poweredOn

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultUserGroup = []*types.UserSearchResult{
	{FullName: "root", Group: true, Principal: "root"},
	{FullName: "root", Group: false, Principal: "root"},
	{FullName: "administrator", Group: false, Principal: "admin"},
}
View Source
var EvalLicense = types.LicenseManagerLicenseInfo{
	LicenseKey: "00000-00000-00000-00000-00000",
	EditionKey: "eval",
	Name:       "Evaluation Mode",
	Properties: []types.KeyAnyValue{
		{
			Key: "feature",
			Value: types.KeyValue{
				Key:   "serialuri:2",
				Value: "Remote virtual Serial Port Concentrator",
			},
		},
		{
			Key: "feature",
			Value: types.KeyValue{
				Key:   "dvs",
				Value: "vSphere Distributed Switch",
			},
		},
	},
}

EvalLicense is the default license

View Source
var GuestID = []types.VirtualMachineGuestOsIdentifier{}/* 148 elements not displayed */

GuestID is the list of valid types.VirtualMachineGuestOsIdentifier

View Source
var Map = NewRegistry()

Map is the default Registry instance.

View Source
var Trace = false

Trace when set to true, writes SOAP traffic to stderr

Functions

func CreateDefaultESX

func CreateDefaultESX(f *Folder)

CreateDefaultESX creates a standalone ESX Adds objects of type: Datacenter, Network, ComputeResource, ResourcePool and HostSystem

func DisableRuleset

func DisableRuleset(info *types.HostFirewallInfo, id string) bool

func EnableRuleset

func EnableRuleset(info *types.HostFirewallInfo, id string) bool

func Fault

func Fault(msg string, fault types.BaseMethodFault) *soap.Fault

Fault wraps the given message and fault in a soap.Fault

func FindReference

FindReference returns the 1st match found in refs, or nil if not found.

func NewAuthorizationManager

func NewAuthorizationManager(ref types.ManagedObjectReference) object.Reference

func NewCustomFieldsManager

func NewCustomFieldsManager(ref types.ManagedObjectReference) object.Reference

func NewEventManager added in v0.17.0

func NewEventManager(ref types.ManagedObjectReference) object.Reference

func NewHostLocalAccountManager added in v0.17.0

func NewHostLocalAccountManager(ref types.ManagedObjectReference) object.Reference

func NewPerformanceManager

func NewPerformanceManager(ref types.ManagedObjectReference) object.Reference

func NewPropertyCollector

func NewPropertyCollector(ref types.ManagedObjectReference) object.Reference

func NewVAppConfigSpec

func NewVAppConfigSpec() types.VAppConfigSpec

func NewVirtualDiskManager

func NewVirtualDiskManager(ref types.ManagedObjectReference) object.Reference

func RemoveReference

func RemoveReference(field *[]types.ManagedObjectReference, ref types.ManagedObjectReference)

RemoveReference removes ref from the given field.

func RenameTask

func RenameTask(e mo.Entity, r *types.Rename_Task) soap.HasFault

Types

type AuthorizationManager

type AuthorizationManager struct {
	mo.AuthorizationManager
	// contains filtered or unexported fields
}

func (*AuthorizationManager) AddAuthorizationRole

func (m *AuthorizationManager) AddAuthorizationRole(req *types.AddAuthorizationRole) soap.HasFault

func (*AuthorizationManager) RemoveAuthorizationRole

func (m *AuthorizationManager) RemoveAuthorizationRole(req *types.RemoveAuthorizationRole) soap.HasFault

func (*AuthorizationManager) RemoveEntityPermission

func (m *AuthorizationManager) RemoveEntityPermission(req *types.RemoveEntityPermission) soap.HasFault

func (*AuthorizationManager) RetrieveAllPermissions

func (m *AuthorizationManager) RetrieveAllPermissions(req *types.RetrieveAllPermissions) soap.HasFault

func (*AuthorizationManager) RetrieveEntityPermissions

func (m *AuthorizationManager) RetrieveEntityPermissions(req *types.RetrieveEntityPermissions) soap.HasFault

func (*AuthorizationManager) RetrieveRolePermissions

func (m *AuthorizationManager) RetrieveRolePermissions(req *types.RetrieveRolePermissions) soap.HasFault

func (*AuthorizationManager) SetEntityPermissions

func (m *AuthorizationManager) SetEntityPermissions(req *types.SetEntityPermissions) soap.HasFault

func (*AuthorizationManager) UpdateAuthorizationRole

func (m *AuthorizationManager) UpdateAuthorizationRole(req *types.UpdateAuthorizationRole) soap.HasFault

type ClusterComputeResource

type ClusterComputeResource struct {
	mo.ClusterComputeResource
	// contains filtered or unexported fields
}

func (*ClusterComputeResource) AddHostTask

func (c *ClusterComputeResource) AddHostTask(add *types.AddHost_Task) soap.HasFault

func (*ClusterComputeResource) ReconfigureComputeResourceTask added in v0.17.0

func (c *ClusterComputeResource) ReconfigureComputeResourceTask(req *types.ReconfigureComputeResource_Task) soap.HasFault

type ContainerView

type ContainerView struct {
	mo.ContainerView
	// contains filtered or unexported fields
}

func (*ContainerView) DestroyView

func (v *ContainerView) DestroyView(ctx *Context, c *types.DestroyView) soap.HasFault

type Context added in v0.17.0

type Context struct {
	context.Context
	Session *Session
	Header  soap.Header
	Caller  *types.ManagedObjectReference
	Map     *Registry
	// contains filtered or unexported fields
}

Context provides per-request Session management.

func (*Context) SetSession added in v0.17.0

func (c *Context) SetSession(session Session, login bool)

SetSession should be called after successful authentication.

func (*Context) WithLock added in v0.17.0

func (c *Context) WithLock(obj mo.Reference, f func())

WithLock holds a lock for the given object while then given function is run.

type CustomFieldsManager

type CustomFieldsManager struct {
	mo.CustomFieldsManager
	// contains filtered or unexported fields
}

func (*CustomFieldsManager) AddCustomFieldDef

func (c *CustomFieldsManager) AddCustomFieldDef(req *types.AddCustomFieldDef) soap.HasFault

func (*CustomFieldsManager) RemoveCustomFieldDef

func (c *CustomFieldsManager) RemoveCustomFieldDef(req *types.RemoveCustomFieldDef) soap.HasFault

func (*CustomFieldsManager) RenameCustomFieldDef

func (c *CustomFieldsManager) RenameCustomFieldDef(req *types.RenameCustomFieldDef) soap.HasFault

func (*CustomFieldsManager) SetField

func (c *CustomFieldsManager) SetField(req *types.SetField) soap.HasFault

type Datacenter added in v0.17.0

type Datacenter struct {
	mo.Datacenter
	// contains filtered or unexported fields
}

func NewDatacenter added in v0.17.0

func NewDatacenter(f *Folder) *Datacenter

NewDatacenter creates a Datacenter and its child folders.

func (*Datacenter) DestroyTask added in v0.17.1

func (d *Datacenter) DestroyTask(req *types.Destroy_Task) soap.HasFault

func (*Datacenter) PowerOnMultiVMTask added in v0.17.0

func (dc *Datacenter) PowerOnMultiVMTask(ctx *Context, req *types.PowerOnMultiVM_Task) soap.HasFault

type Datastore

type Datastore struct {
	mo.Datastore
}

func (*Datastore) RefreshDatastore

func (ds *Datastore) RefreshDatastore(*types.RefreshDatastore) soap.HasFault

type DistributedVirtualPortgroup

type DistributedVirtualPortgroup struct {
	mo.DistributedVirtualPortgroup
}

func (*DistributedVirtualPortgroup) DestroyTask

func (*DistributedVirtualPortgroup) ReconfigureDVPortgroupTask

func (s *DistributedVirtualPortgroup) ReconfigureDVPortgroupTask(req *types.ReconfigureDVPortgroup_Task) soap.HasFault

type DistributedVirtualSwitch

type DistributedVirtualSwitch struct {
	mo.DistributedVirtualSwitch
}

func (*DistributedVirtualSwitch) AddDVPortgroupTask

func (*DistributedVirtualSwitch) DestroyTask

func (*DistributedVirtualSwitch) FetchDVPorts

func (*DistributedVirtualSwitch) ReconfigureDvsTask

func (s *DistributedVirtualSwitch) ReconfigureDvsTask(req *types.ReconfigureDvs_Task) soap.HasFault

type Element added in v0.18.0

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

Element can be used to defer decoding of an XML node.

func (*Element) Decode added in v0.18.0

func (e *Element) Decode(val interface{}) error

func (*Element) UnmarshalXML added in v0.18.0

func (e *Element) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type EventHistoryCollector added in v0.17.0

type EventHistoryCollector struct {
	mo.EventHistoryCollector
	// contains filtered or unexported fields
}

func (*EventHistoryCollector) DestroyCollector added in v0.17.0

func (c *EventHistoryCollector) DestroyCollector(ctx *Context, req *types.DestroyCollector) soap.HasFault

func (*EventHistoryCollector) Get added in v0.17.0

func (*EventHistoryCollector) GetLatestPage added in v0.17.1

func (c *EventHistoryCollector) GetLatestPage() []types.BaseEvent

func (*EventHistoryCollector) SetCollectorPageSize added in v0.17.0

func (c *EventHistoryCollector) SetCollectorPageSize(ctx *Context, req *types.SetCollectorPageSize) soap.HasFault

type EventManager added in v0.17.0

type EventManager struct {
	mo.EventManager
	// contains filtered or unexported fields
}

func (*EventManager) CreateCollectorForEvents added in v0.17.0

func (m *EventManager) CreateCollectorForEvents(ctx *Context, req *types.CreateCollectorForEvents) soap.HasFault

func (*EventManager) PostEvent added in v0.17.0

func (m *EventManager) PostEvent(ctx *Context, req *types.PostEvent) soap.HasFault

func (*EventManager) QueryEvents added in v0.17.1

func (m *EventManager) QueryEvents(ctx *Context, req *types.QueryEvents) soap.HasFault

type FileManager

type FileManager struct {
	mo.FileManager
}

func (*FileManager) CopyDatastoreFileTask

func (f *FileManager) CopyDatastoreFileTask(req *types.CopyDatastoreFile_Task) soap.HasFault

func (*FileManager) DeleteDatastoreFileTask

func (f *FileManager) DeleteDatastoreFileTask(req *types.DeleteDatastoreFile_Task) soap.HasFault

func (*FileManager) MakeDirectory

func (f *FileManager) MakeDirectory(req *types.MakeDirectory) soap.HasFault

func (*FileManager) MoveDatastoreFileTask

func (f *FileManager) MoveDatastoreFileTask(req *types.MoveDatastoreFile_Task) soap.HasFault

type Folder

type Folder struct {
	mo.Folder
}

func (*Folder) AddStandaloneHostTask

func (f *Folder) AddStandaloneHostTask(a *types.AddStandaloneHost_Task) soap.HasFault

func (*Folder) CreateClusterEx

func (f *Folder) CreateClusterEx(c *types.CreateClusterEx) soap.HasFault

func (*Folder) CreateDVSTask

func (f *Folder) CreateDVSTask(req *types.CreateDVS_Task) soap.HasFault

func (*Folder) CreateDatacenter

func (f *Folder) CreateDatacenter(ctx *Context, c *types.CreateDatacenter) soap.HasFault

func (*Folder) CreateFolder

func (f *Folder) CreateFolder(c *types.CreateFolder) soap.HasFault

func (*Folder) CreateStoragePod

func (f *Folder) CreateStoragePod(c *types.CreateStoragePod) soap.HasFault

func (*Folder) CreateVMTask

func (f *Folder) CreateVMTask(ctx *Context, c *types.CreateVM_Task) soap.HasFault

func (*Folder) DestroyTask added in v0.17.1

func (f *Folder) DestroyTask(req *types.Destroy_Task) soap.HasFault

func (*Folder) MoveIntoFolderTask

func (f *Folder) MoveIntoFolderTask(c *types.MoveIntoFolder_Task) soap.HasFault

func (*Folder) RegisterVMTask

func (f *Folder) RegisterVMTask(ctx *Context, c *types.RegisterVM_Task) soap.HasFault

func (*Folder) RenameTask

func (f *Folder) RenameTask(r *types.Rename_Task) soap.HasFault

type HostDatastoreBrowser

type HostDatastoreBrowser struct {
	mo.HostDatastoreBrowser
}

func (*HostDatastoreBrowser) SearchDatastoreSubFoldersTask

func (b *HostDatastoreBrowser) SearchDatastoreSubFoldersTask(s *types.SearchDatastoreSubFolders_Task) soap.HasFault

func (*HostDatastoreBrowser) SearchDatastoreTask

func (b *HostDatastoreBrowser) SearchDatastoreTask(s *types.SearchDatastore_Task) soap.HasFault

type HostDatastoreSystem

type HostDatastoreSystem struct {
	mo.HostDatastoreSystem

	Host *mo.HostSystem
}

func (*HostDatastoreSystem) CreateLocalDatastore

func (dss *HostDatastoreSystem) CreateLocalDatastore(c *types.CreateLocalDatastore) soap.HasFault

func (*HostDatastoreSystem) CreateNasDatastore

func (dss *HostDatastoreSystem) CreateNasDatastore(c *types.CreateNasDatastore) soap.HasFault

type HostFirewallSystem

type HostFirewallSystem struct {
	mo.HostFirewallSystem
}

func NewHostFirewallSystem

func NewHostFirewallSystem(_ *mo.HostSystem) *HostFirewallSystem

func (*HostFirewallSystem) DisableRuleset

func (s *HostFirewallSystem) DisableRuleset(req *types.DisableRuleset) soap.HasFault

func (*HostFirewallSystem) EnableRuleset

func (s *HostFirewallSystem) EnableRuleset(req *types.EnableRuleset) soap.HasFault

type HostLocalAccountManager added in v0.17.0

type HostLocalAccountManager struct {
	mo.HostLocalAccountManager
}

func (*HostLocalAccountManager) CreateUser added in v0.17.0

func (*HostLocalAccountManager) RemoveUser added in v0.17.0

func (*HostLocalAccountManager) UpdateUser added in v0.17.0

type HostNetworkSystem

type HostNetworkSystem struct {
	mo.HostNetworkSystem

	Host *mo.HostSystem
}

func NewHostNetworkSystem

func NewHostNetworkSystem(host *mo.HostSystem) *HostNetworkSystem

func (*HostNetworkSystem) AddPortGroup

func (s *HostNetworkSystem) AddPortGroup(c *types.AddPortGroup) soap.HasFault

func (*HostNetworkSystem) AddVirtualSwitch

func (s *HostNetworkSystem) AddVirtualSwitch(c *types.AddVirtualSwitch) soap.HasFault

func (*HostNetworkSystem) RemovePortGroup

func (s *HostNetworkSystem) RemovePortGroup(c *types.RemovePortGroup) soap.HasFault

func (*HostNetworkSystem) RemoveVirtualSwitch

func (s *HostNetworkSystem) RemoveVirtualSwitch(c *types.RemoveVirtualSwitch) soap.HasFault

func (*HostNetworkSystem) UpdateNetworkConfig

func (s *HostNetworkSystem) UpdateNetworkConfig(req *types.UpdateNetworkConfig) soap.HasFault

type HostSystem

type HostSystem struct {
	mo.HostSystem
}

func CreateStandaloneHost

func CreateStandaloneHost(f *Folder, spec types.HostConnectSpec) (*HostSystem, types.BaseMethodFault)

CreateStandaloneHost uses esx.HostSystem as a template, applying the given spec and creating the ComputeResource parent and ResourcePool sibling.

func NewHostSystem

func NewHostSystem(host mo.HostSystem) *HostSystem

func (*HostSystem) DestroyTask added in v0.17.0

func (h *HostSystem) DestroyTask(req *types.Destroy_Task) soap.HasFault

func (*HostSystem) EnterMaintenanceModeTask

func (h *HostSystem) EnterMaintenanceModeTask(spec *types.EnterMaintenanceMode_Task) soap.HasFault

func (*HostSystem) ExitMaintenanceModeTask

func (h *HostSystem) ExitMaintenanceModeTask(spec *types.ExitMaintenanceMode_Task) soap.HasFault

type IpPool

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

func MustNewIpPool

func MustNewIpPool(config *types.IpPool) *IpPool

func NewIpPool

func NewIpPool(config *types.IpPool) (*IpPool, error)

func (*IpPool) AllocateIPv4

func (p *IpPool) AllocateIPv4(allocation string) (string, error)

func (*IpPool) AllocateIpv6

func (p *IpPool) AllocateIpv6(allocation string) (string, error)

func (*IpPool) ReleaseIpv4

func (p *IpPool) ReleaseIpv4(allocation string) error

func (*IpPool) ReleaseIpv6

func (p *IpPool) ReleaseIpv6(allocation string) error

type IpPoolManager

type IpPoolManager struct {
	mo.IpPoolManager
	// contains filtered or unexported fields
}

IpPoolManager implements a simple IP Pool manager in which all pools are shared across different datacenters.

func NewIpPoolManager

func NewIpPoolManager(ref types.ManagedObjectReference) *IpPoolManager

func (*IpPoolManager) AllocateIpv4Address

func (m *IpPoolManager) AllocateIpv4Address(req *types.AllocateIpv4Address) soap.HasFault

func (*IpPoolManager) AllocateIpv6Address

func (m *IpPoolManager) AllocateIpv6Address(req *types.AllocateIpv6Address) soap.HasFault

func (*IpPoolManager) CreateIpPool

func (m *IpPoolManager) CreateIpPool(req *types.CreateIpPool) soap.HasFault

func (*IpPoolManager) DestroyIpPool

func (m *IpPoolManager) DestroyIpPool(req *types.DestroyIpPool) soap.HasFault

func (*IpPoolManager) QueryIPAllocations

func (m *IpPoolManager) QueryIPAllocations(req *types.QueryIPAllocations) soap.HasFault

func (*IpPoolManager) QueryIpPools

func (m *IpPoolManager) QueryIpPools(req *types.QueryIpPools) soap.HasFault

func (*IpPoolManager) ReleaseIpAllocation

func (m *IpPoolManager) ReleaseIpAllocation(req *types.ReleaseIpAllocation) soap.HasFault

func (*IpPoolManager) UpdateIpPool

func (m *IpPoolManager) UpdateIpPool(req *types.UpdateIpPool) soap.HasFault

type LicenseAssignmentManager

type LicenseAssignmentManager struct {
	mo.LicenseAssignmentManager
}

func (*LicenseAssignmentManager) QueryAssignedLicenses

func (m *LicenseAssignmentManager) QueryAssignedLicenses(req *types.QueryAssignedLicenses) soap.HasFault

type LicenseManager

type LicenseManager struct {
	mo.LicenseManager
}

func (*LicenseManager) AddLicense

func (m *LicenseManager) AddLicense(req *types.AddLicense) soap.HasFault

func (*LicenseManager) RemoveLicense

func (m *LicenseManager) RemoveLicense(req *types.RemoveLicense) soap.HasFault

type ListView added in v0.19.0

type ListView struct {
	mo.ListView
}

func (*ListView) DestroyView added in v0.19.0

func (v *ListView) DestroyView(ctx *Context, c *types.DestroyView) soap.HasFault

func (*ListView) ModifyListView added in v0.19.0

func (v *ListView) ModifyListView(req *types.ModifyListView) soap.HasFault

func (*ListView) ResetListView added in v0.19.0

func (v *ListView) ResetListView(req *types.ResetListView) soap.HasFault

type Method

type Method struct {
	Name   string
	This   types.ManagedObjectReference
	Header soap.Header
	Body   types.AnyType
}

Method encapsulates a decoded SOAP client request

func UnmarshalBody

func UnmarshalBody(typeFunc func(string) (reflect.Type, bool), data []byte) (*Method, error)

UnmarshalBody extracts the Body from a soap.Envelope and unmarshals to the corresponding govmomi type

type Model

type Model struct {
	Service *Service `json:"-"`

	ServiceContent types.ServiceContent `json:"-"`
	RootFolder     mo.Folder            `json:"-"`

	// Autostart will power on Model created VMs when true
	Autostart bool `json:"-"`

	// Datacenter specifies the number of Datacenter entities to create
	Datacenter int

	// Portgroup specifies the number of DistributedVirtualPortgroup entities to create per Datacenter
	Portgroup int

	// Host specifies the number of standalone HostSystems entities to create per Datacenter
	Host int `json:",omitempty"`

	// Cluster specifies the number of ClusterComputeResource entities to create per Datacenter
	Cluster int

	// ClusterHost specifies the number of HostSystems entities to create within a Cluster
	ClusterHost int `json:",omitempty"`

	// Pool specifies the number of ResourcePool entities to create per Cluster
	Pool int

	// Datastore specifies the number of Datastore entities to create
	// Each Datastore will have temporary local file storage and will be mounted
	// on every HostSystem created by the ModelConfig
	Datastore int

	// Machine specifies the number of VirtualMachine entities to create per ResourcePool
	Machine int

	// Folder specifies the number of Datacenter to place within a Folder.
	// This includes a folder for the Datacenter itself and its host, vm, network and datastore folders.
	// All resources for the Datacenter are placed within these folders, rather than the top-level folders.
	Folder int

	// App specifies the number of VirtualApp to create per Cluster
	App int

	// Pod specifies the number of StoragePod to create per Cluster
	Pod int
	// contains filtered or unexported fields
}

Model is used to populate a Model with an initial set of managed entities. This is a simple helper for tests running against a simulator, to populate an inventory with commonly used models.

Example

Example for starting a simulator with empty inventory, similar to a fresh install of vCenter.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/vmware/govmomi"
	"github.com/vmware/govmomi/simulator"
)

func main() {
	ctx := context.Background()

	model := simulator.VPX()
	model.Datacenter = 0 // No DC == no inventory

	defer model.Remove()
	err := model.Create()
	if err != nil {
		log.Fatal(err)
	}

	s := model.Service.NewServer()
	defer s.Close()

	c, _ := govmomi.NewClient(ctx, s.URL, true)

	fmt.Printf("%s with %d hosts", c.Client.ServiceContent.About.ApiType, model.Count().Host)
}
Output:

VirtualCenter with 0 hosts

func ESX

func ESX() *Model

ESX is the default Model for a standalone ESX instance

Example

Example boilerplate for starting a simulator initialized with an ESX model.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/vmware/govmomi"
	"github.com/vmware/govmomi/simulator"
)

func main() {
	ctx := context.Background()

	// ESXi model + initial set of objects (VMs, network, datastore)
	model := simulator.ESX()

	defer model.Remove()
	err := model.Create()
	if err != nil {
		log.Fatal(err)
	}

	s := model.Service.NewServer()
	defer s.Close()

	c, _ := govmomi.NewClient(ctx, s.URL, true)

	fmt.Printf("%s with %d host", c.Client.ServiceContent.About.ApiType, model.Count().Host)
}
Output:

HostAgent with 1 host

func VPX

func VPX() *Model

VPX is the default Model for a vCenter instance

Example

Example boilerplate for starting a simulator initialized with a vCenter model.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/vmware/govmomi"
	"github.com/vmware/govmomi/simulator"
)

func main() {
	ctx := context.Background()

	// vCenter model + initial set of objects (cluster, hosts, VMs, network, datastore, etc)
	model := simulator.VPX()

	defer model.Remove()
	err := model.Create()
	if err != nil {
		log.Fatal(err)
	}

	s := model.Service.NewServer()
	defer s.Close()

	c, _ := govmomi.NewClient(ctx, s.URL, true)

	fmt.Printf("%s with %d hosts", c.Client.ServiceContent.About.ApiType, model.Count().Host)
}
Output:

VirtualCenter with 4 hosts

func (*Model) Count

func (m *Model) Count() Model

Count returns a Model with total number of each existing type

func (*Model) Create

func (m *Model) Create() error

Create populates the Model with the given ModelConfig

func (*Model) Remove

func (m *Model) Remove()

Remove cleans up items created by the Model, such as local datastore directories

type OptionManager

type OptionManager struct {
	mo.OptionManager
}

func (*OptionManager) QueryOptions

func (m *OptionManager) QueryOptions(req *types.QueryOptions) soap.HasFault

func (*OptionManager) UpdateOptions added in v0.17.0

func (m *OptionManager) UpdateOptions(req *types.UpdateOptions) soap.HasFault

type PerformanceManager

type PerformanceManager struct {
	mo.PerformanceManager
	// contains filtered or unexported fields
}

func (*PerformanceManager) QueryAvailablePerfMetric added in v0.19.0

func (p *PerformanceManager) QueryAvailablePerfMetric(ctx *Context, req *types.QueryAvailablePerfMetric) soap.HasFault

func (*PerformanceManager) QueryPerf added in v0.19.0

func (p *PerformanceManager) QueryPerf(ctx *Context, req *types.QueryPerf) soap.HasFault

func (*PerformanceManager) QueryPerfCounter added in v0.19.0

func (p *PerformanceManager) QueryPerfCounter(ctx *Context, req *types.QueryPerfCounter) soap.HasFault

func (*PerformanceManager) QueryPerfProviderSummary added in v0.19.0

func (p *PerformanceManager) QueryPerfProviderSummary(ctx *Context, req *types.QueryPerfProviderSummary) soap.HasFault

type PropertyCollector

type PropertyCollector struct {
	mo.PropertyCollector
	// contains filtered or unexported fields
}

func (*PropertyCollector) CancelWaitForUpdates

func (pc *PropertyCollector) CancelWaitForUpdates(r *types.CancelWaitForUpdates) soap.HasFault

func (*PropertyCollector) CreateFilter

func (pc *PropertyCollector) CreateFilter(ctx *Context, c *types.CreateFilter) soap.HasFault

func (*PropertyCollector) CreatePropertyCollector

func (pc *PropertyCollector) CreatePropertyCollector(ctx *Context, c *types.CreatePropertyCollector) soap.HasFault

func (*PropertyCollector) DestroyPropertyCollector

func (pc *PropertyCollector) DestroyPropertyCollector(ctx *Context, c *types.DestroyPropertyCollector) soap.HasFault

func (*PropertyCollector) Lock added in v0.19.0

func (*PropertyCollector) Lock()

func (*PropertyCollector) PutObject added in v0.19.0

func (pc *PropertyCollector) PutObject(o mo.Reference)

func (*PropertyCollector) RemoveObject added in v0.19.0

func (pc *PropertyCollector) RemoveObject(ref types.ManagedObjectReference)

func (*PropertyCollector) RetrieveProperties

func (pc *PropertyCollector) RetrieveProperties(ctx *Context, r *types.RetrieveProperties) soap.HasFault

RetrieveProperties is deprecated, but govmomi is still using it at the moment.

func (*PropertyCollector) RetrievePropertiesEx

func (pc *PropertyCollector) RetrievePropertiesEx(ctx *Context, r *types.RetrievePropertiesEx) soap.HasFault

func (*PropertyCollector) Unlock added in v0.19.0

func (*PropertyCollector) Unlock()

func (*PropertyCollector) UpdateObject added in v0.19.0

func (pc *PropertyCollector) UpdateObject(o mo.Reference, changes []types.PropertyChange)

func (*PropertyCollector) WaitForUpdates

func (pc *PropertyCollector) WaitForUpdates(ctx *Context, r *types.WaitForUpdates) soap.HasFault

WaitForUpdates is deprecated, but pyvmomi is still using it at the moment.

func (*PropertyCollector) WaitForUpdatesEx

func (pc *PropertyCollector) WaitForUpdatesEx(ctx *Context, r *types.WaitForUpdatesEx) soap.HasFault

type PropertyFilter

type PropertyFilter struct {
	mo.PropertyFilter
	// contains filtered or unexported fields
}

func (*PropertyFilter) DestroyPropertyFilter

func (f *PropertyFilter) DestroyPropertyFilter(ctx *Context, c *types.DestroyPropertyFilter) soap.HasFault

type RegisterObject

type RegisterObject interface {
	mo.Reference
	PutObject(mo.Reference)
	UpdateObject(mo.Reference, []types.PropertyChange)
	RemoveObject(types.ManagedObjectReference)
}

RegisterObject interface supports callbacks when objects are created, updated and deleted from the Registry

type Registry

type Registry struct {
	Namespace string
	Path      string
	// contains filtered or unexported fields
}

Registry manages a map of mo.Reference objects

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new instances of Registry

func (*Registry) AddHandler

func (r *Registry) AddHandler(h RegisterObject)

AddHandler adds a RegisterObject handler to the Registry.

func (*Registry) AddReference added in v0.17.0

func (r *Registry) AddReference(obj mo.Reference, field *[]types.ManagedObjectReference, ref types.ManagedObjectReference)

AddReference appends ref to field if not already in the given field.

func (*Registry) Any

func (r *Registry) Any(kind string) mo.Entity

Any returns the first instance of entity type specified by kind.

func (*Registry) AppendReference added in v0.17.0

func (r *Registry) AppendReference(obj mo.Reference, field *[]types.ManagedObjectReference, ref ...types.ManagedObjectReference)

AppendReference appends the given refs to field.

func (*Registry) EventManager added in v0.17.0

func (r *Registry) EventManager() *EventManager

EventManager returns the EventManager singleton

func (*Registry) FileManager

func (r *Registry) FileManager() *FileManager

FileManager returns the FileManager singleton

func (*Registry) FindByName

func (r *Registry) FindByName(name string, refs []types.ManagedObjectReference) mo.Entity

FindByName returns the first mo.Entity of the given refs whose Name field is equal to the given name. If there is no match, nil is returned. This method is useful for cases where objects are required to have a unique name, such as Datastore with a HostStorageSystem or HostSystem within a ClusterComputeResource.

func (*Registry) Get

Get returns the object for the given reference.

func (*Registry) IsESX

func (r *Registry) IsESX() bool

IsESX returns true if this Registry maps an ESX model

func (*Registry) IsVPX

func (r *Registry) IsVPX() bool

IsVPX returns true if this Registry maps a VPX model

func (*Registry) MarshalJSON added in v0.17.0

func (r *Registry) MarshalJSON() ([]byte, error)

func (*Registry) NewEntity

func (r *Registry) NewEntity(item mo.Entity) mo.Entity

NewEntity sets Entity().Self with a new, unique Value. Useful for creating object instances from templates.

func (*Registry) OptionManager added in v0.18.0

func (r *Registry) OptionManager() *OptionManager

OptionManager returns the OptionManager singleton

func (*Registry) Put

func (r *Registry) Put(item mo.Reference) mo.Reference

Put adds a new object to Registry, generating a ManagedObjectReference if not already set.

func (*Registry) PutEntity

func (r *Registry) PutEntity(parent mo.Entity, item mo.Entity) mo.Entity

PutEntity sets item.Parent to that of parent.Self before adding item to the Registry.

func (*Registry) Remove

func (r *Registry) Remove(item types.ManagedObjectReference)

Remove removes an object from the Registry.

func (*Registry) RemoveReference added in v0.17.0

func (r *Registry) RemoveReference(obj mo.Reference, field *[]types.ManagedObjectReference, ref types.ManagedObjectReference)

RemoveReference removes ref from the given field.

func (*Registry) SearchIndex

func (r *Registry) SearchIndex() *SearchIndex

SearchIndex returns the SearchIndex singleton

func (*Registry) SessionManager added in v0.17.0

func (r *Registry) SessionManager() *SessionManager

SessionManager returns the SessionManager singleton

func (*Registry) Update added in v0.19.0

func (r *Registry) Update(obj mo.Reference, changes []types.PropertyChange)

Update dispatches object property changes to RegisterObject handlers, such as any PropertyCollector instances with in-progress WaitForUpdates calls. The changes are also applied to the given object via mo.ApplyPropertyChange, so there is no need to set object fields directly.

func (*Registry) UserDirectory added in v0.17.0

func (r *Registry) UserDirectory() *UserDirectory

UserDirectory returns the UserDirectory singleton

func (*Registry) ViewManager

func (r *Registry) ViewManager() *ViewManager

ViewManager returns the ViewManager singleton

func (*Registry) VirtualDiskManager

func (r *Registry) VirtualDiskManager() *VirtualDiskManager

VirtualDiskManager returns the VirtualDiskManager singleton

func (*Registry) WithLock added in v0.17.0

func (r *Registry) WithLock(obj mo.Reference, f func())

WithLock holds a lock for the given object while then given function is run.

type ResourcePool

type ResourcePool struct {
	mo.ResourcePool
}

func NewResourcePool

func NewResourcePool() *ResourcePool

func (*ResourcePool) CreateResourcePool

func (p *ResourcePool) CreateResourcePool(c *types.CreateResourcePool) soap.HasFault

func (*ResourcePool) CreateVApp

func (p *ResourcePool) CreateVApp(req *types.CreateVApp) soap.HasFault

func (*ResourcePool) DestroyTask

func (p *ResourcePool) DestroyTask(req *types.Destroy_Task) soap.HasFault

func (*ResourcePool) UpdateConfig

func (p *ResourcePool) UpdateConfig(c *types.UpdateConfig) soap.HasFault

type SearchIndex

type SearchIndex struct {
	mo.SearchIndex
}

func (*SearchIndex) FindByDatastorePath

func (s *SearchIndex) FindByDatastorePath(r *types.FindByDatastorePath) soap.HasFault

func (*SearchIndex) FindByInventoryPath

func (s *SearchIndex) FindByInventoryPath(req *types.FindByInventoryPath) soap.HasFault

func (*SearchIndex) FindByUuid

func (s *SearchIndex) FindByUuid(req *types.FindByUuid) soap.HasFault

func (*SearchIndex) FindChild

func (s *SearchIndex) FindChild(req *types.FindChild) soap.HasFault

type Server

type Server struct {
	*httptest.Server
	URL    *url.URL
	Tunnel int
	// contains filtered or unexported fields
}

Server provides a simulator Service over HTTP

func (*Server) Certificate

func (s *Server) Certificate() *x509.Certificate

Certificate returns the TLS certificate for the Server if started with TLS enabled. This method will panic if TLS is not enabled for the server.

func (*Server) CertificateFile

func (s *Server) CertificateFile() (string, error)

CertificateFile returns a file name, where the file contains the PEM encoded Server.Certificate. The temporary file is removed when Server.Close() is called.

func (*Server) CertificateInfo

func (s *Server) CertificateInfo() *object.HostCertificateInfo

CertificateInfo returns Server.Certificate() as object.HostCertificateInfo

func (*Server) Close

func (s *Server) Close()

Close shuts down the server and blocks until all outstanding requests on this server have completed.

func (*Server) StartTunnel added in v0.18.0

func (s *Server) StartTunnel() error

StartTunnel runs an HTTP proxy for tunneling SDK requests that require TLS client certificate authentication.

type Service

type Service struct {
	TLS      *tls.Config
	ServeMux *http.ServeMux
	// contains filtered or unexported fields
}

Service decodes incoming requests and dispatches to a Handler

func New

func New(instance *ServiceInstance) *Service

New returns an initialized simulator Service instance

func (*Service) About

func (s *Service) About(w http.ResponseWriter, r *http.Request)

About generates some info about the simulator.

func (*Service) NewServer

func (s *Service) NewServer() *Server

NewServer returns an http Server instance for the given service

func (*Service) RegisterSDK added in v0.18.0

func (s *Service) RegisterSDK(r *Registry)

RegisterSDK adds an HTTP handler for the Registry's Path and Namespace.

func (*Service) RoundTrip

func (s *Service) RoundTrip(ctx context.Context, request, response soap.HasFault) error

RoundTrip implements the soap.RoundTripper interface in process. Rather than encode/decode SOAP over HTTP, this implementation uses reflection.

func (*Service) ServeDatastore

func (s *Service) ServeDatastore(w http.ResponseWriter, r *http.Request)

ServeDatastore handler for Datastore access via /folder path.

func (*Service) ServeSDK

func (s *Service) ServeSDK(w http.ResponseWriter, r *http.Request)

ServeSDK implements the http.Handler interface

func (*Service) ServiceVersions

func (*Service) ServiceVersions(w http.ResponseWriter, r *http.Request)

ServiceVersions handler for the /sdk/vimServiceVersions.xml path.

type ServiceInstance

type ServiceInstance struct {
	mo.ServiceInstance
}

func NewServiceInstance

func NewServiceInstance(content types.ServiceContent, folder mo.Folder) *ServiceInstance

func (*ServiceInstance) CurrentTime

func (*ServiceInstance) RetrieveServiceContent

func (s *ServiceInstance) RetrieveServiceContent(*types.RetrieveServiceContent) soap.HasFault

type Session added in v0.17.0

type Session struct {
	types.UserSession
	*Registry
}

Session combines a UserSession and a Registry for per-session managed objects.

func (*Session) Get added in v0.17.0

Get wraps Registry.Get, session-izing singleton objects such as SessionManager and the root PropertyCollector.

func (*Session) Put added in v0.17.0

func (s *Session) Put(item mo.Reference) mo.Reference

Put wraps Registry.Put, setting the moref value to include the session key.

type SessionManager

type SessionManager struct {
	mo.SessionManager

	ServiceHostName string
	// contains filtered or unexported fields
}

func (*SessionManager) AcquireCloneTicket added in v0.17.0

func (s *SessionManager) AcquireCloneTicket(ctx *Context, _ *types.AcquireCloneTicket) soap.HasFault

func (*SessionManager) AcquireGenericServiceTicket

func (s *SessionManager) AcquireGenericServiceTicket(ticket *types.AcquireGenericServiceTicket) soap.HasFault

func (*SessionManager) CloneSession added in v0.17.0

func (s *SessionManager) CloneSession(ctx *Context, ticket *types.CloneSession) soap.HasFault

func (*SessionManager) Login

func (s *SessionManager) Login(ctx *Context, req *types.Login) soap.HasFault

func (*SessionManager) LoginByToken added in v0.18.0

func (s *SessionManager) LoginByToken(ctx *Context, req *types.LoginByToken) soap.HasFault

func (*SessionManager) LoginExtensionByCertificate added in v0.18.0

func (s *SessionManager) LoginExtensionByCertificate(ctx *Context, req *types.LoginExtensionByCertificate) soap.HasFault

func (*SessionManager) Logout

func (s *SessionManager) Logout(ctx *Context, _ *types.Logout) soap.HasFault

func (*SessionManager) TerminateSession added in v0.17.0

func (s *SessionManager) TerminateSession(ctx *Context, req *types.TerminateSession) soap.HasFault

type StoragePod

type StoragePod struct {
	mo.StoragePod
}

StoragePod aka "Datastore Cluster"

func (*StoragePod) MoveIntoFolderTask

func (p *StoragePod) MoveIntoFolderTask(c *types.MoveIntoFolder_Task) soap.HasFault

type Task

type Task struct {
	mo.Task

	Execute func(*Task) (types.AnyType, types.BaseMethodFault)
}

func CreateTask

func CreateTask(e mo.Reference, name string, run func(*Task) (types.AnyType, types.BaseMethodFault)) *Task

func NewTask

func NewTask(runner TaskRunner) *Task

func (*Task) Run

type TaskManager

type TaskManager struct {
	mo.TaskManager
	sync.Mutex
}

func (*TaskManager) PutObject

func (m *TaskManager) PutObject(obj mo.Reference)

func (*TaskManager) RemoveObject

func (*TaskManager) RemoveObject(types.ManagedObjectReference)

func (*TaskManager) UpdateObject added in v0.19.0

func (*TaskManager) UpdateObject(mo.Reference, []types.PropertyChange)

type TaskRunner

type TaskRunner interface {
	mo.Reference

	Run(*Task) (types.AnyType, types.BaseMethodFault)
}

type UserDirectory

type UserDirectory struct {
	mo.UserDirectory
	// contains filtered or unexported fields
}

func (*UserDirectory) RetrieveUserGroups

func (u *UserDirectory) RetrieveUserGroups(req *types.RetrieveUserGroups) soap.HasFault

type ViewManager

type ViewManager struct {
	mo.ViewManager
	// contains filtered or unexported fields
}

func (*ViewManager) CreateContainerView

func (m *ViewManager) CreateContainerView(ctx *Context, req *types.CreateContainerView) soap.HasFault

func (*ViewManager) CreateListView added in v0.19.0

func (m *ViewManager) CreateListView(ctx *Context, req *types.CreateListView) soap.HasFault

type VirtualApp

type VirtualApp struct {
	mo.VirtualApp
}

func (*VirtualApp) CreateChildVMTask

func (a *VirtualApp) CreateChildVMTask(ctx *Context, req *types.CreateChildVM_Task) soap.HasFault

func (*VirtualApp) DestroyTask

func (a *VirtualApp) DestroyTask(req *types.Destroy_Task) soap.HasFault

type VirtualDiskManager

type VirtualDiskManager struct {
	mo.VirtualDiskManager
}

func (*VirtualDiskManager) CopyVirtualDiskTask

func (m *VirtualDiskManager) CopyVirtualDiskTask(req *types.CopyVirtualDisk_Task) soap.HasFault

func (*VirtualDiskManager) CreateVirtualDiskTask

func (m *VirtualDiskManager) CreateVirtualDiskTask(req *types.CreateVirtualDisk_Task) soap.HasFault

func (*VirtualDiskManager) DeleteVirtualDiskTask

func (m *VirtualDiskManager) DeleteVirtualDiskTask(req *types.DeleteVirtualDisk_Task) soap.HasFault

func (*VirtualDiskManager) MoveVirtualDiskTask

func (m *VirtualDiskManager) MoveVirtualDiskTask(req *types.MoveVirtualDisk_Task) soap.HasFault

func (*VirtualDiskManager) QueryVirtualDiskUuid added in v0.17.0

func (m *VirtualDiskManager) QueryVirtualDiskUuid(req *types.QueryVirtualDiskUuid) soap.HasFault

func (*VirtualDiskManager) SetVirtualDiskUuid added in v0.18.0

func (m *VirtualDiskManager) SetVirtualDiskUuid(req *types.SetVirtualDiskUuid) soap.HasFault

type VirtualMachine

type VirtualMachine struct {
	mo.VirtualMachine
	// contains filtered or unexported fields
}

func (*VirtualMachine) CloneVMTask

func (vm *VirtualMachine) CloneVMTask(ctx *Context, req *types.CloneVM_Task) soap.HasFault

func (*VirtualMachine) CreateSnapshotTask

func (vm *VirtualMachine) CreateSnapshotTask(req *types.CreateSnapshot_Task) soap.HasFault

func (*VirtualMachine) DestroyTask

func (vm *VirtualMachine) DestroyTask(ctx *Context, req *types.Destroy_Task) soap.HasFault

func (*VirtualMachine) MarkAsTemplate added in v0.17.0

func (vm *VirtualMachine) MarkAsTemplate(req *types.MarkAsTemplate) soap.HasFault

func (*VirtualMachine) PowerOffVMTask

func (vm *VirtualMachine) PowerOffVMTask(ctx *Context, c *types.PowerOffVM_Task) soap.HasFault

func (*VirtualMachine) PowerOnVMTask

func (vm *VirtualMachine) PowerOnVMTask(ctx *Context, c *types.PowerOnVM_Task) soap.HasFault

func (*VirtualMachine) ReconfigVMTask

func (vm *VirtualMachine) ReconfigVMTask(ctx *Context, req *types.ReconfigVM_Task) soap.HasFault

func (*VirtualMachine) RelocateVMTask

func (vm *VirtualMachine) RelocateVMTask(req *types.RelocateVM_Task) soap.HasFault

func (*VirtualMachine) RemoveAllSnapshotsTask

func (vm *VirtualMachine) RemoveAllSnapshotsTask(req *types.RemoveAllSnapshots_Task) soap.HasFault

func (*VirtualMachine) ResetVMTask added in v0.19.0

func (vm *VirtualMachine) ResetVMTask(ctx *Context, req *types.ResetVM_Task) soap.HasFault

func (*VirtualMachine) RevertToCurrentSnapshotTask

func (vm *VirtualMachine) RevertToCurrentSnapshotTask(req *types.RevertToCurrentSnapshot_Task) soap.HasFault

func (*VirtualMachine) ShutdownGuest

func (vm *VirtualMachine) ShutdownGuest(ctx *Context, c *types.ShutdownGuest) soap.HasFault

func (*VirtualMachine) SuspendVMTask added in v0.19.0

func (vm *VirtualMachine) SuspendVMTask(ctx *Context, req *types.SuspendVM_Task) soap.HasFault

func (*VirtualMachine) UnregisterVM

func (vm *VirtualMachine) UnregisterVM(ctx *Context, c *types.UnregisterVM) soap.HasFault

type VirtualMachineSnapshot

type VirtualMachineSnapshot struct {
	mo.VirtualMachineSnapshot
}

func (*VirtualMachineSnapshot) RemoveSnapshotTask

func (v *VirtualMachineSnapshot) RemoveSnapshotTask(req *types.RemoveSnapshot_Task) soap.HasFault

func (*VirtualMachineSnapshot) RevertToSnapshotTask

func (v *VirtualMachineSnapshot) RevertToSnapshotTask(req *types.RevertToSnapshot_Task) soap.HasFault

Directories

Path Synopsis
Package esx contains SOAP responses from an ESX server, captured using `govc ...
Package esx contains SOAP responses from an ESX server, captured using `govc ...
Package vpx contains SOAP responses from a vCenter server, captured using `govc ...
Package vpx contains SOAP responses from a vCenter server, captured using `govc ...

Jump to

Keyboard shortcuts

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