vishesh92 commented on code in PR #8371:
URL: https://github.com/apache/cloudstack/pull/8371#discussion_r1437470465
##########
server/src/main/java/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java:
##########
@@ -2798,28 +2766,38 @@ public void finalizeStop(final VirtualMachineProfile
profile, final Answer answe
final VirtualMachine vm = profile.getVirtualMachine();
final DomainRouterVO domR = _routerDao.findById(vm.getId());
processStopOrRebootAnswer(domR, answer);
- final List<? extends Nic> routerNics =
_nicDao.listByVmId(profile.getId());
- for (final Nic nic : routerNics) {
- final Network network =
_networkModel.getNetwork(nic.getNetworkId());
- final DataCenterVO dcVO =
_dcDao.findById(network.getDataCenterId());
-
- if (network.getTrafficType() == TrafficType.Guest &&
nic.getBroadcastUri() != null &&
nic.getBroadcastUri().getScheme().equals("pvlan")) {
- final NicProfile nicProfile = new NicProfile(nic, network,
nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic");
-
- final NetworkTopology networkTopology =
_networkTopologyContext.retrieveNetworkTopology(dcVO);
- try {
- networkTopology.setupDhcpForPvlan(false, domR,
domR.getHostId(), nicProfile);
- } catch (final ResourceUnavailableException e) {
- s_logger.debug("ERROR in finalizeStop: ", e);
- }
- }
+ if
(Boolean.TRUE.equals(RemoveControlIpOnStop.valueIn(profile.getVirtualMachine().getDataCenterId())))
{
+ removeNics(vm, domR);
}
-
}
}
@Override
public void finalizeExpunge(final VirtualMachine vm) {
+ final DomainRouterVO domR = _routerDao.findById(vm.getId());
+ // not sure if it would hurt to do it in any case, but
+ if
(Boolean.FALSE.equals(RemoveControlIpOnStop.valueIn(vm.getDataCenterId()))) {
+ removeNics(vm, domR);
+ }
+ }
+
+ private void removeNics(VirtualMachine vm, DomainRouterVO domR) {
+ final List<? extends Nic> routerNics = _nicDao.listByVmId(vm.getId());
+ for (final Nic nic : routerNics) {
+ final Network network =
_networkModel.getNetwork(nic.getNetworkId());
Review Comment:
This will be making 2 queries in a for loop for network & datacenter. Can we
extract them out of the for loop and get the values in a map. And then use that
map here instead?
--
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]