mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-21 01:59:07 +00:00
Merge pull request #2853 from thebsdbox/vmware_host_fix
Added capability to find a host if -hostname isn't specified
This commit is contained in:
commit
47bba67fe4
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
@ -208,11 +209,22 @@ func vCenterConnect(ctx context.Context, newVM vmConfig) (*govmomi.Client, *obje
|
||||
}
|
||||
}
|
||||
|
||||
// Set the host that the VM will be created on
|
||||
hs, err := f.HostSystemOrDefault(ctx, *newVM.vSphereHost)
|
||||
// Check to see if a host has been specified
|
||||
var hs *object.HostSystem
|
||||
if *newVM.vSphereHost != "" {
|
||||
// Find the selected host
|
||||
hs, err = f.HostSystem(ctx, *newVM.vSphereHost)
|
||||
if err != nil {
|
||||
log.Fatalf("vSphere host [%s], could not be found", *newVM.vSphereHost)
|
||||
}
|
||||
} else {
|
||||
allHosts, err := f.HostSystemList(ctx, "*/*")
|
||||
if err != nil || len(allHosts) == 0 {
|
||||
log.Fatalf("No vSphere hosts could be found on vCenter server")
|
||||
}
|
||||
// Select a host from the list off all available hosts at random
|
||||
hs = allHosts[rand.Int()%len(allHosts)]
|
||||
}
|
||||
|
||||
var rp *object.ResourcePool
|
||||
rp, err = hs.ResourcePool(ctx)
|
||||
|
Loading…
Reference in New Issue
Block a user