.: bump govmomi to v0.30.6

Bumping govmomi to include an error check fix needed
to work with go1.20. We made this fix in the CI, but
were reliant on the text matching of error strings,
which is why it didn't catch the actual issue. This

Fix in b4eac19369
PR to bump govmomi in cloud-provider-vsphere: https://github.com/kubernetes/cloud-provider-vsphere/pull/738

Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>
This commit is contained in:
Madhav Jivrajani 2023-09-18 22:15:49 +05:30
parent 76a22d3b32
commit fc6b19a4ba
22 changed files with 268 additions and 90 deletions

2
go.mod
View File

@ -65,7 +65,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.2
github.com/vishvananda/netlink v1.1.0
github.com/vmware/govmomi v0.30.0
github.com/vmware/govmomi v0.30.6
go.etcd.io/etcd/api/v3 v3.5.9
go.etcd.io/etcd/client/pkg/v3 v3.5.9
go.etcd.io/etcd/client/v3 v3.5.9

4
go.sum
View File

@ -826,8 +826,8 @@ github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYp
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8=
github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
github.com/vmware/govmomi v0.30.0 h1:Fm8ugPnnlMSTSceDKY9goGvjmqc6eQLPUSUeNXdpeXA=
github.com/vmware/govmomi v0.30.0/go.mod h1:F7adsVewLNHsW/IIm7ziFURaXDaHEwcc+ym4r3INMdY=
github.com/vmware/govmomi v0.30.6 h1:O3tjSwQBy0XwI5uK1/yVIfQ1LP9bAECEDUfifnyGs9U=
github.com/vmware/govmomi v0.30.6/go.mod h1:epgoslm97rLECMV4D+08ORzUBEU7boFSepKjt7AYVGg=
github.com/vmware/vmw-guestinfo v0.0.0-20170707015358-25eff159a728/go.mod h1:x9oS4Wk2s2u4tS29nEaDLdzvuHdB19CvSGJjPgkZJNk=
github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=

View File

