[Vmware] Add missing condition to cleanup nics if there are commands to send (#5449)

* [Vmware] Add missing condition to cleanup nics if there are commands to send
This commit is contained in:
Nicolas Vazquez 2021-09-17 13:24:52 -03:00 committed by GitHub
parent 939ef4ec4b
commit 8228ecee43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -636,19 +636,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
// send hypervisor-dependent commands before removing
final List<Command> finalizeExpungeCommands = hvGuru.finalizeExpunge(vm);
if (finalizeExpungeCommands != null && finalizeExpungeCommands.size() > 0) {
if (CollectionUtils.isNotEmpty(finalizeExpungeCommands) || CollectionUtils.isNotEmpty(nicExpungeCommands)) {
if (hostId != null) {
final Commands cmds = new Commands(Command.OnError.Stop);
for (final Command command : finalizeExpungeCommands) {
command.setBypassHostMaintenance(expungeCommandCanBypassHostMaintenance(vm));
cmds.addCommand(command);
}
if (nicExpungeCommands != null) {
for (final Command command : nicExpungeCommands) {
command.setBypassHostMaintenance(expungeCommandCanBypassHostMaintenance(vm));
cmds.addCommand(command);
}
}
addAllExpungeCommandsFromList(finalizeExpungeCommands, cmds, vm);
addAllExpungeCommandsFromList(nicExpungeCommands, cmds, vm);
_agentMgr.send(hostId, cmds);
if (!cmds.isSuccessful()) {
for (final Answer answer : cmds.getAnswers()) {
@ -667,6 +659,19 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
private void addAllExpungeCommandsFromList(List<Command> cmdList, Commands cmds, VMInstanceVO vm) {
if (CollectionUtils.isEmpty(cmdList)) {
return;
}
for (final Command command : cmdList) {
command.setBypassHostMaintenance(expungeCommandCanBypassHostMaintenance(vm));
if (s_logger.isTraceEnabled()) {
s_logger.trace(String.format("Adding expunge command [%s] for VM [%s]", command.toString(), vm.toString()));
}
cmds.addCommand(command);
}
}
private List<Map<String, String>> getTargets(Long hostId, long vmId) {
List<Map<String, String>> targets = new ArrayList<>();