check vcenter url for /sdk
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-05-23 12:22:20 +10:00
parent b5e92a5ff2
commit b5d10d535e

12
main.go
View File

@@ -6,6 +6,7 @@ import (
"fmt"
"net/url"
"os"
"strings"
"time"
"github.com/vmware/govmomi"
@@ -21,6 +22,8 @@ var (
ctx context.Context
cancel context.CancelFunc
location *time.Location
sha1ver string // sha1 revision used to build the program
buildTime string // when the executable was built
)
func getEvents(eventTypes []string, entities []types.ManagedObjectReference, begin time.Duration, end time.Duration) []types.Event {
@@ -102,13 +105,20 @@ func main() {
// So we can convert vCenter UTC to our local timezone
location, _ = time.LoadLocation(*vTZ)
fmt.Printf("Starting execution. Built on %s from sha1 %s\n", buildTime, sha1ver)
u, err := url.Parse(*vURL)
if err != nil {
fmt.Fprintf(os.Stderr, "Error parsing url %s : %s\n", *vURL, err)
os.Exit(1)
} else {
if !strings.HasSuffix(u.Path, "/sdk") {
u.Path, _ = url.JoinPath(u.Path, "/sdk")
fmt.Printf("Updated vCenter URL to '%v'\n", u)
}
}
//fmt.Printf("Connecting to vCenter %s\n", u)
fmt.Printf("Connecting to vCenter %s\n", u)
u.User = url.UserPassword(*vUser, *vPass)
ctx, cancel = context.WithCancel(context.Background())