dont query vm folder path unless we need to
This commit is contained in:
@@ -27,8 +27,6 @@ type Vcenter struct {
|
||||
type VmProperties struct {
|
||||
Vm mo.VirtualMachine
|
||||
ResourcePool string
|
||||
FolderPath string
|
||||
//Datacenter string
|
||||
}
|
||||
|
||||
// New creates a new Vcenter with the given logger
|
||||
@@ -181,7 +179,6 @@ func (v *Vcenter) FindVMByIDWithDatacenter(vmID string, dcID string) (*VmPropert
|
||||
//var dcName string
|
||||
var err error
|
||||
resourcePool := ""
|
||||
vmFolderPath := ""
|
||||
v.Logger.Debug("searching for vm id", "vm_id", vmID, "datacenter_id", dcID)
|
||||
|
||||
finder := find.NewFinder(v.client.Client, true)
|
||||
@@ -226,20 +223,10 @@ func (v *Vcenter) FindVMByIDWithDatacenter(vmID string, dcID string) (*VmPropert
|
||||
|
||||
}
|
||||
|
||||
// Retrieve the full folder path of the VM
|
||||
folderPath, err := v.getVMFolderPath(vm)
|
||||
if err != nil {
|
||||
v.Logger.Error("failed to get vm folder path", "error", err)
|
||||
} else {
|
||||
v.Logger.Debug("Found vm folder path", "folder_path", folderPath)
|
||||
vmFolderPath = folderPath
|
||||
}
|
||||
|
||||
return &VmProperties{
|
||||
//Datacenter: dcName,
|
||||
Vm: vm,
|
||||
ResourcePool: resourcePool,
|
||||
FolderPath: vmFolderPath,
|
||||
}, nil
|
||||
} else if _, ok := err.(*find.NotFoundError); !ok {
|
||||
// If the error is not a NotFoundError, return it
|
||||
@@ -255,7 +242,7 @@ func (v *Vcenter) FindVMByIDWithDatacenter(vmID string, dcID string) (*VmPropert
|
||||
}
|
||||
|
||||
// Helper function to retrieve the full folder path for the VM
|
||||
func (v *Vcenter) getVMFolderPath(vm mo.VirtualMachine) (string, error) {
|
||||
func (v *Vcenter) GetVMFolderPath(vm mo.VirtualMachine) (string, error) {
|
||||
//finder := find.NewFinder(v.client.Client, true)
|
||||
|
||||
v.Logger.Debug("Commencing vm folder path search")
|
||||
|
Reference in New Issue
Block a user