diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java index 5cff679d17eb..f07b03f6cccc 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java @@ -52,6 +52,7 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA static final String RouterTemplateLxcCK = "router.template.lxc"; static final String SetServiceMonitorCK = "network.router.EnableServiceMonitoring"; static final String RouterAlertsCheckIntervalCK = "router.alerts.check.interval"; + static final String RouterReprovisionOnOutOfBandMigrationCK = "router.reboot.when.migrated"; static final ConfigKey RouterTemplateXen = new ConfigKey(String.class, RouterTemplateXenCK, "Advanced", "SystemVM Template (XenServer)", "Name of the default router template on Xenserver.", true, ConfigKey.Scope.Zone, null); @@ -63,12 +64,16 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA "Name of the default router template on Hyperv.", true, ConfigKey.Scope.Zone, null); static final ConfigKey RouterTemplateLxc = new ConfigKey(String.class, RouterTemplateLxcCK, "Advanced", "SystemVM Template (LXC)", "Name of the default router template on LXC.", true, ConfigKey.Scope.Zone, null); - static final ConfigKey SetServiceMonitor = new ConfigKey(String.class, SetServiceMonitorCK, "Advanced", "true", "service monitoring in router enable/disable option, default true", true, ConfigKey.Scope.Zone, null); - static final ConfigKey RouterAlertsCheckInterval = new ConfigKey(Integer.class, RouterAlertsCheckIntervalCK, "Advanced", "1800", "Interval (in seconds) to check for alerts in Virtual Router.", false, ConfigKey.Scope.Global, null); + static final ConfigKey routerVersionCheckEnabled = new ConfigKey("Advanced", Boolean.class, "router.version.check", "true", + "If true, router minimum required version is checked before sending command", false); + static final ConfigKey UseExternalDnsServers = new ConfigKey(Boolean.class, "use.external.dns", "Advanced", "false", + "Bypass internal dns, use external dns1 and dns2", true, ConfigKey.Scope.Zone, null); + static final ConfigKey RouterReprovisionOnOutOfBandMigration = new ConfigKey(Boolean.class, RouterReprovisionOnOutOfBandMigrationCK, "Advanced", "false", + "Reboot routers when they are migrated out of band in order to reprovision", true, ConfigKey.Scope.Zone, null); public static final int DEFAULT_ROUTER_VM_RAMSIZE = 256; // 256M public static final int DEFAULT_ROUTER_CPU_MHZ = 500; // 500 MHz diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 59bd4c641814..4400a6284795 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -673,13 +673,6 @@ public VirtualRouter rebootRouter(final long routerId, final boolean reprogramNe } } - static final ConfigKey UseExternalDnsServers = new ConfigKey(Boolean.class, "use.external.dns", "Advanced", "false", - "Bypass internal dns, use external dns1 and dns2", true, ConfigKey.Scope.Zone, null); - - static final ConfigKey routerVersionCheckEnabled = new ConfigKey("Advanced", Boolean.class, "router.version.check", "true", - "If true, router minimum required version is checked before sending command", false); - - @Override public boolean configure(final String name, final Map params) throws ConfigurationException { @@ -4394,7 +4387,7 @@ public String getConfigComponentName() { @Override public ConfigKey[] getConfigKeys() { - return new ConfigKey[] {UseExternalDnsServers, routerVersionCheckEnabled, SetServiceMonitor, RouterAlertsCheckInterval}; + return new ConfigKey[] {UseExternalDnsServers, routerVersionCheckEnabled, SetServiceMonitor, RouterAlertsCheckInterval, RouterReprovisionOnOutOfBandMigration}; } @Override @@ -4404,25 +4397,34 @@ public boolean preStateTransitionEvent(State oldState, VirtualMachine.Event even @Override public boolean postStateTransitionEvent(State oldState, VirtualMachine.Event event, State newState, VirtualMachine vo, boolean status, Object opaque) { - if (event == VirtualMachine.Event.FollowAgentPowerOnReport && newState == State.Running) { - if (vo.getType() == VirtualMachine.Type.DomainRouter) { - 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; - 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"); - _executor.schedule(new RebootTask(vo.getId()), 1000, TimeUnit.MICROSECONDS); - } - } + // if (vm is a router) and ((vm was stopped before) or (reprovision on out of band migration is true)) and (vm is running) + boolean reprovision_out_of_band = RouterReprovisionOnOutOfBandMigration.value(); + if ( + (vo.getType() == VirtualMachine.Type.DomainRouter) && + ((oldState == State.Stopped) || (reprovision_out_of_band && isOutOfBandMigrated(opaque))) && + (event == VirtualMachine.Event.FollowAgentPowerOnReport) && + (newState == State.Running)) { + 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"); + _executor.schedule(new RebootTask(vo.getId()), 1000, TimeUnit.MICROSECONDS); + } + return true; + } + + private boolean isOutOfBandMigrated(Object opaque) { + 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; + 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()) { + return true; } } } - return true; + return false; } protected class RebootTask extends ManagedContextRunnable {