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

20
main.go
View File

@@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"net/url" "net/url"
"os" "os"
"strings"
"time" "time"
"github.com/vmware/govmomi" "github.com/vmware/govmomi"
@@ -17,10 +18,12 @@ import (
) )
var ( var (
c *govmomi.Client c *govmomi.Client
ctx context.Context ctx context.Context
cancel context.CancelFunc cancel context.CancelFunc
location *time.Location 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 { 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 // So we can convert vCenter UTC to our local timezone
location, _ = time.LoadLocation(*vTZ) location, _ = time.LoadLocation(*vTZ)
fmt.Printf("Starting execution. Built on %s from sha1 %s\n", buildTime, sha1ver)
u, err := url.Parse(*vURL) u, err := url.Parse(*vURL)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error parsing url %s : %s\n", *vURL, err) fmt.Fprintf(os.Stderr, "Error parsing url %s : %s\n", *vURL, err)
os.Exit(1) 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) u.User = url.UserPassword(*vUser, *vPass)
ctx, cancel = context.WithCancel(context.Background()) ctx, cancel = context.WithCancel(context.Background())