@ -15,7 +15,7 @@ require (
github.com/google/go-cmp v0.5.9
github.com/rubiojr/go-vhd v0.0.0-20200706105327-02e210299021
github.com/stretchr/testify v1.8.2
github.com/vmware/govmomi v0.30.0
github.com/vmware/govmomi v0.30.6
golang.org/x/crypto v0.11.0
golang.org/x/oauth2 v0.8.0
google.golang.org/api v0.114.0

View File

@ -337,8 +337,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/vmware/govmomi v0.30.0 h1:Fm8ugPnnlMSTSceDKY9goGvjmqc6eQLPUSUeNXdpeXA=
github.com/vmware/govmomi v0.30.0/go.mod h1:F7adsVewLNHsW/IIm7ziFURaXDaHEwcc+ym4r3INMdY=
github.com/vmware/govmomi v0.30.6 h1:O3tjSwQBy0XwI5uK1/yVIfQ1LP9bAECEDUfifnyGs9U=
github.com/vmware/govmomi v0.30.6/go.mod h1:epgoslm97rLECMV4D+08ORzUBEU7boFSepKjt7AYVGg=
github.com/vmware/vmw-guestinfo v0.0.0-20170707015358-25eff159a728/go.mod h1:x9oS4Wk2s2u4tS29nEaDLdzvuHdB19CvSGJjPgkZJNk=
github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

View File

@ -34,13 +34,12 @@ archives:
- id: govcbuild
builds:
- govc
name_template: "govc_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
replacements: &replacements
darwin: Darwin
linux: Linux
windows: Windows
freebsd: FreeBSD
amd64: x86_64
name_template: >-
govc_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
format_overrides: &overrides
- goos: windows
format: zip
@ -52,8 +51,12 @@ archives:
- id: vcsimbuild
builds:
- vcsim
name_template: "vcsim_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
replacements: *replacements
name_template: >-
vcsim_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
format_overrides: *overrides
files: *extrafiles

View File

@ -1,5 +1,5 @@
/*
Copyright (c) 2014-2020 VMware, Inc. All Rights Reserved.
Copyright (c) 2014-2023 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.
@ -784,6 +784,11 @@ func (f *Finder) NetworkList(ctx context.Context, path string) ([]object.Network
}
if len(ns) == 0 {
net, nerr := f.networkByID(ctx, path)
if nerr == nil {
return []object.NetworkReference{net}, nil
}
return nil, &NotFoundError{"network", path}
}
@ -798,18 +803,13 @@ func (f *Finder) NetworkList(ctx context.Context, path string) ([]object.Network
// Examples:
// - Name: "dvpg-1"
// - Inventory Path: "vds-1/dvpg-1"
// - Cluster Path: "/dc-1/host/cluster-1/dvpg-1"
// - ManagedObject ID: "DistributedVirtualPortgroup:dvportgroup-53"
// - Logical Switch UUID: "da2a59b8-2450-4cb2-b5cc-79c4c1d2144c"
// - Segment ID: "/infra/segments/vnet_ce50e69b-1784-4a14-9206-ffd7f1f146f7"
func (f *Finder) Network(ctx context.Context, path string) (object.NetworkReference, error) {
networks, err := f.NetworkList(ctx, path)
if err != nil {
if _, ok := err.(*NotFoundError); ok {
net, nerr := f.networkByID(ctx, path)
if nerr == nil {
return net, nil
}
}
return nil, err
}

View File

@ -21,5 +21,5 @@ const (
ClientName = "govmomi"
// ClientVersion is the version of this SDK
ClientVersion = "0.30.0"
ClientVersion = "0.30.6"
)

View File

@ -1,5 +1,5 @@
/*
Copyright (c) 2014-2016 VMware, Inc. All Rights Reserved.
Copyright (c) 2014-2023 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.
@ -312,6 +312,7 @@ func (l Lister) ListComputeResource(ctx context.Context) ([]Element, error) {
fields := []string{
"host",
"network",
"resourcePool",
}
@ -327,6 +328,7 @@ func (l Lister) ListComputeResource(ctx context.Context) ([]Element, error) {
childTypes := []string{
"HostSystem",
"Network",
"ResourcePool",
}

View File

@ -125,7 +125,9 @@ func EndpointURL(ctx context.Context, c *vim25.Client, path string, filter *type
path = endpoint.Url
if u, err := url.Parse(path); err == nil {
if c.Thumbprint(u.Host) == "" {
// Set thumbprint only for endpoints on hosts outside this vCenter.
// Platform Services may live on multiple hosts.
if c.URL().Host != u.Host && c.Thumbprint(u.Host) == "" {
c.SetThumbprint(u.Host, endpointThumbprint(endpoint))
}
}

View File

@ -86,10 +86,7 @@ func (info *HostCertificateInfo) FromURL(u *url.URL, config *tls.Config) error {
conn, err := tls.Dial("tcp", addr, config)
if err != nil {
switch err.(type) {
case x509.UnknownAuthorityError:
case x509.HostnameError:
default:
if !soap.IsCertificateUntrusted(err) {
return err
}

View File

@ -93,7 +93,18 @@ func (s SearchIndex) FindByInventoryPath(ctx context.Context, path string) (Refe
if res.Returnval == nil {
return nil, nil
}
return NewReference(s.c, *res.Returnval), nil
r := NewReference(s.c, *res.Returnval)
type common interface {
SetInventoryPath(string)
}
if c, ok := r.(common); ok {
c.SetInventoryPath(path)
}
return r, nil
}
// FindByIp finds a virtual machine or host by IP address.

View File

@ -114,6 +114,20 @@ func (c *container) inspect(vm *VirtualMachine) error {
net := &vm.Guest.Net[0]
net.IpAddress = []string{s.IPAddress}
net.MacAddress = s.MacAddress
net.IpConfig = &types.NetIpConfigInfo{
IpAddress: []types.NetIpConfigInfoIpAddress{{
IpAddress: s.IPAddress,
PrefixLength: int32(s.IPPrefixLen),
State: string(types.NetIpConfigInfoIpAddressStatusPreferred),
}},
}
}
for _, d := range vm.Config.Hardware.Device {
if eth, ok := d.(types.BaseVirtualEthernetCard); ok {
eth.GetVirtualEthernetCard().MacAddress = s.MacAddress
break
}
}
}
@ -235,6 +249,8 @@ func (c *container) start(ctx *Context, vm *VirtualMachine) {
var args []string
var env []string
mountDMI := true
ports := make(map[string]string)
for _, opt := range vm.Config.ExtraConfig {
val := opt.GetOptionValue()
@ -247,6 +263,23 @@ func (c *container) start(ctx *Context, vm *VirtualMachine) {
continue
}
if val.Key == "RUN.mountdmi" {
var mount bool
err := json.Unmarshal([]byte(val.Value.(string)), &mount)
if err == nil {
mountDMI = mount
}
}
if strings.HasPrefix(val.Key, "RUN.port.") {
sKey := strings.Split(val.Key, ".")
containerPort := sKey[len(sKey)-1]
ports[containerPort] = val.Value.(string)
}
if strings.HasPrefix(val.Key, "RUN.env.") {
sKey := strings.Split(val.Key, ".")
envKey := sKey[len(sKey)-1]
env = append(env, "--env", fmt.Sprintf("%s=%s", envKey, val.Value.(string)))
}
if strings.HasPrefix(val.Key, "guestinfo.") {
key := strings.Replace(strings.ToUpper(val.Key), ".", "_", -1)
env = append(env, "--env", fmt.Sprintf("VMX_%s=%s", key, val.Value.(string)))
@ -260,14 +293,22 @@ func (c *container) start(ctx *Context, vm *VirtualMachine) {
// Configure env as the data access method for cloud-init-vmware-guestinfo
env = append(env, "--env", "VMX_GUESTINFO=true")
}
if len(ports) != 0 {
// Publish the specified container ports
for containerPort, hostPort := range ports {
env = append(env, "-p", fmt.Sprintf("%s:%s", hostPort, containerPort))
}
}
c.name = fmt.Sprintf("vcsim-%s-%s", sanitizeName(vm.Name), vm.uid)
run := append([]string{"docker", "run", "-d", "--name", c.name}, env...)
if err := c.createDMI(vm, c.name); err != nil {
return
if mountDMI {
if err := c.createDMI(vm, c.name); err != nil {
return
}
run = append(run, "-v", fmt.Sprintf("%s:%s:ro", c.name, "/sys/class/dmi/id"))
}
run = append(run, "-v", fmt.Sprintf("%s:%s:ro", c.name, "/sys/class/dmi/id"))
args = append(run, args...)
cmd := exec.Command(shell, "-c", strings.Join(args, " "))

View File

@ -52,7 +52,7 @@ var HostSystem = mo.HostSystem{
DynamicData: types.DynamicData{},
ConnectionState: "connected",
PowerState: "poweredOn",
StandbyMode: "",
StandbyMode: "none",
InMaintenanceMode: false,
BootTime: (*time.Time)(nil),
HealthSystemRuntime: &types.HealthSystemRuntime{

View File

@ -53,9 +53,22 @@ var GuestID = []types.VirtualMachineGuestOsIdentifier{
types.VirtualMachineGuestOsIdentifierWindows9Guest,
types.VirtualMachineGuestOsIdentifierWindows9_64Guest,
types.VirtualMachineGuestOsIdentifierWindows9Server64Guest,
types.VirtualMachineGuestOsIdentifierWindows11_64Guest,
types.VirtualMachineGuestOsIdentifierWindows12_64Guest,
types.VirtualMachineGuestOsIdentifierWindowsHyperVGuest,
types.VirtualMachineGuestOsIdentifierWindows2019srv_64Guest,
types.VirtualMachineGuestOsIdentifierWindows2019srvNext_64Guest,
types.VirtualMachineGuestOsIdentifierWindows2022srvNext_64Guest,
types.VirtualMachineGuestOsIdentifierFreebsdGuest,
types.VirtualMachineGuestOsIdentifierFreebsd64Guest,
types.VirtualMachineGuestOsIdentifierFreebsd11Guest,
types.VirtualMachineGuestOsIdentifierFreebsd11_64Guest,
types.VirtualMachineGuestOsIdentifierFreebsd12Guest,
types.VirtualMachineGuestOsIdentifierFreebsd12_64Guest,
types.VirtualMachineGuestOsIdentifierFreebsd13Guest,
types.VirtualMachineGuestOsIdentifierFreebsd13_64Guest,
types.VirtualMachineGuestOsIdentifierFreebsd14Guest,
types.VirtualMachineGuestOsIdentifierFreebsd14_64Guest,
types.VirtualMachineGuestOsIdentifierRedhatGuest,
types.VirtualMachineGuestOsIdentifierRhel2Guest,
types.VirtualMachineGuestOsIdentifierRhel3Guest,
@ -68,18 +81,24 @@ var GuestID = []types.VirtualMachineGuestOsIdentifier{
types.VirtualMachineGuestOsIdentifierRhel6_64Guest,
types.VirtualMachineGuestOsIdentifierRhel7Guest,
types.VirtualMachineGuestOsIdentifierRhel7_64Guest,
types.VirtualMachineGuestOsIdentifierRhel8_64Guest,
types.VirtualMachineGuestOsIdentifierRhel9_64Guest,
types.VirtualMachineGuestOsIdentifierCentosGuest,
types.VirtualMachineGuestOsIdentifierCentos64Guest,
types.VirtualMachineGuestOsIdentifierCentos6Guest,
types.VirtualMachineGuestOsIdentifierCentos6_64Guest,
types.VirtualMachineGuestOsIdentifierCentos7Guest,
types.VirtualMachineGuestOsIdentifierCentos7_64Guest,
types.VirtualMachineGuestOsIdentifierCentos8_64Guest,
types.VirtualMachineGuestOsIdentifierCentos9_64Guest,
types.VirtualMachineGuestOsIdentifierOracleLinuxGuest,
types.VirtualMachineGuestOsIdentifierOracleLinux64Guest,
types.VirtualMachineGuestOsIdentifierOracleLinux6Guest,
types.VirtualMachineGuestOsIdentifierOracleLinux6_64Guest,
types.VirtualMachineGuestOsIdentifierOracleLinux7Guest,
types.VirtualMachineGuestOsIdentifierOracleLinux7_64Guest,
types.VirtualMachineGuestOsIdentifierOracleLinux8_64Guest,
types.VirtualMachineGuestOsIdentifierOracleLinux9_64Guest,
types.VirtualMachineGuestOsIdentifierSuseGuest,
types.VirtualMachineGuestOsIdentifierSuse64Guest,
types.VirtualMachineGuestOsIdentifierSlesGuest,
@ -90,6 +109,8 @@ var GuestID = []types.VirtualMachineGuestOsIdentifier{
types.VirtualMachineGuestOsIdentifierSles11_64Guest,
types.VirtualMachineGuestOsIdentifierSles12Guest,
types.VirtualMachineGuestOsIdentifierSles12_64Guest,
types.VirtualMachineGuestOsIdentifierSles15_64Guest,
types.VirtualMachineGuestOsIdentifierSles16_64Guest,
types.VirtualMachineGuestOsIdentifierNld9Guest,
types.VirtualMachineGuestOsIdentifierOesGuest,
types.VirtualMachineGuestOsIdentifierSjdsGuest,
@ -114,12 +135,18 @@ var GuestID = []types.VirtualMachineGuestOsIdentifier{
types.VirtualMachineGuestOsIdentifierDebian9_64Guest,
types.VirtualMachineGuestOsIdentifierDebian10Guest,
types.VirtualMachineGuestOsIdentifierDebian10_64Guest,
types.VirtualMachineGuestOsIdentifierDebian11Guest,
types.VirtualMachineGuestOsIdentifierDebian11_64Guest,
types.VirtualMachineGuestOsIdentifierDebian12Guest,
types.VirtualMachineGuestOsIdentifierDebian12_64Guest,
types.VirtualMachineGuestOsIdentifierAsianux3Guest,
types.VirtualMachineGuestOsIdentifierAsianux3_64Guest,
types.VirtualMachineGuestOsIdentifierAsianux4Guest,
types.VirtualMachineGuestOsIdentifierAsianux4_64Guest,
types.VirtualMachineGuestOsIdentifierAsianux5_64Guest,
types.VirtualMachineGuestOsIdentifierAsianux7_64Guest,
types.VirtualMachineGuestOsIdentifierAsianux8_64Guest,
types.VirtualMachineGuestOsIdentifierAsianux9_64Guest,
types.VirtualMachineGuestOsIdentifierOpensuseGuest,
types.VirtualMachineGuestOsIdentifierOpensuse64Guest,
types.VirtualMachineGuestOsIdentifierFedoraGuest,
@ -130,10 +157,16 @@ var GuestID = []types.VirtualMachineGuestOsIdentifier{
types.VirtualMachineGuestOsIdentifierOther26xLinuxGuest,
types.VirtualMachineGuestOsIdentifierOtherLinuxGuest,
types.VirtualMachineGuestOsIdentifierOther3xLinuxGuest,
types.VirtualMachineGuestOsIdentifierOther4xLinuxGuest,
types.VirtualMachineGuestOsIdentifierOther5xLinuxGuest,
types.VirtualMachineGuestOsIdentifierOther6xLinuxGuest,
types.VirtualMachineGuestOsIdentifierGenericLinuxGuest,
types.VirtualMachineGuestOsIdentifierOther24xLinux64Guest,
types.VirtualMachineGuestOsIdentifierOther26xLinux64Guest,
types.VirtualMachineGuestOsIdentifierOther3xLinux64Guest,
types.VirtualMachineGuestOsIdentifierOther4xLinux64Guest,
types.VirtualMachineGuestOsIdentifierOther5xLinux64Guest,
types.VirtualMachineGuestOsIdentifierOther6xLinux64Guest,
types.VirtualMachineGuestOsIdentifierOtherLinux64Guest,
types.VirtualMachineGuestOsIdentifierSolaris6Guest,
types.VirtualMachineGuestOsIdentifierSolaris7Guest,
@ -162,10 +195,24 @@ var GuestID = []types.VirtualMachineGuestOsIdentifier{
types.VirtualMachineGuestOsIdentifierDarwin14_64Guest,
types.VirtualMachineGuestOsIdentifierDarwin15_64Guest,
types.VirtualMachineGuestOsIdentifierDarwin16_64Guest,
types.VirtualMachineGuestOsIdentifierDarwin17_64Guest,
types.VirtualMachineGuestOsIdentifierDarwin18_64Guest,
types.VirtualMachineGuestOsIdentifierDarwin19_64Guest,
types.VirtualMachineGuestOsIdentifierDarwin20_64Guest,
types.VirtualMachineGuestOsIdentifierDarwin21_64Guest,
types.VirtualMachineGuestOsIdentifierDarwin22_64Guest,
types.VirtualMachineGuestOsIdentifierDarwin23_64Guest,
types.VirtualMachineGuestOsIdentifierVmkernelGuest,
types.VirtualMachineGuestOsIdentifierVmkernel5Guest,
types.VirtualMachineGuestOsIdentifierVmkernel6Guest,
types.VirtualMachineGuestOsIdentifierVmkernel65Guest,
types.VirtualMachineGuestOsIdentifierVmkernel7Guest,
types.VirtualMachineGuestOsIdentifierVmkernel8Guest,
types.VirtualMachineGuestOsIdentifierAmazonlinux2_64Guest,
types.VirtualMachineGuestOsIdentifierAmazonlinux3_64Guest,
types.VirtualMachineGuestOsIdentifierCrxPod1Guest,
types.VirtualMachineGuestOsIdentifierRockylinux_64Guest,
types.VirtualMachineGuestOsIdentifierAlmalinux_64Guest,
types.VirtualMachineGuestOsIdentifierOtherGuest,
types.VirtualMachineGuestOsIdentifierOtherGuest64,
}

View File

@ -19,6 +19,7 @@ package simulator
import (
"math/rand"
"strconv"
"strings"
"time"
"github.com/vmware/govmomi/simulator/esx"
@ -174,9 +175,6 @@ func (p *PerformanceManager) QueryPerf(ctx *Context, req *types.QueryPerf) soap.
body.Res.Returnval = make([]types.BasePerfEntityMetricBase, len(req.QuerySpec))
for i, qs := range req.QuerySpec {
metrics := new(types.PerfEntityMetric)
metrics.Entity = qs.Entity
// Get metric data for this entity type
metricData, ok := p.metricData[qs.Entity.Type]
if !ok {
@ -202,10 +200,13 @@ func (p *PerformanceManager) QueryPerf(ctx *Context, req *types.QueryPerf) soap.
interval = 20 // TODO: Determine from entity type
}
n := 1 + int32(end.Sub(start).Seconds())/interval
if n > qs.MaxSample {
if qs.MaxSample > 0 && n > qs.MaxSample {
n = qs.MaxSample
}
metrics := new(types.PerfEntityMetric)
metrics.Entity = qs.Entity
// Loop through each interval "tick"
metrics.SampleInfo = make([]types.PerfSampleInfo, n)
metrics.Value = make([]types.BasePerfMetricSeries, len(qs.MetricId))
@ -213,10 +214,11 @@ func (p *PerformanceManager) QueryPerf(ctx *Context, req *types.QueryPerf) soap.
metrics.SampleInfo[tick] = types.PerfSampleInfo{Timestamp: end.Add(time.Duration(-interval*tick) * time.Second), Interval: interval}
}
series := make([]*types.PerfMetricIntSeries, len(qs.MetricId))
for j, mid := range qs.MetricId {
// Create list of metrics for this tick
series := &types.PerfMetricIntSeries{Value: make([]int64, n)}
series.Id = mid
series[j] = &types.PerfMetricIntSeries{Value: make([]int64, n)}
series[j].Id = mid
points := metricData[mid.CounterId]
offset := int64(start.Unix()) / int64(interval)
@ -237,11 +239,56 @@ func (p *PerformanceManager) QueryPerf(ctx *Context, req *types.QueryPerf) soap.
} else {
p = 0
}
series.Value[tick] = p
series[j].Value[tick] = p
}
metrics.Value[j] = series
metrics.Value[j] = series[j]
}
if qs.Format == string(types.PerfFormatCsv) {
metricsCsv := new(types.PerfEntityMetricCSV)
metricsCsv.Entity = qs.Entity
//PerfSampleInfo encoded in the following CSV format: [interval1], [date1], [interval2], [date2], and so on.
metricsCsv.SampleInfoCSV = sampleInfoCSV(metrics)
metricsCsv.Value = make([]types.PerfMetricSeriesCSV, len(qs.MetricId))
for j, mid := range qs.MetricId {
seriesCsv := &types.PerfMetricSeriesCSV{Value: ""}
seriesCsv.Id = mid
seriesCsv.Value = valueCSV(series[j])
metricsCsv.Value[j] = *seriesCsv
}
body.Res.Returnval[i] = metricsCsv
} else {
body.Res.Returnval[i] = metrics
}
body.Res.Returnval[i] = metrics
}
return body
}
// sampleInfoCSV converts the SampleInfo field to a CSV string
func sampleInfoCSV(m *types.PerfEntityMetric) string {
values := make([]string, len(m.SampleInfo)*2)
i := 0
for _, s := range m.SampleInfo {
values[i] = strconv.Itoa(int(s.Interval))
i++
values[i] = s.Timestamp.Format(time.RFC3339)
i++
}
return strings.Join(values, ",")
}
// valueCSV converts the Value field to a CSV string
func valueCSV(s *types.PerfMetricIntSeries) string {
values := make([]string, len(s.Value))
for i := range s.Value {
values[i] = strconv.FormatInt(s.Value[i], 10)
}
return strings.Join(values, ",")
}

View File

@ -53,6 +53,14 @@ func (s *SearchIndex) FindByDatastorePath(r *types.FindByDatastorePath) soap.Has
func (s *SearchIndex) FindByInventoryPath(req *types.FindByInventoryPath) soap.HasFault {
body := &methods.FindByInventoryPathBody{Res: new(types.FindByInventoryPathResponse)}
root := Map.content().RootFolder
o := &root
if req.InventoryPath == "/" {
body.Res.Returnval = o
return body
}
split := func(c rune) bool {
return c == '/'
}
@ -61,9 +69,6 @@ func (s *SearchIndex) FindByInventoryPath(req *types.FindByInventoryPath) soap.H
return body
}
root := Map.content().RootFolder
o := &root
for _, name := range path {
f := s.FindChild(&types.FindChild{Entity: *o, Name: name})

View File

@ -1,11 +1,11 @@
/*
Copyright (c) 2017-2018 VMware, Inc. All Rights Reserved.
Copyright (c) 2017-2023 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
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,
@ -20,6 +20,7 @@ import (
"context"
"fmt"
"net/http"
"net/url"
"os"
"reflect"
"strings"
@ -41,6 +42,7 @@ type SessionManager struct {
ServiceHostName string
TLSCert func() string
ValidLogin func(*types.Login) bool
sessions map[string]Session
}
@ -106,22 +108,23 @@ func (m *SessionManager) putSession(s Session) {
m.sessions[s.Key] = s
}
func (s *SessionManager) validLogin(ctx *Context, req *types.Login) bool {
if ctx.Session != nil {
return false
}
user := ctx.svc.Listen.User
if user == nil || user == DefaultLogin {
func (s *SessionManager) Authenticate(u url.URL, req *types.Login) bool {
if u.User == nil || u.User == DefaultLogin {
return req.UserName != "" && req.Password != ""
}
pass, _ := user.Password()
return req.UserName == user.Username() && req.Password == pass
if s.ValidLogin != nil {
return s.ValidLogin(req)
}
pass, _ := u.User.Password()
return req.UserName == u.User.Username() && req.Password == pass
}
func (s *SessionManager) Login(ctx *Context, req *types.Login) soap.HasFault {
body := new(methods.LoginBody)
if s.validLogin(ctx, req) {
if ctx.Session == nil && s.Authenticate(*ctx.svc.Listen, req) {
body.Res = &types.LoginResponse{
Returnval: createSession(ctx, req.UserName, req.Locale),
}

View File

@ -1,5 +1,5 @@
/*
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
Copyright (c) 2017-2023 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.
@ -154,6 +154,8 @@ func walk(root mo.Reference, f func(child types.ManagedObjectReference)) {
children = []types.ManagedObjectReference{e.VmFolder, e.HostFolder, e.DatastoreFolder, e.NetworkFolder}
case *mo.Folder:
children = e.ChildEntity
case *mo.StoragePod:
children = e.ChildEntity
case *mo.ComputeResource:
children = e.Host
children = append(children, *e.ResourcePool)

View File

@ -1,11 +1,11 @@
/*
Copyright (c) 2018-2022 VMware, Inc. All Rights Reserved.
Copyright (c) 2018-2023 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
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,
@ -88,6 +88,7 @@ type download struct {
type handler struct {
sync.Mutex
sm *simulator.SessionManager
ServeMux *http.ServeMux
URL url.URL
Category map[string]*tags.Category
@ -104,7 +105,7 @@ type handler struct {
func init() {
simulator.RegisterEndpoint(func(s *simulator.Service, r *simulator.Registry) {
if r.IsVPX() {
patterns, h := New(s.Listen, r.OptionManager().Setting)
patterns, h := New(s.Listen, r)
for _, p := range patterns {
s.Handle(p, h)
}
@ -113,8 +114,9 @@ func init() {
}
// New creates a vAPI simulator.
func New(u *url.URL, settings []vim.BaseOptionValue) ([]string, http.Handler) {
func New(u *url.URL, r *simulator.Registry) ([]string, http.Handler) {
s := &handler{
sm: r.SessionManager(),
ServeMux: http.NewServeMux(),
URL: *u,
Category: make(map[string]*tags.Category),
@ -237,10 +239,7 @@ func (s *handler) isAuthorized(r *http.Request) bool {
func (s *handler) hasAuthorization(r *http.Request) (string, bool) {
u, p, ok := r.BasicAuth()
if ok { // user+pass auth
if u == "" || p == "" {
return u, false
}
return u, true
return u, s.sm.Authenticate(s.URL, &vim.Login{UserName: u, Password: p})
}
auth := r.Header.Get("Authorization")
return "TODO", strings.HasPrefix(auth, "SIGN ") // token auth

View File

@ -369,24 +369,10 @@ func (c *Client) dialTLSContext(
return conn, nil
}
switch err.(type) {
case x509.UnknownAuthorityError:
case x509.HostnameError:
default:
// Allow a thumbprint verification attempt if the error indicates
// the failure was due to lack of trust.
//
// Please note the err variable is not a special type of x509 or HTTP
// error that can be validated by a type assertion. The err variable is
// in fact an *errors.errorString.
switch {
case strings.HasSuffix(err.Error(), "certificate is not trusted"):
// darwin and linux
case strings.HasSuffix(err.Error(), "certificate signed by unknown authority"):
// windows
default:
return nil, err
}
// Allow a thumbprint verification attempt if the error indicates
// the failure was due to lack of trust.
if !IsCertificateUntrusted(err) {
return nil, err
}
thumbprint := c.Thumbprint(addr)
@ -411,10 +397,6 @@ func (c *Client) dialTLSContext(
return conn, nil
}
func (c *Client) dialTLS(network, addr string) (net.Conn, error) {
return c.dialTLSContext(context.Background(), network, addr)
}
// splitHostPort is similar to net.SplitHostPort,
// but rather than return error if there isn't a ':port',
// return an empty string for the port.

View File

@ -17,9 +17,12 @@ limitations under the License.
package soap
import (
"crypto/x509"
"encoding/json"
"errors"
"fmt"
"reflect"
"strings"
"github.com/vmware/govmomi/vim25/types"
)
@ -127,3 +130,37 @@ func IsVimFault(err error) bool {
func ToVimFault(err error) types.BaseMethodFault {
return err.(vimFaultError).fault
}
func IsCertificateUntrusted(err error) bool {
// golang 1.20 introduce a new type to wrap 509 errors. So instead of
// casting the type, now we check the error chain contains the
// x509 error or not.
x509UnknownAuthorityErr := &x509.UnknownAuthorityError{}
ok := errors.As(err, x509UnknownAuthorityErr)
if ok {
return true
}
x509HostNameErr := &x509.HostnameError{}
ok = errors.As(err, x509HostNameErr)
if ok {
return true
}
// The err variable may not be a special type of x509 or HTTP
// error that can be validated by a type assertion. The err variable is
// in fact be an *errors.errorString.
msgs := []string{
"certificate is not trusted",
"certificate signed by unknown authority",
}
for _, msg := range msgs {
if strings.HasSuffix(err.Error(), msg) {
return true
}
}
return false
}

4
vendor/modules.txt vendored
View File

@ -678,8 +678,8 @@ github.com/vishvananda/netlink/nl
# github.com/vishvananda/netns v0.0.4
## explicit; go 1.17
github.com/vishvananda/netns
# github.com/vmware/govmomi v0.30.0
## explicit; go 1.17
# github.com/vmware/govmomi v0.30.6
## explicit; go 1.19
github.com/vmware/govmomi
github.com/vmware/govmomi/find
github.com/vmware/govmomi/history