diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index f4e83ac4c38..fb39c0a2998 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -4461,16 +4461,23 @@ VirtualMachineGuru, Listener, Configurable, StateListener if (opaque != null && opaque instanceof Pair) { Pair pair = (Pair)opaque; Object first = pair.first(); Object second = pair.second(); - if (first != null && second != null && first instanceof Long && second instanceof Long) { - Long hostId = (Long)first; + // powerHostId cannot be null in case of out-of-band VM movement + if (second != null && second instanceof Long) { Long powerHostId = (Long)second; - // If VM host known to CS is different from 'PowerOn' report host, then it is out-of-band movement - if (hostId.longValue() != powerHostId.longValue()) { - s_logger.info("Schedule a router reboot task as router " + vo.getId() + " is powered-on out-of-band. we need to reboot to refresh network rules"); + Long hostId = null; + if (first != null && first instanceof Long) { + hostId = (Long)first; + } + // The following scenarios are due to out-of-band VM movement + // 1. If VM is in stopped state in CS due to 'PowerMissing' report from old host (hostId is null) and then there is a 'PowerOn' report from new host + // 2. If VM is in running state in CS and there is a 'PowerOn' report from new host + if (hostId == null || (hostId.longValue() != powerHostId.longValue())) { + s_logger.info("Schedule a router reboot task as router " + vo.getId() + " is powered-on out-of-band, need to reboot to refresh network rules"); _executor.schedule(new RebootTask(vo.getId()), 1000, TimeUnit.MICROSECONDS); } }