Help us shape the future of Go! Take the 2026 Go Developer Survey

vmx

package module
v0.0.0-...-983fd93 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2017 License: MPL-2.0 Imports: 9 Imported by: 7

README

GoVMX

Gitter GoDoc Build Status

Data encoding and decoding library for VMware VMX files.

Encoding

type VM struct {
	Encoding     string `vmx:".encoding"`
	Annotation   string `vmx:"annotation"`
	Hwversion    uint8  `vmx:"virtualHW.version"`
	HwProdCompat string `vmx:"virtualHW.productCompatibility"`
	Memsize      uint   `vmx:"memsize"`
	Numvcpus     uint   `vmx:"numvcpus"`
	MemHotAdd    bool   `vmx:"mem.hotadd"`
	DisplayName  string `vmx:"displayName"`
	GuestOS      string `vmx:"guestOS"`
	Autoanswer   bool   `vmx:"msg.autoAnswer"`
}

vm := new(VM)
vm.Encoding = "utf-8"
vm.Annotation = "Test VM"
vm.Hwversion = 10
vm.HwProdCompat = "hosted"
vm.Memsize = 1024
vm.Numvcpus = 2
vm.MemHotAdd = false
vm.DisplayName = "test"
vm.GuestOS = "other3xlinux-64"
vm.Autoanswer = true

data, err := Marshal(vm)

data should be:

.encoding = "utf-8"
annotation = "Test VM"
virtualHW.version = "10"
virtualHW.productCompatibility = "hosted"
memsize = "1024"
numvcpus = "2"
mem.hotadd = "false"
displayName = "test"
guestOS = "other3xlinux-64"
msg.autoAnswer = "true"

Decoding

var data = `.encoding = "utf-8"
annotation = "Test VM"
virtualHW.version = "10"
virtualHW.productCompatibility = "hosted"
memsize = "1024"
numvcpus = "2"
mem.hotadd = "false"
displayName = "test"
guestOS = "other3xlinux-64"
msg.autoAnswer = "true"
`

type VM struct {
	Encoding     string `vmx:".encoding"`
	Annotation   string `vmx:"annotation"`
	Hwversion    uint8  `vmx:"virtualHW.version"`
	HwProdCompat string `vmx:"virtualHW.productCompatibility"`
	Memsize      uint   `vmx:"memsize"`
	Numvcpus     uint   `vmx:"numvcpus"`
	MemHotAdd    bool   `vmx:"mem.hotadd"`
	DisplayName  string `vmx:"displayName"`
	GuestOS      string `vmx:"guestOS"`
	Autoanswer   bool   `vmx:"msg.autoAnswer"`
}

vm := new(VM)
err := Unmarshal([]byte(data), vm)

Documentation

Overview

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

Index

Constants

View Source
const (
	MAC_TYPE_STATIC    = "static"
	MAC_TYPE_GENERATED = "generated"
)
View Source
const (
	CDROM_IMAGE string = "cdrom-image"
	CDROM_RAW   string = "cdrom-raw"
)

CDROM device types

View Source
const (
	MAX_VCPUS = 64
	// Megabytes
	MAX_MEMORY                   = 1000000 // 1tib
	MAX_IDE_ADAPTERS             = 2
	MAX_IDE_DEVICES_PER_ADAPTER  = 2
	MAX_SATA_ADAPTERS            = 4
	MAX_SATA_DEVICES_PER_ADAPTER = 30
	MAX_SCSI_ADAPTERS            = 4
	MAX_SCSI_DEVICES_PER_ADAPTER = 15
	MAX_VDISKS                   = 60
	// Megabytes
	MAX_VDISK_SIZE                 = 6200000 // 62tib
	MAX_FLOPPY_ADAPTERS            = 1
	MAX_FLOPPY_DEVICES             = 2
	MAX_VNICS                      = 10
	MAX_USB_ADAPTERS               = 1
	MAX_USB_DEVICES                = 20
	MAX_PARALLEL_PORTS             = 3
	MAX_SERIAL_PORTS               = 4
	MAX_REMOTE_CONSOLE_CONNECTIONS = 40
	// Megabytes
	MAX_VIDEO_MEMORY = 512
)

Maximum values for a virtual machine From http://www.vmware.com/pdf/vsphere5/r55/vsphere-55-configuration-maximums.pdf

