diff --git a/main.go b/main.go index 1aa1931..75d8f98 100644 --- a/main.go +++ b/main.go @@ -16,14 +16,17 @@ import ( "github.com/vmware/govmomi" "github.com/vmware/govmomi/find" "github.com/vmware/govmomi/view" + "github.com/vmware/govmomi/vim25/methods" "github.com/vmware/govmomi/vim25/mo" + "github.com/vmware/govmomi/vim25/types" ) type HostTimeErrors struct { - HostName string - HostTime time.Time - Cluster string - Vcenter string + HostName string + HostTime time.Time + HostTimeDrift string + Cluster string + Vcenter string } var ( @@ -189,6 +192,30 @@ func main() { continue } + // test triggering update + // Call RefreshDateTimeSystem method using methods.RefreshDateTimeSystem + refreshReq := &types.RefreshDateTimeSystem{ + This: dts.Reference(), + } + _, err = methods.RefreshDateTimeSystem(ctx, c.Client, refreshReq) + if err != nil { + log.Printf("Failed to refresh datetime system for host %s: %v", hs.Name, err) + } else { + //prettyPrint(refreshResp) + } + + /* + // Call UpdateDateTime method using methods.UpdateDateTime - this will manually set the ESXi clock + updateReq := &types.UpdateDateTime{ + This: dts.Reference(), + DateTime: time.Now().UTC(), + } + _, err = methods.UpdateDateTime(ctx, c.Client, updateReq) + if err != nil { + log.Fatal(err) + } + */ + // Get the current ESXi time which is UTC hostTime, err := dts.Query(ctx) @@ -212,10 +239,11 @@ func main() { } thisResult := HostTimeErrors{ - HostName: hs.Name, - Cluster: clusterName, - Vcenter: u.Host, - HostTime: esxiTimeLocal, + HostName: hs.Name, + Cluster: clusterName, + Vcenter: u.Host, + HostTime: esxiTimeLocal, + HostTimeDrift: diff.String(), } hostTimeErrors = append(hostTimeErrors, thisResult)