toolbox

package
v0.56.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 18 Imported by: 30

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrProcessNotFound = errors.New("process not found in guest")

ErrProcessNotFound is returned by Run when the guest does not report the process that was started, such as after VMware Tools was restarted.

Functions

This section is empty.

Types

type Client

type Client struct {
	ProcessManager *guest.ProcessManager
	FileManager    *guest.FileManager
	Authentication types.BaseGuestAuthentication
	GuestFamily    types.VirtualMachineGuestOsFamily
}

Client attempts to expose guest.OperationsManager as idiomatic Go interfaces

func NewClient added in v0.26.0

NewClient initializes a Client's ProcessManager, FileManager and GuestFamily

func (*Client) Download

func (c *Client) Download(ctx context.Context, src string) (io.ReadCloser, int64, error)

Download initiates a file transfer from the guest

func (*Client) Run

func (c *Client) Run(ctx context.Context, cmd *exec.Cmd) error

Run implements exec.Cmd.Run over vmx guest RPC against standard vmware-tools or toolbox. If the guest stops reporting the started process, Run returns an error wrapping ErrProcessNotFound. The command was started and may have completed, so its outcome is unknown and it should only be run again if it is safe to do so.

Example
package main

import (
	"context"
	"fmt"
	"os"
	"os/exec"

	"github.com/vmware/govmomi/find"
	"github.com/vmware/govmomi/guest/toolbox"
	"github.com/vmware/govmomi/simulator"
	"github.com/vmware/govmomi/test"
	"github.com/vmware/govmomi/vim25"
	"github.com/vmware/govmomi/vim25/types"
)

func main() {
	simulator.Run(func(ctx context.Context, c *vim25.Client) error {
		if !test.HasDocker() {
			fmt.Println("Linux")
			return nil
		}
		vm, err := find.NewFinder(c).VirtualMachine(ctx, "DC0_H0_VM0")
		if err != nil {
			return err
		}
		err = simulator.RunContainer(ctx, c, vm, "nginx")
		if err != nil {
			return err
		}

		tools, err := toolbox.NewClient(ctx, c, vm, &types.NamePasswordAuthentication{
			Username: "user",
			Password: "pass",
		})

		cmd := &exec.Cmd{
			Path:   "uname",
			Stdout: os.Stdout,
			Stderr: os.Stderr,
		}

		return tools.Run(ctx, cmd)
	})
}
Output:
Linux

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, src io.Reader, dst string, p soap.Upload, attr types.BaseGuestFileAttributes, force bool) error

Upload transfers a file to the guest

Jump to

Keyboard shortcuts

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