Variables

This section is empty.

Functions

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal traverses the value v recursively. If an encountered value implements the Marshaler interface and is not a nil pointer, Marshal calls its MarshalVMX method to produce VMX. The nil pointer exception is not strictly necessary but mimics a similar, necessary exception in the behavior of UnmarshalVMX.

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Takes VMX data and binds it to the Go value pointed by v

Types

type BIOS

type BIOS struct {
	BootOrder string `vmx:"bootorder,omitempty"`
	HDDOrder  string `vmx:"hddorder,omitempty"`
}

type BusType

type BusType string

Bus type to use when attaching or detaching CD/DVD drives and disks.

const (
	IDE  BusType = "ide"
	SCSI BusType = "scsi"
	SATA BusType = "sata"
)

Disk controllers

type Config

type Config struct {
	Version string `vmx:"version,omitempty"`
}

type Decoder

type Decoder struct {

	// Report an error if there are keys in the Go structure
	// that do not have a match in the VMX file
	ErrorUnmatched bool
	// contains filtered or unexported fields
}

func NewDecoder

func NewDecoder(reader io.Reader, errorUnmatched bool) *Decoder

func (*Decoder) Decode

func (d *Decoder) Decode(v interface{}) error

Decodes a VMX file into a Go structure. This is O(n) for now, we can optimize later if needed. Although, runtime complexities will vary depending on the value type and whether there are nested fields in the reflect value. However, the impact could be minimized by setting bounds to the recursion.

type Device

type Device struct {
	VMXID          string
	Present        bool   `vmx:"present"`
	Autodetect     bool   `vmx:"autodetect,omitempty"`
	StartConnected bool   `vmx:"startconnected,omitempty"`
	Type           string `vmx:"devicetype,omitempty"`
	Filename       string `vmxl:"filename,omitempty"`
}

type Encoder

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

func NewEncoder

func NewEncoder(buffer *bytes.Buffer) *Encoder

Creates a new encoder

func (*Encoder) Encode

func (e *Encoder) Encode(v interface{}) error

Encodes Go structure into a VMX structure, recursively.

type Error

type Error struct {
	Errors []string
}

Error implements the error interface and can represents multiple errors that occur in the course of a single decode.

func (*Error) Error

func (e *Error) Error() string

type Ethernet

type Ethernet struct {
	VMXID                string
	Address              string              `vmx:"address,omitempty"`
	GeneratedAddress     string              `vmx:"generatedaddress,omit"`
	StartConnected       bool                `vmx:"startconnected,omitempty"`
	Present              bool                `vmx:"present"`
	ConnectionType       string              `vmx:"connectiontype,omitempty"`
	VirtualDev           string              `vmx:"virtualdev,omitempty"`
	WakeOnPcktRcv        bool                `vmx:"wakeonpcktrcv,omitempty"`
	AddressType          EthernetAddressType `vmx:"addresstype,omitempty"`
	LinkStatePropagation bool                `vmx:"linkstatepropagation.enable,omitempty"`
	VNetwork             string              `vmx:"vnet,omitempty"`
}

type EthernetAddressType

type EthernetAddressType string

type FloppyDevice

type FloppyDevice struct {
	VMXID          string
	Present        bool   `vmx:"present"`
	StartConnected bool   `vmx:"startconnected,omitempty"`
	Autodetect     bool   `vmx:"autodetect,omitempty"`
	Filename       string `vmx:"filename,omitempty"`
	Filetype       string `vmx:"filetype,omitempty"`
	GuestControl   bool   `vmx:"allowGuestConnectionControl,omitempty"`
}

type GUI

type GUI struct {
	ExitAtPowerOff      bool `vmx:"exitatpoweroff,omitempty"`
	FullScreenAtPowerOn bool `vmx:"fullscreenatpoweron,omitempty"`
	PowerOnAtStartup    bool `vmx:"poweronatstartup,omitempty"`
	ExitOnCLIHalt       bool `vmx:"exitonclihlt,omitempty"`
}

type IDEDevice

type IDEDevice struct {
	Device
}

type Isolation

type Isolation struct {
	// Disable shared folders
	HgfsDisable      bool `vmx:"tools.hgfs.disable,omitempty"`
	CopyDisable      bool `vmx:"tools.copy.disable,omitempty"`
	PasteDisable     bool `vmx:"tools.paste.disable,omitempty"`
	DragNDropDisable bool `vmx:"tools.dnd.disable,omitempty"`
}

