4141import com .cloud .network .rules .NicPlugInOutRules ;
4242import com .cloud .network .rules .RuleApplier ;
4343import com .cloud .network .rules .RuleApplierWrapper ;
44+ import com .cloud .network .rules .StaticRoutesRules ;
4445import com .cloud .network .rules .UserdataPwdRules ;
4546import com .cloud .network .rules .VpcIpAssociationRules ;
4647import com .cloud .network .vpc .NetworkACLItem ;
@@ -60,10 +61,31 @@ public class AdvancedNetworkTopology extends BasicNetworkTopology {
6061 protected AdvancedNetworkVisitor _advancedVisitor ;
6162
6263 @ Override
63- public boolean applyStaticRoutes (final List <StaticRouteProfile > staticRoutes ,
64- final List <DomainRouterVO > routers ) throws ResourceUnavailableException {
65- // TODO Auto-generated method stub
66- return super .applyStaticRoutes (staticRoutes , routers );
64+ public boolean applyStaticRoutes (final List <StaticRouteProfile > staticRoutes , final List <DomainRouterVO > routers ) throws ResourceUnavailableException {
65+
66+ if (staticRoutes == null || staticRoutes .isEmpty ()) {
67+ s_logger .debug ("No static routes to apply" );
68+ return true ;
69+ }
70+
71+ StaticRoutesRules routesRules = _virtualNetworkApplianceFactory .createStaticRoutesRules (staticRoutes );
72+
73+ boolean result = true ;
74+ for (VirtualRouter router : routers ) {
75+ if (router .getState () == State .Running ) {
76+
77+ result = result && routesRules .accept (_advancedVisitor , router );
78+
79+ } else if (router .getState () == State .Stopped || router .getState () == State .Stopping ) {
80+ s_logger .debug ("Router " + router .getInstanceName () + " is in " + router .getState () + ", so not sending StaticRoute command to the backend" );
81+ } else {
82+ s_logger .warn ("Unable to apply StaticRoute, virtual router is not in the right state " + router .getState ());
83+
84+ throw new ResourceUnavailableException ("Unable to apply StaticRoute on the backend," + " virtual router is not in the right state" , DataCenter .class ,
85+ router .getDataCenterId ());
86+ }
87+ }
88+ return result ;
6789 }
6890
6991 @ Override
0 commit comments