add vm inventory update endpoint
Some checks are pending
CI / Lint (push) Waiting to run
CI / Test (push) Waiting to run
CI / End-to-End (push) Waiting to run
CI / Publish Docker (push) Blocked by required conditions
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-09-30 15:30:38 +10:00
parent 6a41528f41
commit 380707cf23
11 changed files with 254 additions and 23 deletions

View File

@@ -114,16 +114,16 @@ func (c *CronTask) AddVmToInventory(vmObject *mo.VirtualMachine, vc *vcenter.Vce
c.Logger.Debug("found VM")
if vmObject.Name == "DBRaaS_testVMTemplate" {
c.Logger.Debug("Found problematic VM")
//prettyPrint(vmObject)
}
srmPlaceholder = "FALSE" // Default assumption
//prettyPrint(vmObject)
/*
if vmObject.Name == "DBRaaS_testVMTemplate" {
c.Logger.Debug("Found problematic VM")
//prettyPrint(vmObject)
}
*/
// calculate VM properties we want to store
if vmObject.Config != nil {
// Skip any template VMs
if vmObject.Config.Template {
c.Logger.Debug("Not adding templates to inventory")
return nil
@@ -133,6 +133,7 @@ func (c *CronTask) AddVmToInventory(vmObject *mo.VirtualMachine, vc *vcenter.Vce
numRam = vmObject.Config.Hardware.MemoryMB
numVcpus = vmObject.Config.Hardware.NumCPU
srmPlaceholder = "FALSE" // Default assumption
// Calculate creation date
if vmObject.Config.CreateDate.IsZero() {
@@ -156,16 +157,19 @@ func (c *CronTask) AddVmToInventory(vmObject *mo.VirtualMachine, vc *vcenter.Vce
}
totalDiskBytes += disk.CapacityInBytes
//totalDiskGB += float64(disk.CapacityInBytes / 1024 / 1024 / 1024) // Convert from bytes to GB
}
}
totalDiskGB = float64(totalDiskBytes / 1024 / 1024 / 1024)
c.Logger.Debug("Converted total disk size", "bytes", totalDiskBytes, "GB", totalDiskGB)
// Determine if the VM is a normal VM or an SRM placeholder
if vmObject.Config.ManagedBy != nil && vmObject.Config.ManagedBy.Type == "com.vmware.vcDr" {
c.Logger.Debug("VM ManagedBy indicates managed by SRM")
srmPlaceholder = "TRUE"
if vmObject.Config.ManagedBy != nil && vmObject.Config.ManagedBy.ExtensionKey == "com.vmware.vcDr" {
if vmObject.Config.ManagedBy.Type == "placeholderVm" {
c.Logger.Debug("VM is a placeholder")
srmPlaceholder = "TRUE"
} else {
c.Logger.Debug("VM is managed by SRM but not a placeholder", "details", vmObject.Config.ManagedBy)
}
}
// Retrieve the full folder path of the VM
@@ -179,10 +183,10 @@ func (c *CronTask) AddVmToInventory(vmObject *mo.VirtualMachine, vc *vcenter.Vce
foundVmConfig = true
} else {
c.Logger.Error("Empty VM config")
c.Logger.Warn("Empty VM config")
}
c.Logger.Debug("VM has runtime data", "power_state", vmObject.Runtime.PowerState)
//c.Logger.Debug("VM has runtime data", "power_state", vmObject.Runtime.PowerState)
if vmObject.Runtime.PowerState == "poweredOff" {
poweredOn = "FALSE"
} else {
@@ -241,7 +245,6 @@ func (c *CronTask) AddVmToInventory(vmObject *mo.VirtualMachine, vc *vcenter.Vce
}
return nil
}
// prettyPrint comes from https://gist.github.com/sfate/9d45f6c5405dc4c9bf63bf95fe6d1a7c