harikrishna-patnala commented on code in PR #7239:
URL: https://github.com/apache/cloudstack/pull/7239#discussion_r1247364501
##########
plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/guru/VMwareGuru.java:
##########
@@ -661,30 +660,29 @@ private Long getImportingVMTemplate(List<VirtualDisk>
virtualDisks, DatacenterMO
* If VM exists: update VM
*/
private VMInstanceVO getVM(String vmInternalName, long templateId, long
guestOsId, long serviceOfferingId, long zoneId, long accountId, long userId,
long domainId) {
- s_logger.debug(String.format("Trying to get VM with specs:
[vmInternalName: %s, templateId: %s, guestOsId: %s, serviceOfferingId: %s].",
vmInternalName,
- templateId, guestOsId, serviceOfferingId));
- VMInstanceVO vm =
virtualMachineDao.findVMByInstanceNameIncludingRemoved(vmInternalName);
- if (vm != null) {
- s_logger.debug(String.format("Found an existing VM [id: %s,
removed: %s] with internalName: [%s].", vm.getUuid(), vm.getRemoved() != null ?
"yes" : "no", vmInternalName));
- vm.setState(VirtualMachine.State.Stopped);
- vm.setPowerState(VirtualMachine.PowerState.PowerOff);
- virtualMachineDao.update(vm.getId(), vm);
- if (vm.getRemoved() != null) {
- virtualMachineDao.unremove(vm.getId());
- UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE,
accountId, vm.getDataCenterId(), vm.getId(), vm.getHostName(),
vm.getServiceOfferingId(), vm.getTemplateId(),
- vm.getHypervisorType().toString(),
VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplayVm());
- }
- return virtualMachineDao.findById(vm.getId());
- } else {
+ s_logger.debug(String.format("Trying to get VM with specs:
[vmInternalName: %s], and in states [%s, %s].", vmInternalName,
VirtualMachine.State.Running, VirtualMachine.State.Stopped));
+ VMInstanceVO vm =
virtualMachineDao.findVMInStatesAndWithInternalNameIncludingRemoved(vmInternalName,
VirtualMachine.State.Running, VirtualMachine.State.Stopped);
Review Comment:
@SadiJr can you please help me understand how this solved the problem of
duplicate entries with the same VM name? Previously also we are looking for any
VMs with that name (including removed) and then reusing that removed entry.
Here in this fix, findVMInStatesAndWithInternalNameIncludingRemoved() method
is fetching only VMs with states Running and Stopped. There won't be any VM
entries that are removed with Running and Stopped states unless they are marked
as removed in the DB manually. This means we are ignoring the actually removed
entries.
Please correct me if I'm wrong here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]