type PCIBridge

type PCIBridge struct {
	VMXID      string
	Present    bool   `vmx:"present"`
	VirtualDev string `vmx:"virtualdev,omitempty"`
	SlotNumber int    `vmx:"pcislotnumber,omitempty"`
	Functions  uint   `vmx:"functions,omitempty"`
}

type PowerType

type PowerType struct {
	PowerOff string `vmx:"poweroff,omitempty"`
	PowerOn  string `vmx:"poweron,omitempty"`
	Reset    string `vmx:"reset,omitempty"`
	Suspend  string `vmx:"suspend,omitempty"`
}

type RTC

type RTC struct {
	DiffFromUTC int `vmx:"diffFromUTC"`
}

type RemoteDisplay

type RemoteDisplay struct {
	VNCEnabled     bool   `vmx:"vnc.enabled,omitempty"`
	VNCPort        uint   `vmx:"vnc.port,omitempty"`
	VNCPassword    string `vmx:"vnc.password,omitempty"`
	VNCIPAddress   string `vmx:"vnc.ip,omitempty"`
	VNCKey         string `vmx:"vnc.key,omitempty"`
	VNCKeyMap      string `vmx:"vnc.keymap,omitempty"`
	VNCKeyMapFile  string `vmx:"vnc.keymapfile,omitempty"`
	VNCZlibLevel   uint   `vmx:"vnc.zliblevel,omitempty"`
	VNCWheelStep   string `vmx:"vncWheelStep,omitempty"`
	Depth          uint   `vmx:"depth,omitempty"`
	MaxConnections uint   `vmx:"maxconnections,omitempty"`
	MaxHeight      uint   `vmx:"maxheight,omitempty"`
	MaxWidth       uint   `vmx:"maxwidth,omitempty"`
}

type SATADevice

type SATADevice struct {
	Device
}

type SCSIDevice

type SCSIDevice struct {
	Device
	PCISlot    int    `vmx:"pcislotnumber,omitempty"`
	VirtualDev string `vmx:"virtualdev,omitempty"`
}

type SerialPort

type SerialPort struct {
	VMXID              string
	StartConnected     bool   `vmx:"startconnected,omitempty"`
	Present            bool   `vmx:"present"`
	Filetype           string `vmx:"filetype,omitempty"`
	Filename           string `vmx:"filename,omitempty"`
	Autodetect         bool   `vmx:"autodetect,omitempty"`
	TryNoRxLoss        bool   `vmx:"trynorxloss,omitempty"`
	PipeEndpoint       string `vmx:"pipe.endpoint,omitempty"`
	AllowGuestConnCtrl bool   `vmx:"allowguestconnectioncontrol,omitempty"`
	HardwareFlowCtrl   bool   `vmx:"hardwareFlowControl,omitempty"`
}

type SharedFolder

type SharedFolder struct {
	VMXID       string
	Present     bool   `vmx:"present"`
	Enabled     bool   `vmx:"enabled,omitempty"`
	ReadAccess  bool   `vmx:"readaccess,omitempty"`
	WriteAccess bool   `vmx:"writeaccess,omitempty"`
	HostPath    string `vmx:"hostpath,omitempty"`
	GuestName   string `vmx:"guestname,omitempty"`
	Expiration  string `vmx:"expiration,omitempty"`
}

type Sound

type Sound struct {
	VMXID      string
	Present    bool   `vmx:"present"`
	Filename   string `vmx:"filename,omitempty"`
	Autodetect bool   `vmx:"autodetect,omitempty"`
}

type Tools

type Tools struct {
	SyncTime      bool   `vmx:"synctime,omitempty"`
	UpgradePolicy string `vmx:"upgrade.policy,omitempty"`
	RemindInstall bool   `vmx:"remindinstall,omitempty"`
}

type USB

type USB struct {
	Present            bool `vmx:"present"`
	GenericAutoconnect bool `vmx:"generic.autoconnect,omitempty"`
}

type USBDevice

type USBDevice struct {
	VMXID   string
	Present bool   `vmx:"present"`
	Speed   uint   `vmx:"speed,omitempty"`
	Type    string `vmx:"devicetype,omitempty"`
	Port    uint   `vmx:"port,omitempty"`
	Parent  string `vmx:"parent,omitempty"`
}

