8787 * }
8888 **/
8989public class VirtualRoutingResource {
90+ protected class VRScripts {
91+ protected static final String S2SVPN_CHECK = "checkbatchs2svpn.sh" ;
92+ protected static final String S2SVPN_IPSEC = "ipsectunnel.sh" ;
93+ protected static final String DHCP = "edithosts.sh" ;
94+ protected static final String DNSMASQ_CONFIG = "dnsmasq.sh" ;
95+ protected static final String FIREWALL_EGRESS = "firewall_egress.sh" ;
96+ protected static final String FIREWALL_INGRESS = "firewall_ingress.sh" ;
97+ protected static final String FIREWALL_NAT = "firewall_nat.sh" ;
98+ protected static final String IPALIAS_CREATE = "createipAlias.sh" ;
99+ protected static final String IPALIAS_DELETE = "deleteipAlias.sh" ;
100+ protected static final String IPASSOC = "ipassoc.sh" ;
101+ protected static final String LB = "loadbalancer.sh" ;
102+ protected static final String MONITOR_SERVICE = "monitor_service.sh" ;
103+ protected static final String PASSWORD = "savepassword.sh" ;
104+ protected static final String RVR_CHECK = "checkrouter.sh" ;
105+ protected static final String RVR_BUMPUP_PRI = "bumpup_priority.sh" ;
106+ protected static final String VMDATA = "vmdata.py" ;
107+ protected static final String VERSION = "get_template_version.sh" ;
108+ protected static final String VPC_ACL = "vpc_acl.sh" ;
109+ protected static final String VPC_GUEST_NETWORK = "vpc_guestnw.sh" ;
110+ protected static final String VPC_IPASSOC = "vpc_ipassoc.sh" ;
111+ protected static final String VPC_LB = "vpc_loadbalancer.sh" ;
112+ protected static final String VPC_PRIVATEGW = "vpc_privateGateway.sh" ;
113+ protected static final String VPC_PRIVATEGW_ACL = "vpc_privategw_acl.sh" ;
114+ protected static final String VPC_PORTFORWARDING = "vpc_portforwarding.sh" ;
115+ protected static final String VPC_SOURCE_NAT = "vpc_snat.sh" ;
116+ protected static final String VPC_STATIC_NAT = "vpc_staticnat.sh" ;
117+ protected static final String VPC_STATIC_ROUTE = "vpc_staticroute.sh" ;
118+ protected static final String VPN_L2TP = "vpn_l2tp.sh" ;
119+ }
120+
90121 private static final Logger s_logger = Logger .getLogger (VirtualRoutingResource .class );
91122 private VirtualRouterDeployer _vrDeployer ;
92123
@@ -190,7 +221,7 @@ private Answer execute(VpnUsersCfgCommand cmd) {
190221 args += "-u " ;
191222 args += userpwd .getUsernamePassword ();
192223 }
193- ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), "vpn_l2tp.sh" , args );
224+ ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), VRScripts . VPN_L2TP , args );
194225 if (!result .isSuccess ()) {
195226 return new Answer (cmd , false , "Configure VPN user failed for user " + userpwd .getUsername () + ":" + result .getDetails ());
196227 }
@@ -217,7 +248,7 @@ private Answer execute(RemoteAccessVpnCfgCommand cmd) {
217248 }
218249 args += " -C " + cmd .getLocalCidr ();
219250 args += " -i " + cmd .getPublicInterface ();
220- ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), "vpn_l2tp.sh" , args );
251+ ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), VRScripts . VPN_L2TP , args );
221252 return new Answer (cmd , result .isSuccess (), result .getDetails ());
222253 }
223254
@@ -259,9 +290,9 @@ private Answer execute(SetFirewallRulesCommand cmd) {
259290 ExecutionResult result ;
260291
261292 if (trafficType == FirewallRule .TrafficType .Egress ) {
262- result = _vrDeployer .executeInVR (routerAccessIp , "firewall_egress.sh" , args );
293+ result = _vrDeployer .executeInVR (routerAccessIp , VRScripts . FIREWALL_EGRESS , args );
263294 } else {
264- result = _vrDeployer .executeInVR (routerAccessIp , "firewall_ingress.sh" , args );
295+ result = _vrDeployer .executeInVR (routerAccessIp , VRScripts . FIREWALL_INGRESS , args );
265296 }
266297
267298 if (!result .isSuccess ()) {
@@ -288,7 +319,7 @@ private Answer execute(SetPortForwardingRulesCommand cmd) {
288319 args .append (" -r " ).append (rule .getDstIp ());
289320 args .append (" -d " ).append (rule .getStringDstPortRange ());
290321
291- ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), "firewall_nat.sh" , args .toString ());
322+ ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), VRScripts . FIREWALL_NAT , args .toString ());
292323
293324 if (!result .isSuccess ()) {
294325 results [i ++] = "Failed" ;
@@ -311,7 +342,7 @@ protected SetStaticNatRulesAnswer SetVPCStaticNatRules(SetStaticNatRulesCommand
311342 args += " -l " + rule .getSrcIp ();
312343 args += " -r " + rule .getDstIp ();
313344
314- ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), "vpc_staticnat.sh" , args );
345+ ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), VRScripts . VPC_STATIC_NAT , args );
315346
316347 if (!result .isSuccess ()) {
317348 results [i ++] = null ;
@@ -345,7 +376,7 @@ private SetStaticNatRulesAnswer execute(SetStaticNatRulesCommand cmd) {
345376 args .append (" -d " ).append (rule .getStringSrcPortRange ());
346377 args .append (" -G " );
347378
348- ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), "firewall_nat.sh" , args .toString ());
379+ ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), VRScripts . FIREWALL_NAT , args .toString ());
349380
350381 if (!result .isSuccess ()) {
351382 results [i ++] = "Failed" ;
@@ -416,10 +447,10 @@ private Answer execute(LoadBalancerConfigCommand cmd) {
416447
417448 if (cmd .getVpcId () == null ) {
418449 args = " -i " + routerIp + args ;
419- result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), "loadbalancer.sh" , args );
450+ result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), VRScripts . LB , args );
420451 } else {
421452 args = " -i " + cmd .getNic ().getIp () + args ;
422- result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), "vpc_loadbalancer.sh" , args );
453+ result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), VRScripts . VPC_LB , args );
423454 }
424455
425456 return new Answer (cmd , result .isSuccess (), result .getDetails ());
@@ -437,7 +468,7 @@ protected Answer execute(VmDataCommand cmd) {
437468
438469 String args = "-d " + json ;
439470
440- final ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), "vmdata.py" , args );
471+ final ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), VRScripts . VMDATA , args );
441472 return new Answer (cmd , result .isSuccess (), result .getDetails ());
442473 }
443474
@@ -449,7 +480,7 @@ protected Answer execute(final SavePasswordCommand cmd) {
449480 String args = "-v " + vmIpAddress ;
450481 args += " -p " + password ;
451482
452- ExecutionResult result = _vrDeployer .executeInVR (routerPrivateIPAddress , "savepassword.sh" , args );
483+ ExecutionResult result = _vrDeployer .executeInVR (routerPrivateIPAddress , VRScripts . PASSWORD , args );
453484 return new Answer (cmd , result .isSuccess (), result .getDetails ());
454485 }
455486
@@ -481,7 +512,7 @@ protected Answer execute(final DhcpEntryCommand cmd) {
481512 args += " -N" ;
482513 }
483514
484- final ExecutionResult result = _vrDeployer .executeInVR (cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP ), "edithosts.sh" , args );
515+ final ExecutionResult result = _vrDeployer .executeInVR (cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP ), VRScripts . DHCP , args );
485516 return new Answer (cmd , result .isSuccess (), result .getDetails ());
486517 }
487518
@@ -491,7 +522,7 @@ protected Answer execute(final CreateIpAliasCommand cmd) {
491522 for (IpAliasTO ipaliasto : ipAliasTOs ) {
492523 args = args + ipaliasto .getAlias_count () + ":" + ipaliasto .getRouterip () + ":" + ipaliasto .getNetmask () + "-" ;
493524 }
494- final ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), "createipAlias.sh" , args );
525+ final ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), VRScripts . IPALIAS_CREATE , args );
495526 return new Answer (cmd , result .isSuccess (), result .getDetails ());
496527 }
497528
@@ -507,7 +538,7 @@ protected Answer execute(final DeleteIpAliasCommand cmd) {
507538 for (IpAliasTO ipAliasTO : activeIpAliasTOs ) {
508539 args = args + ipAliasTO .getAlias_count () + ":" + ipAliasTO .getRouterip () + ":" + ipAliasTO .getNetmask () + "-" ;
509540 }
510- final ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), "deleteipAlias.sh" , args );
541+ final ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), VRScripts . IPALIAS_DELETE , args );
511542 return new Answer (cmd , result .isSuccess (), result .getDetails ());
512543 }
513544
@@ -517,7 +548,7 @@ protected Answer execute(final DnsMasqConfigCommand cmd) {
517548 for (DhcpTO dhcpTo : dhcpTos ) {
518549 args = args + dhcpTo .getRouterIp () + ":" + dhcpTo .getGateway () + ":" + dhcpTo .getNetmask () + ":" + dhcpTo .getStartIpOfSubnet () + "-" ;
519550 }
520- final ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), "dnsmasq.sh" , args );
551+ final ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), VRScripts . DNSMASQ_CONFIG , args );
521552 return new Answer (cmd , result .isSuccess (), result .getDetails ());
522553 }
523554
@@ -529,29 +560,29 @@ private CheckS2SVpnConnectionsAnswer execute(CheckS2SVpnConnectionsCommand cmd)
529560 args += ip + " " ;
530561 }
531562
532- ExecutionResult result = _vrDeployer .executeInVR (routerIP , "checkbatchs2svpn.sh" , args );
563+ ExecutionResult result = _vrDeployer .executeInVR (routerIP , VRScripts . S2SVPN_CHECK , args );
533564 return new CheckS2SVpnConnectionsAnswer (cmd , result .isSuccess (), result .getDetails ());
534565 }
535566
536567 protected Answer execute (CheckRouterCommand cmd ) {
537568 final String routerPrivateIPAddress = cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP );
538569
539- final ExecutionResult result = _vrDeployer .executeInVR (routerPrivateIPAddress , "checkrouter.sh" , null );
570+ final ExecutionResult result = _vrDeployer .executeInVR (routerPrivateIPAddress , VRScripts . RVR_CHECK , null );
540571 if (!result .isSuccess ()) {
541572 return new CheckRouterAnswer (cmd , result .getDetails ());
542573 }
543574 return new CheckRouterAnswer (cmd , result .getDetails (), true );
544575 }
545576
546577 protected Answer execute (BumpUpPriorityCommand cmd ) {
547- ExecutionResult result = _vrDeployer .executeInVR (cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP ), "bumpup_priority.sh" , null );
578+ ExecutionResult result = _vrDeployer .executeInVR (cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP ), VRScripts . RVR_BUMPUP_PRI , null );
548579 return new Answer (cmd , result .isSuccess (), result .getDetails ());
549580 }
550581
551582 protected Answer execute (GetDomRVersionCmd cmd ) {
552583 final String routerPrivateIPAddress = cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP );
553584
554- final ExecutionResult result = _vrDeployer .executeInVR (routerPrivateIPAddress , "get_template_version.sh" , null );
585+ final ExecutionResult result = _vrDeployer .executeInVR (routerPrivateIPAddress , VRScripts . VERSION , null );
555586 if (!result .isSuccess ()) {
556587 return new GetDomRVersionAnswer (cmd , "GetDomRVersionCmd failed" );
557588 }
@@ -604,7 +635,7 @@ protected Answer execute(Site2SiteVpnCfgCommand cmd) {
604635 args += " -N " ;
605636 args += cmd .getPeerGuestCidrList ();
606637 }
607- ExecutionResult result = _vrDeployer .executeInVR (cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP ), "ipsectunnel.sh" , args );
638+ ExecutionResult result = _vrDeployer .executeInVR (cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP ), VRScripts . S2SVPN_IPSEC , args );
608639 if (!result .isSuccess ()) {
609640 return new Answer (cmd , false , "Configure site to site VPN failed due to " + result .getDetails ());
610641 }
@@ -621,7 +652,7 @@ protected Answer execute(SetMonitorServiceCommand cmd) {
621652 args = args + " -d" ;
622653 }
623654
624- ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), "monitor_service.sh" , args );
655+ ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), VRScripts . MONITOR_SERVICE , args );
625656
626657 if (!result .isSuccess ()) {
627658 return new Answer (cmd , false , result .getDetails ());
@@ -663,7 +694,7 @@ protected Answer execute(SetupGuestNetworkCommand cmd) {
663694 if (domainName != null && !domainName .isEmpty ()) {
664695 args += " -e " + domainName ;
665696 }
666- ExecutionResult result = _vrDeployer .executeInVR (routerIP , "vpc_guestnw.sh" , args );
697+ ExecutionResult result = _vrDeployer .executeInVR (routerIP , VRScripts . VPC_GUEST_NETWORK , args );
667698
668699 if (!result .isSuccess ()) {
669700 return new Answer (cmd , false , "Creating guest network failed due to " + result .getDetails ());
@@ -695,12 +726,12 @@ private SetNetworkACLAnswer execute(SetNetworkACLCommand cmd) {
695726 args += " -M " + nic .getMac ();
696727 if (privateGw != null ) {
697728 args += " -a " + rule ;
698- result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), "vpc_privategw_acl.sh" , args );
729+ result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), VRScripts . VPC_PRIVATEGW_ACL , args );
699730 } else {
700731 args += " -i " + nic .getIp ();
701732 args += " -m " + netmask ;
702733 args += " -a " + rule ;
703- result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), "vpc_acl.sh" , args );
734+ result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), VRScripts . VPC_ACL , args );
704735 }
705736
706737 if (!result .isSuccess ()) {
@@ -727,7 +758,7 @@ protected Answer execute(SetSourceNatCommand cmd) {
727758 args += pubIP .getPublicIp ();
728759 args += " -c " ;
729760 args += dev ;
730- ExecutionResult result = _vrDeployer .executeInVR (routerIP , "vpc_snat.sh" , args );
761+ ExecutionResult result = _vrDeployer .executeInVR (routerIP , VRScripts . VPC_SOURCE_NAT , args );
731762 return new Answer (cmd , result .isSuccess (), result .getDetails ());
732763 }
733764
@@ -744,7 +775,7 @@ private SetPortForwardingRulesAnswer execute(SetPortForwardingRulesVpcCommand cm
744775 args += " -r " + rule .getDstIp ();
745776 args += " -d " + rule .getStringDstPortRange ().replace (":" , "-" );
746777
747- ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), "vpc_portforwarding.sh" , args );
778+ ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), VRScripts . VPC_PORTFORWARDING , args );
748779
749780 if (!result .isSuccess ()) {
750781 results [i ++] = "Failed" ;
@@ -787,7 +818,7 @@ public IpAssocAnswer execute(IpAssocVpcCommand cmd) {
787818 args += " -n " ;
788819 args += NetUtils .getSubNet (ip .getPublicIp (), ip .getVlanNetmask ());
789820
790- ExecutionResult result = _vrDeployer .executeInVR (routerIP , "vpc_ipassoc.sh" , args );
821+ ExecutionResult result = _vrDeployer .executeInVR (routerIP , VRScripts . VPC_IPASSOC , args );
791822 if (!result .isSuccess ()) {
792823 results [i ++] = ip .getPublicIp () + " - vpc_ipassoc failed:" + result .getDetails ();
793824 break ;
@@ -797,7 +828,7 @@ public IpAssocAnswer execute(IpAssocVpcCommand cmd) {
797828 snatArgs += " -l " + ip .getPublicIp ();
798829 snatArgs += " -c " + nicName ;
799830
800- result = _vrDeployer .executeInVR (routerIP , "vpc_privateGateway.sh" , snatArgs );
831+ result = _vrDeployer .executeInVR (routerIP , VRScripts . VPC_PRIVATEGW , snatArgs );
801832 if (result != null ) {
802833 results [i ++] = ip .getPublicIp () + " - vpc_privateGateway failed:" + result .getDetails ();
803834 break ;
@@ -821,7 +852,7 @@ private SetStaticRouteAnswer execute(SetStaticRouteCommand cmd) {
821852 }
822853
823854 String args = " -a " + sb .toString ();
824- ExecutionResult result = _vrDeployer .executeInVR (routerIP , "vpc_staticroute.sh" , args );
855+ ExecutionResult result = _vrDeployer .executeInVR (routerIP , VRScripts . VPC_STATIC_ROUTE , args );
825856
826857 if (!result .isSuccess ()) {
827858 for (int i = 0 ; i < results .length ; i ++) {
@@ -873,7 +904,7 @@ public Answer execute(IpAssocCommand cmd) {
873904 args += " -n" ;
874905 }
875906
876- ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), "ipassoc.sh" , args );
907+ ExecutionResult result = _vrDeployer .executeInVR (cmd .getRouterAccessIp (), VRScripts . IPASSOC , args );
877908 if (result .isSuccess ()) {
878909 results [i ++] = ip .getPublicIp () + " - success" ;
879910 } else {
0 commit comments