func (vs *VSphere) IsVMPresent(vmName string, dataCenterRef types.ManagedObjectReference) (isVMPresent bool, err error) {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	Connect(ctx, vs)
	folderMor, err := vs.GetFolderByPath(ctx, dataCenterRef, vs.Config.Folder)
	if err != nil {
		return
	}
	vmFolder := object.NewFolder(vs.Client.Client, folderMor)
	vmFoldersChildren, err := vmFolder.Children(ctx)
	if err != nil {
		framework.Logf("Failed to get children from Folder: %s. err: %+v", vmFolder.InventoryPath, err)
		return
	}
	for _, vmFoldersChild := range vmFoldersChildren {
		if vmFoldersChild.Reference().Type == virtualMachineType {
			if object.NewVirtualMachine(vs.Client.Client, vmFoldersChild.Reference()).Name() == vmName {
				return true, nil
			}
		}
	}
	return
}
// IsVMPresent checks if VM with the name specified in the vmName argument, is present in the vCenter inventory.
// if VM is present, function returns true else false.
IsVMPresent checks if VM with the name specified in the vmName argument, is present in the vCenter inventory.
if VM is present, function returns true else false.
// IsVMPresent checks if VM with the name specified in the vmName argument is present in the vCenter inventory . // if VM is present function returns true else false .
func (vs *VSphere) IsVMPresent(vmName string, dataCenterRef types.ManagedObjectReference) (isVMPresent bool, err error) {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	Connect(ctx, vs)
	folderMor, err := vs.GetFolderByPath(ctx, dataCenterRef, vs.Config.Folder)
	if err != nil {
		return
	}
	vmFolder := object.NewFolder(vs.Client.Client, folderMor)
	vmFoldersChildren, err := vmFolder.Children(ctx)
	if err != nil {
		framework.Logf("Failed to get children from Folder: %s. err: %+v", vmFolder.InventoryPath, err)
		return
	}
	for _, vmFoldersChild := range vmFoldersChildren {
		if vmFoldersChild.Reference().Type == virtualMachineType {
			if object.NewVirtualMachine(vs.Client.Client, vmFoldersChild.Reference()).Name() == vmName {
				return true, nil
			}
		}
	}
	return
}
func ( vs * VSphere ) IsVMPresent ( vmName string , dataCenterRef types . ManagedObjectReference ) ( isVMPresent bool , err error ) { ctx , cancel := context . WithCancel ( context . Background ( ) ) defer cancel ( ) Connect ( ctx , vs ) folderMor , err := vs . GetFolderByPath ( ctx , dataCenterRef , vs . Config . Folder ) if err != nil { return } vmFolder := object . NewFolder ( vs . Client . Client , folderMor ) vmFoldersChildren , err := vmFolder . Children ( ctx ) if err != nil { framework . Logf ( " " , vmFolder . InventoryPath , err ) return } for _ , vmFoldersChild := range vmFoldersChildren { if vmFoldersChild . Reference ( ) . Type == virtualMachineType { if object . NewVirtualMachine ( vs . Client . Client , vmFoldersChild . Reference ( ) ) . Name ( ) == vmName { return true , nil } } } return }
IsVMPresent checks if VM with the name specified in the vmName argument, is present in the vCenter inventory.
IsVMPresent checks if VM with the name specified in the vmName argument is present in the vCenter inventory .