type UUID

type UUID struct {
	Action string `vmx:"action,omitempty"`
	// Autogenerated, do not change
	Bios string `vmx:"bios,omitempty"`
	// Autogenerated, do not change
	Location string `vmx:"location,omitempty"`
}

type VMCI

type VMCI struct {
	VMXID string
	ID    string `vmx:"id,omitempty"`
	// We omit adding vmci.present = "false" since VMWare defaults it to TRUE
	// given that it increases IO performance between VMs in the same host
	Present bool `vmx:"present,omitempty"`
	PCISlot int  `vmx:"pcislotnumber,omitempty"`
}

type VMotion

type VMotion struct {
	CheckpointSize string `vmx:"checkpointFBSize,omitempty"`
}

type Vhardware

type Vhardware struct {
	Version int    `vmx:"version,omitempty"`
	Compat  string `vmx:"productcompatibility,omitempty"`
}

type VirtualMachine

type VirtualMachine struct {
	Encoding        string    `vmx:".encoding,omitempty"`
	ExtendedCfgFile string    `vmx:"extendedconfigfile,omitempty"`
	PowerType       PowerType `vmx:"powertype,omitempty"`
	Annotation      string    `vmx:"annotation,omitempty"`
	Vhardware       Vhardware `vmx:"virtualhw,omitempty"`
	Memsize         uint      `vmx:"memsize,omitempty"`
	NumvCPUs        uint      `vmx:"numvcpus,omitempty"`
	MemHotAdd       bool      `vmx:"mem.hotadd,omitempty"`
	VCPUHotAdd      bool      `vmx:"vcpu.hotadd,omitempty"`
	DisplayName     string    `vmx:"displayname,omitempty"`
	GuestOS         string    `vmx:"guestos,omitempty"`
	Autoanswer      bool      `vmx:"msg.autoanswer,omitempty"`
	Sound           Sound     `vmx:"sound,omitempty"`
	Tools           Tools     `vmx:"tools,omitempty"`
	NVRam           string    `vmx:"nvmram,omitempty"`
	UUID            UUID      `vmx:"uuid,omitempty"`
	CleanShutdown   bool      `vmx:"cleanshutdown,omitempty"`
	SoftPowerOff    bool      `vmx:"softpoweroff,omitempty"`
	VMCI            VMCI      `vmx:"vmci0,omitempty"`
	VMotion         VMotion   `vmx:"vmotion,omitempty"`
	USB             USB       `vmx:"usb,omitempty"`
	RTC             RTC       `vmx:"rtc,omitempty"`
	Config          Config    `vmx:"config"`
	// Enable or not nested virtualiation
	VHVEnable     bool           `vmx:"vhv.enable,omitempty"`
	RemoteDisplay RemoteDisplay  `vmx:"remotedisplay,omitempty"`
	Isolation     Isolation      `vmx:"isolation,omitempty"`
	SharedFolders []SharedFolder `vmx:"sharedfolder,omitempty"`
	PCIBridges    []PCIBridge    `vmx:"pcibridge,omitempty"`
	SerialPorts   []SerialPort   `vmx:"serial,omitempty"`
	Ethernet      []Ethernet     `vmx:"ethernet,omitempty"`
	IDEDevices    []IDEDevice    `vmx:"ide,omitempty"`
	SCSIDevices   []SCSIDevice   `vmx:"scsi,omitempty"`
	SATADevices   []SATADevice   `vmx:"sata,omitempty"`
	USBDevices    []USBDevice    `vmx:"usb,omitempty"`
	FloppyDevices []FloppyDevice `vmx:"floppy,omitempty"`
}

func (VirtualMachine) FindDevice

func (vm VirtualMachine) FindDevice(p func(Device) bool, types ...BusType) bool

FindDevice executes the given function p on all the devices of one of the given types until one of the calls returns true. If no bus types are provided all will be used. FindDevice returns true only if one of the calls of p returned true.

func (VirtualMachine) WalkDevices

func (vm VirtualMachine) WalkDevices(f func(Device), types ...BusType)

WalkDevices executes the given function f on all the devices of one of the specified types. If no bus types are provided all will be used.

Jump to

Keyboard shortcuts

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