Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination dest, R
throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException,
ResourceUnavailableException;

/**
* Re-reserves the Allocated nics of a VM that is Running, e.g. after its nics were released on a power report
* that was later reverted, and restores the active nics count of their networks.
*/
void reconcileNicsForRunningVm(VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context);

/**
* Removes the provided nic from the given vm
* @param vm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5432,6 +5432,7 @@ private void handlePowerOnReportWithNoPendingJobsOnVM(final VMInstanceVO vm) {
ActionEventUtils.onActionEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, vm.getDomainId(),
EventTypes.EVENT_VM_START, "Out of band VM power on", vm.getId(), getApiCommandResourceTypeForVm(vm).toString());
logger.info("VM {} is sync-ed to at Running state according to power-on report from hypervisor.", vm.getInstanceName());
reconcileNicsForRunningVm(vm);
break;

case Destroyed:
Expand All @@ -5456,6 +5457,20 @@ private void handlePowerOnReportWithNoPendingJobsOnVM(final VMInstanceVO vm) {
}
}

private void reconcileNicsForRunningVm(final VMInstanceVO vm) {
final VMInstanceVO runningVm = _vmDao.findById(vm.getId());
if (runningVm == null || runningVm.getType() != VirtualMachine.Type.User || runningVm.getState() != State.Running || runningVm.getHostId() == null

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the issue impact DomainRouter ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't because if it's not userVM we return.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the VR should not impact the network garbage collector.
is it possble that VR nic is also released when it is reported as Stopped unexpectedly ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh misinterpreted your statement earlier - I thought you meant does the fix impact VRs - my bad 🤦
That said, I dont think VR was VR is impacted by the issue, and even if it did, we never really took into account VRs nic count, so this fix should only be limited to userVMs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's true indeed

|| _nicsDao.listByVmId(runningVm.getId()).stream().noneMatch(nic -> nic.getState() == Nic.State.Allocated)) {
return;
}
final Host host = _hostDao.findById(runningVm.getHostId());
final DataCenter dc = _entityMgr.findById(DataCenter.class, runningVm.getDataCenterId());
final User user = _entityMgr.findById(User.class, User.UID_SYSTEM);
final Account account = _entityMgr.findById(Account.class, Account.ACCOUNT_ID_SYSTEM);
final ReservationContext context = new ReservationContextImpl(null, null, user, account);
_networkMgr.reconcileNicsForRunningVm(new VirtualMachineProfileImpl(runningVm), new DeployDestination(dc, null, null, host), context);
}

private void handlePowerOffReportWithNoPendingJobsOnVM(final VMInstanceVO vm) {
switch (vm.getState()) {
case Starting:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2187,6 +2187,26 @@ public int compare(final NicVO nic1, final NicVO nic2) {
}
}

@Override
public void reconcileNicsForRunningVm(final VirtualMachineProfile vmProfile, final DeployDestination dest, final ReservationContext context) {
for (final NicVO nic : _nicDao.listByVmId(vmProfile.getId())) {
if (nic.getState() != Nic.State.Allocated) {
continue;
}
try {
final Pair<NetworkGuru, NetworkVO> implemented = implementNetwork(nic.getNetworkId(), dest, context);
if (implemented == null || implemented.first() == null) {
logger.warn("Unable to implement Network ID={} to reconcile NIC {} of Running Instance {}", nic.getNetworkId(), nic, vmProfile);
continue;
}
prepareNic(vmProfile, dest, context, nic.getId(), implemented.second());
logger.info("Re-reserved NIC {} of Running Instance {}", nic, vmProfile);
} catch (final Exception e) {
logger.warn("Failed to reconcile NIC {} of Running Instance {}", nic, vmProfile, e);
}
}
}

@Override
public NicProfile prepareNic(final VirtualMachineProfile vmProfile, final DeployDestination dest, final ReservationContext context, final long nicId, final Network network)
throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,10 @@ public Pair<NicProfile, Integer> allocateNic(NicProfile requested, Network netwo
return null;
}

@Override
public void reconcileNicsForRunningVm(VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context) {
}

@Override
public NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context, long nicId, Network network)
throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException,
Expand Down
Loading