This commit is contained in:
@@ -436,7 +436,12 @@ SELECT
|
||||
COALESCE(agg.any_creation, agg.first_present, 0) AS "CreationTime",
|
||||
CASE
|
||||
WHEN NULLIF(agg.inv_deletion, 0) IS NOT NULL THEN NULLIF(agg.inv_deletion, 0)
|
||||
WHEN totals.max_snapshot IS NOT NULL AND agg.last_present < totals.max_snapshot THEN COALESCE(NULLIF(agg.any_deletion, 0), totals.max_snapshot, agg.last_present)
|
||||
WHEN totals.max_snapshot IS NOT NULL AND agg.last_present < totals.max_snapshot THEN COALESCE(
|
||||
NULLIF(agg.any_deletion, 0),
|
||||
(SELECT MIN(s2."SnapshotTime") FROM snapshots s2 WHERE s2."SnapshotTime" > agg.last_present),
|
||||
totals.max_snapshot,
|
||||
agg.last_present
|
||||
)
|
||||
ELSE NULLIF(agg.any_deletion, 0)
|
||||
END AS "DeletionTime",
|
||||
(
|
||||
|
||||
@@ -404,10 +404,14 @@ func (v *Vcenter) GetClusterFromHost(hostRef *types.ManagedObjectReference) (str
|
||||
v.Logger.Error("cant get host", "error", err)
|
||||
return "", err
|
||||
}
|
||||
if host == nil {
|
||||
v.Logger.Warn("host lookup returned nil", "host_ref", hostRef)
|
||||
return "", nil
|
||||
}
|
||||
|
||||
v.Logger.Debug("host parent", "parent", host.Parent)
|
||||
|
||||
if host.Parent.Type == "ClusterComputeResource" {
|
||||
if host.Parent != nil && host.Parent.Type == "ClusterComputeResource" {
|
||||
// Retrieve properties of the compute resource
|
||||
var moCompute mo.ComputeResource
|
||||
err = v.client.RetrieveOne(v.ctx, *host.Parent, nil, &moCompute)
|
||||
@@ -651,7 +655,7 @@ func (v *Vcenter) GetVMFolderPath(vm mo.VirtualMachine) (string, error) {
|
||||
folderPath := ""
|
||||
//v.Logger.Debug("parent is", "parent", parentRef)
|
||||
|
||||
for parentRef.Type != "Datacenter" {
|
||||
for parentRef != nil && parentRef.Type != "Datacenter" {
|
||||
// Retrieve the parent object
|
||||
//parentObj, err := finder.ObjectReference(v.ctx, *parentRef)
|
||||
//if err != nil {
|
||||
@@ -681,5 +685,9 @@ func (v *Vcenter) GetVMFolderPath(vm mo.VirtualMachine) (string, error) {
|
||||
//break
|
||||
}
|
||||
|
||||
if parentRef == nil {
|
||||
return "", fmt.Errorf("folder traversal terminated early for VM %s", vm.Name)
|
||||
}
|
||||
|
||||
return folderPath, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user