build(deps): bump github.com/vmware/govmomi from 0.23.0 to 0.26.1

Bumps [github.com/vmware/govmomi](https://github.com/vmware/govmomi) from 0.23.0 to 0.26.1.
- [Release notes](https://github.com/vmware/govmomi/releases)
- [Changelog](https://github.com/vmware/govmomi/blob/master/CHANGELOG.md)
- [Commits](https://github.com/vmware/govmomi/compare/v0.23.0...v0.26.1)

---
updated-dependencies:
- dependency-name: github.com/vmware/govmomi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
dependabot[bot] 2021-09-04 17:51:27 +00:00 committed by Ondřej Budai
parent 974c258382
commit 137819b9cd
77 changed files with 7610 additions and 486 deletions

View file

@ -440,7 +440,7 @@ func (cmd *clone) cloneVM(ctx context.Context) (*object.VirtualMachine, error) {
_, err := datastore.Stat(ctx, vmxPath)
if err == nil {
dsPath := cmd.Datastore.Path(vmxPath)
dsPath := datastore.Path(vmxPath)
return nil, fmt.Errorf("file %s already exists", dsPath)
}
}

View file

@ -36,6 +36,7 @@ type console struct {
*flags.VirtualMachineFlag
h5 bool
wss bool
capture string
}
@ -48,6 +49,7 @@ func (cmd *console) Register(ctx context.Context, f *flag.FlagSet) {
cmd.VirtualMachineFlag.Register(ctx, f)
f.BoolVar(&cmd.h5, "h5", false, "Generate HTML5 UI console link")
f.BoolVar(&cmd.wss, "wss", false, "Generate WebSocket console link")
f.StringVar(&cmd.capture, "capture", "", "Capture console screen shot to file")
}
@ -127,6 +129,17 @@ func (cmd *console) Run(ctx context.Context, f *flag.FlagSet) error {
return c.DownloadFile(ctx, cmd.capture, u, &param)
}
if cmd.wss {
ticket, err := vm.AcquireTicket(ctx, string(types.VirtualMachineTicketTypeWebmks))
if err != nil {
return err
}
link := fmt.Sprintf("wss://%s:%d/ticket/%s", ticket.Host, ticket.Port, ticket.Ticket)
fmt.Fprintln(cmd.Out, link)
return nil
}
m := session.NewManager(c)
ticket, err := m.AcquireCloneTicket(ctx)
if err != nil {
@ -167,7 +180,7 @@ func (cmd *console) Run(ctx context.Context, f *flag.FlagSet) error {
link = fmt.Sprintf("vmrc://clone:%s@%s/?moid=%s", ticket, u.Hostname(), vm.Reference().Value)
}
fmt.Fprintln(os.Stdout, link)
fmt.Fprintln(cmd.Out, link)
return nil
}

View file

@ -43,6 +43,14 @@ var hardwareVersions = []struct {
{"7.0", "vmx-17"},
}
var (
FirmwareTypes = []string{
string(types.GuestOsDescriptorFirmwareTypeBios),
string(types.GuestOsDescriptorFirmwareTypeEfi),
}
FirmwareUsage = fmt.Sprintf("Firmware type [%s]", strings.Join(FirmwareTypes, "|"))
)
type create struct {
*flags.ClientFlag
*flags.ClusterFlag
@ -129,13 +137,7 @@ func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) {
f.StringVar(&cmd.controller, "disk.controller", "scsi", "Disk controller type")
f.StringVar(&cmd.annotation, "annotation", "", "VM description")
firmwareTypes := []string{
string(types.GuestOsDescriptorFirmwareTypeBios),
string(types.GuestOsDescriptorFirmwareTypeEfi),
}
f.StringVar(&cmd.firmware, "firmware", firmwareTypes[0],
fmt.Sprintf("Firmware type [%s]", strings.Join(firmwareTypes, "|")))
f.StringVar(&cmd.firmware, "firmware", FirmwareTypes[0], FirmwareUsage)
var versions []string
for i := range hardwareVersions {
versions = append(versions, hardwareVersions[i].esx)

View file

@ -39,9 +39,11 @@ type customize struct {
host types.CustomizationFixedName
mac flags.StringList
ip flags.StringList
ip6 flags.StringList
gateway flags.StringList
netmask flags.StringList
dnsserver flags.StringList
dnssuffix flags.StringList
kind string
}
@ -60,14 +62,18 @@ func (cmd *customize) Register(ctx context.Context, f *flag.FlagSet) {
f.StringVar(&cmd.host.Name, "name", "", "Host name")
f.Var(&cmd.mac, "mac", "MAC address")
cmd.mac = nil
f.Var(&cmd.ip, "ip", "IP address")
f.Var(&cmd.ip, "ip", "IPv4 address")
cmd.ip = nil
f.Var(&cmd.ip6, "ip6", "IPv6 addresses with optional netmask (defaults to /64), separated by comma")
cmd.ip6 = nil
f.Var(&cmd.gateway, "gateway", "Gateway")
cmd.gateway = nil
f.Var(&cmd.netmask, "netmask", "Netmask")
cmd.netmask = nil
f.Var(&cmd.dnsserver, "dns-server", "DNS server")
f.Var(&cmd.dnsserver, "dns-server", "DNS server list")
cmd.dnsserver = nil
f.Var(&cmd.dnssuffix, "dns-suffix", "DNS suffix list")
cmd.dnssuffix = nil
f.StringVar(&cmd.kind, "type", "Linux", "Customization type if spec NAME is not specified (Linux|Windows)")
}
@ -83,6 +89,8 @@ Optionally specify a customization spec NAME.
The '-ip', '-netmask' and '-gateway' flags are for static IP configuration.
If the VM has multiple NICs, an '-ip' and '-netmask' must be specified for each.
The '-dns-server' and '-dns-suffix' flags can be specified multiple times.
Windows -tz value requires the Index (hex): https://support.microsoft.com/en-us/help/973627/microsoft-time-zone-index-values
Examples:
@ -93,11 +101,58 @@ Examples:
govc vm.customize -vm VM -ip 10.0.0.178 -netmask 255.255.255.0 -ip 10.0.0.162 -netmask 255.255.255.0
# Multiple -ip with -mac are applied by vCenter to the NIC with the given MAC address
govc vm.customize -vm VM -mac 00:50:56:be:dd:f8 -ip 10.0.0.178 -netmask 255.255.255.0 -mac 00:50:56:be:60:cf -ip 10.0.0.162 -netmask 255.255.255.0
# Dual stack IPv4/IPv6, single NIC
govc vm.customize -vm VM -ip 10.0.0.1 -netmask 255.255.255.0 -ip6 '2001:db8::1/64' -name my-hostname NAME
# DHCPv6, single NIC
govc vm.customize -vm VM -ip6 dhcp6 NAME
# Static IPv6, three NICs, last one with two addresses
govc vm.customize -vm VM -ip6 2001:db8::1/64 -ip6 2001:db8::2/64 -ip6 2001:db8::3/64,2001:db8::4/64 NAME
govc vm.customize -vm VM -auto-login 3 NAME
govc vm.customize -vm VM -prefix demo NAME
govc vm.customize -vm VM -tz America/New_York NAME`
}
// Parse a string of multiple IPv6 addresses with optional netmask; separated by comma
func parseIPv6Argument(argv string) (ipconf []types.BaseCustomizationIpV6Generator, err error) {
for _, substring := range strings.Split(argv, ",") {
// remove leading and trailing white space
substring = strings.TrimSpace(substring)
// handle "dhcp6" and lists of static IPv6 addresses
switch substring {
case "dhcp6":
ipconf = append(
ipconf,
&types.CustomizationDhcpIpV6Generator{},
)
default:
// check if subnet mask was specified
switch strings.Count(substring, "/") {
// no mask, set default
case 0:
ipconf = append(ipconf, &types.CustomizationFixedIpV6{
IpAddress: substring,
SubnetMask: 64,
})
// a single forward slash was found: parse and use subnet mask
case 1:
parts := strings.Split(substring, "/")
mask, err := strconv.Atoi(parts[1])
if err != nil {
return nil, fmt.Errorf("unable to convert subnet mask to int: %w", err)
}
ipconf = append(ipconf, &types.CustomizationFixedIpV6{
IpAddress: parts[0],
SubnetMask: int32(mask),
})
// too many forward slashes; return error
default:
return nil, fmt.Errorf("unable to parse IPv6 address (too many subnet separators): %s", substring)
}
}
}
return ipconf, nil
}
func (cmd *customize) Run(ctx context.Context, f *flag.FlagSet) error {
vm, err := cmd.VirtualMachineFlag.VirtualMachine()
if err != nil {
@ -173,6 +228,8 @@ func (cmd *customize) Run(ctx context.Context, f *flag.FlagSet) error {
}
}
spec.GlobalIPSettings.DnsSuffixList = cmd.dnssuffix
if cmd.prefix.Base != "" {
if isWindows {
sysprep.UserData.ComputerName = &cmd.prefix
@ -234,6 +291,23 @@ func (cmd *customize) Run(ctx context.Context, f *flag.FlagSet) error {
}
}
for i, ip6 := range cmd.ip6 {
ipconfig, err := parseIPv6Argument(ip6)
if err != nil {
return err
}
// use the same logic as the ip switch: the first occurrence of the ip6 switch is assigned to the first nic,
// the second to the second nic and so forth.
if spec.NicSettingMap == nil || len(spec.NicSettingMap) < i {
return fmt.Errorf("unable to find a network adapter for IPv6 settings %d (%s)", i, ip6)
}
nic := &spec.NicSettingMap[i]
if nic.Adapter.IpV6Spec == nil {
nic.Adapter.IpV6Spec = new(types.CustomizationIPSettingsIpV6AddressSpec)
}
nic.Adapter.IpV6Spec.Ip = append(nic.Adapter.IpV6Spec.Ip, ipconfig...)
}
task, err := vm.Customize(ctx, *spec)
if err != nil {
return err

View file

@ -79,7 +79,7 @@ func (cmd *download) Run(ctx context.Context, f *flag.FlagSet) error {
return os.ErrExist
}
c, err := cmd.Toolbox()
c, err := cmd.Toolbox(ctx)
if err != nil {
return err
}

View file

@ -26,8 +26,6 @@ import (
"github.com/vmware/govmomi/guest"
"github.com/vmware/govmomi/guest/toolbox"
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/vim25/mo"
"github.com/vmware/govmomi/vim25/types"
)
type GuestFlag struct {
@ -70,38 +68,18 @@ func (flag *GuestFlag) Process(ctx context.Context) error {
return nil
}
func (flag *GuestFlag) Toolbox() (*toolbox.Client, error) {
pm, err := flag.ProcessManager()
if err != nil {
return nil, err
}
fm, err := flag.FileManager()
if err != nil {
return nil, err
}
func (flag *GuestFlag) Toolbox(ctx context.Context) (*toolbox.Client, error) {
vm, err := flag.VirtualMachine()
if err != nil {
return nil, err
}
family := ""
var props mo.VirtualMachine
err = vm.Properties(context.Background(), vm.Reference(), []string{"guest.guestFamily"}, &props)
c, err := flag.Client()
if err != nil {
return nil, err
}
if props.Guest != nil {
family = props.Guest.GuestFamily
}
return &toolbox.Client{
ProcessManager: pm,
FileManager: fm,
Authentication: flag.Auth(),
GuestFamily: types.VirtualMachineGuestOsFamily(family),
}, nil
return toolbox.NewClient(ctx, c, vm, flag.Auth())
}
func (flag *GuestFlag) FileManager() (*guest.FileManager, error) {

View file

@ -58,6 +58,11 @@ The guest.run command starts a program in the VM with i/o redirected, waits for
propagates the exit code to the govc process exit code. Note that stdout and stderr are redirected by default,
stdin is only redirected when the '-d' flag is specified.
Note that vmware-tools requires program PATH to be absolute.
If PATH is not absolute and vm guest family is Windows,
guest.run changes the command to: 'c:\\Windows\\System32\\cmd.exe /c "PATH [ARG]..."'
Otherwise the command is changed to: '/bin/bash -c "PATH [ARG]..."'
Examples:
govc guest.run -vm $name ifconfig
govc guest.run -vm $name ifconfig eth0
@ -65,7 +70,8 @@ Examples:
govc guest.run -vm $name -d "hello $USER" cat
govc guest.run -vm $name curl -s :invalid: || echo $? # exit code 6
govc guest.run -vm $name -e FOO=bar -e BIZ=baz -C /tmp env
govc guest.run -l root:'mypassword' -vm my_vm_hostname "ntpdate -u pool.ntp.org"`
govc guest.run -vm $name -l root:mypassword ntpdate -u pool.ntp.org
govc guest.run -vm $name powershell C:\\network_refresh.ps1`
}
func (cmd *run) Run(ctx context.Context, f *flag.FlagSet) error {
@ -74,7 +80,7 @@ func (cmd *run) Run(ctx context.Context, f *flag.FlagSet) error {
}
name := f.Arg(0)
c, err := cmd.Toolbox()
c, err := cmd.Toolbox(ctx)
if err != nil {
return err
}

View file

@ -77,7 +77,7 @@ func (cmd *upload) Run(ctx context.Context, f *flag.FlagSet) error {
return flag.ErrHelp
}
c, err := cmd.Toolbox()
c, err := cmd.Toolbox(ctx)
if err != nil {
return err
}

View file

@ -0,0 +1,250 @@
/*
Copyright (c) 2014-2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package vm
import (
"context"
"flag"
"fmt"
"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/types"
)
type instantclone struct {
*flags.ClientFlag
*flags.DatacenterFlag
*flags.DatastoreFlag
*flags.ResourcePoolFlag
*flags.NetworkFlag
*flags.FolderFlag
*flags.VirtualMachineFlag
name string
extraConfig extraConfig
Client *vim25.Client
Datacenter *object.Datacenter
Datastore *object.Datastore
ResourcePool *object.ResourcePool
Folder *object.Folder
VirtualMachine *object.VirtualMachine
}
func init() {
cli.Register("vm.instantclone", &instantclone{})
}
func (cmd *instantclone) Register(ctx context.Context, f *flag.FlagSet) {
cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
cmd.ClientFlag.Register(ctx, f)
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
cmd.DatacenterFlag.Register(ctx, f)
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
cmd.DatastoreFlag.Register(ctx, f)
cmd.ResourcePoolFlag, ctx = flags.NewResourcePoolFlag(ctx)
cmd.ResourcePoolFlag.Register(ctx, f)
cmd.NetworkFlag, ctx = flags.NewNetworkFlag(ctx)
cmd.NetworkFlag.Register(ctx, f)
cmd.FolderFlag, ctx = flags.NewFolderFlag(ctx)
cmd.FolderFlag.Register(ctx, f)
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
cmd.VirtualMachineFlag.Register(ctx, f)
f.Var(&cmd.extraConfig, "e", "ExtraConfig. <key>=<value>")
}
func (cmd *instantclone) Usage() string {
return "NAME"
}
func (cmd *instantclone) Description() string {
return `Instant Clone VM to NAME.
Examples:
govc vm.instantclone -vm source-vm new-vm
# Configure ExtraConfig variables on a guest VM:
govc vm.instantclone -vm source-vm -e guestinfo.ipaddress=192.168.0.1 -e guestinfo.netmask=255.255.255.0 new-vm
# Read the variable set above inside the guest:
vmware-rpctool "info-get guestinfo.ipaddress"
vmware-rpctool "info-get guestinfo.netmask"`
}
func (cmd *instantclone) Process(ctx context.Context) error {
if err := cmd.ClientFlag.Process(ctx); err != nil {
return err
}
if err := cmd.DatacenterFlag.Process(ctx); err != nil {
return err
}
if err := cmd.DatastoreFlag.Process(ctx); err != nil {
return err
}
if err := cmd.ResourcePoolFlag.Process(ctx); err != nil {
return err
}
if err := cmd.NetworkFlag.Process(ctx); err != nil {
return err
}
if err := cmd.FolderFlag.Process(ctx); err != nil {
return err
}
if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
return err
}
return nil
}
func (cmd *instantclone) Run(ctx context.Context, f *flag.FlagSet) error {
var err error
if len(f.Args()) != 1 {
return flag.ErrHelp
}
cmd.name = f.Arg(0)
if cmd.name == "" {
return flag.ErrHelp
}
cmd.Client, err = cmd.ClientFlag.Client()
if err != nil {
return err
}
cmd.Datacenter, err = cmd.DatacenterFlag.Datacenter()
if err != nil {
return err
}
cmd.Datastore, err = cmd.DatastoreFlag.Datastore()
if err != nil {
return err
}
cmd.Folder, err = cmd.FolderFlag.Folder()
if err != nil {
return err
}
cmd.ResourcePool, err = cmd.ResourcePoolFlag.ResourcePool()
if err != nil {
return err
}
cmd.VirtualMachine, err = cmd.VirtualMachineFlag.VirtualMachine()
if err != nil {
return err
}
if cmd.VirtualMachine == nil {
return flag.ErrHelp
}
_, err = cmd.instantcloneVM(ctx)
if err != nil {
return err
}
return nil
}
func (cmd *instantclone) instantcloneVM(ctx context.Context) (*object.VirtualMachine, error) {
relocateSpec := types.VirtualMachineRelocateSpec{}
if cmd.NetworkFlag.IsSet() {
devices, err := cmd.VirtualMachine.Device(ctx)
if err != nil {
return nil, err
}
// prepare virtual device config spec for network card
configSpecs := []types.BaseVirtualDeviceConfigSpec{}
op := types.VirtualDeviceConfigSpecOperationAdd
card, derr := cmd.NetworkFlag.Device()
if derr != nil {
return nil, derr
}
// search for the first network card of the source
for _, device := range devices {
if _, ok := device.(types.BaseVirtualEthernetCard); ok {
op = types.VirtualDeviceConfigSpecOperationEdit
// set new backing info
cmd.NetworkFlag.Change(device, card)
card = device
break
}
}
configSpecs = append(configSpecs, &types.VirtualDeviceConfigSpec{
Operation: op,
Device: card,
})
relocateSpec.DeviceChange = configSpecs
}
if cmd.FolderFlag.IsSet() {
folderref := cmd.Folder.Reference()
relocateSpec.Folder = &folderref
}
if cmd.ResourcePoolFlag.IsSet() {
poolref := cmd.ResourcePool.Reference()
relocateSpec.Pool = &poolref
}
if cmd.DatastoreFlag.IsSet() {
datastoreref := cmd.Datastore.Reference()
relocateSpec.Datastore = &datastoreref
}
instantcloneSpec := &types.VirtualMachineInstantCloneSpec{
Name: cmd.name,
Location: relocateSpec,
}
if len(cmd.extraConfig) > 0 {
instantcloneSpec.Config = cmd.extraConfig
}
task, err := cmd.VirtualMachine.InstantClone(ctx, *instantcloneSpec)
if err != nil {
return nil, err
}
logger := cmd.ProgressLogger(fmt.Sprintf("Instant Cloning %s to %s...", cmd.VirtualMachine.InventoryPath, cmd.name))
defer logger.Wait()
info, err := task.WaitForResult(ctx, logger)
if err != nil {
return nil, err
}
return object.NewVirtualMachine(cmd.Client, info.Result.(types.ManagedObjectReference)), nil
}

View file

@ -64,8 +64,8 @@ func (cmd *markasvm) Description() string {
return `Mark VM template as a virtual machine.
Examples:
govc vm.markasvm $name -host host1
govc vm.markasvm $name -pool cluster1/Resources`
govc vm.markasvm -host host1 $name
govc vm.markasvm -host host1 $name`
}
func (cmd *markasvm) Run(ctx context.Context, f *flag.FlagSet) error {