129129import com .cloud .agent .api .to .PortForwardingRuleTO ;
130130import com .cloud .agent .api .to .StaticNatRuleTO ;
131131import com .cloud .agent .api .to .VirtualMachineTO ;
132+ import com .cloud .agent .resource .virtualnetwork .VRScripts ;
132133import com .cloud .agent .resource .virtualnetwork .VirtualRouterDeployer ;
133134import com .cloud .agent .resource .virtualnetwork .VirtualRoutingResource ;
134135import com .cloud .dc .DataCenter .NetworkType ;
@@ -852,12 +853,13 @@ protected Answer execute(final RemoteAccessVpnCfgCommand cmd) {
852853 argsBuf .append (" -i " ).append (cmd .getPublicInterface ());
853854
854855 try {
856+ final String command = String .format ("%s%s %s" , "/opt/cloud/bin/" , VRScripts .VPN_L2TP , argsBuf .toString ());
855857
856858 if (s_logger .isDebugEnabled ()) {
857- s_logger .debug ("Executing /opt/cloud/bin/vpn_lt2p.sh " );
859+ s_logger .debug ("Executing " + command );
858860 }
859861
860- final Pair <Boolean , String > result = SshHelper .sshExecute (controlIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , "/opt/cloud/bin/vpn_l2tp.sh " + argsBuf . toString () );
862+ final Pair <Boolean , String > result = SshHelper .sshExecute (controlIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , command );
861863
862864 if (!result .first ()) {
863865 s_logger .error ("RemoteAccessVpnCfg command on domR failed, message: " + result .second ());
@@ -940,10 +942,12 @@ private SetStaticRouteAnswer execute(final SetStaticRouteCommand cmd) {
940942 }
941943 args += " -a " + sb .toString ();
942944
945+ final String command = String .format ("%s%s %s" , "/opt/cloud/bin/" , VRScripts .VPC_STATIC_ROUTE , args );
946+
943947 // Send over the command for execution, via ssh, to the VR.
944948 try {
945949 final Pair <Boolean , String > result =
946- SshHelper .sshExecute (controlIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , "/opt/cloud/bin/vpc_staticroute.sh " + args );
950+ SshHelper .sshExecute (controlIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , command );
947951
948952 if (s_logger .isDebugEnabled ()) {
949953 s_logger .debug ("Executing script on domain router " + controlIp + ": /opt/cloud/bin/vpc_staticroute.sh " + args );
@@ -966,15 +970,18 @@ private SetStaticRouteAnswer execute(final SetStaticRouteCommand cmd) {
966970 }
967971
968972 protected CheckS2SVpnConnectionsAnswer execute (final CheckS2SVpnConnectionsCommand cmd ) {
973+ final StringBuilder cmdline = new StringBuilder ();
974+ cmdline .append ("/opt/cloud/bin/" );
975+ cmdline .append (VRScripts .S2SVPN_CHECK );
976+
969977 if (s_logger .isDebugEnabled ()) {
970978 s_logger .debug ("Executing resource CheckS2SVpnConnectionsCommand: " + s_gson .toJson (cmd ));
971- s_logger .debug ("Run command on domR " + cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP ) + ", /opt/cloud/bin/checkbatchs2svpn.sh " );
979+ s_logger .debug ("Run command on domR " + cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP ) + cmdline . toString () );
972980 }
973981
974982 Pair <Boolean , String > result ;
975983 try {
976984 final String controlIp = getRouterSshControlIp (cmd );
977- final StringBuilder cmdline = new StringBuilder ("/opt/cloud/bin/checkbatchs2svpn.sh " );
978985 for (final String ip : cmd .getVpnIps ()) {
979986 cmdline .append (" " );
980987 cmdline .append (ip );
@@ -1048,7 +1055,8 @@ protected Answer execute(final Site2SiteVpnCfgCommand cmd) {
10481055
10491056 Pair <Boolean , String > result ;
10501057 try {
1051- result = SshHelper .sshExecute (routerIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , "/opt/cloud/bin/ipsectunnel.sh " + args );
1058+ final String command = String .format ("%s%s %s" , "/opt/cloud/bin/" , VRScripts .S2SVPN_IPSEC , args );
1059+ result = SshHelper .sshExecute (routerIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , command );
10521060
10531061 if (!result .first ()) {
10541062 s_logger .error ("Setup site2site VPN " + cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP ) + " failed, message: " + result .second ());
@@ -1085,7 +1093,9 @@ protected SetSourceNatAnswer execute(final SetSourceNatCommand cmd) {
10851093 args += " -c " ;
10861094 args += "eth" + ethDeviceNum ;
10871095
1088- final Pair <Boolean , String > result = SshHelper .sshExecute (routerIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , "/opt/cloud/bin/vpc_snat.sh " + args );
1096+ final String command = String .format ("%s%s %s" , "/opt/cloud/bin/" , VRScripts .VPC_SOURCE_NAT , args );
1097+
1098+ final Pair <Boolean , String > result = SshHelper .sshExecute (routerIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , command );
10891099
10901100 if (!result .first ()) {
10911101 final String msg = "SetupGuestNetworkCommand on domain router " + routerIp + " failed. message: " + result .second ();
@@ -1146,16 +1156,18 @@ protected Answer execute(final SetPortForwardingRulesCommand cmd) {
11461156 }
11471157
11481158 protected Answer execute (final CheckRouterCommand cmd ) {
1159+ final String command = String .format ("%s%s" , "/opt/cloud/bin/" , VRScripts .RVR_CHECK );
1160+
11491161 if (s_logger .isDebugEnabled ()) {
11501162 s_logger .debug ("Executing resource CheckRouterCommand: " + s_gson .toJson (cmd ));
1151- s_logger .debug ("Run command on domR " + cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP ) + ", /opt/cloud/bin/checkrouter.sh " );
1163+ s_logger .debug ("Run command on domR " + cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP ) + command );
11521164 }
11531165
11541166 Pair <Boolean , String > result ;
11551167 try {
11561168
11571169 final String controlIp = getRouterSshControlIp (cmd );
1158- result = SshHelper .sshExecute (controlIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , "/opt/cloud/bin/checkrouter.sh " );
1170+ result = SshHelper .sshExecute (controlIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , command );
11591171
11601172 if (!result .first ()) {
11611173 s_logger .error ("check router command on domR " + cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP ) + " failed, message: " + result .second ());
@@ -1367,11 +1379,13 @@ protected Answer execute(final LoadBalancerConfigCommand cmd) {
13671379 return new Answer (cmd , false , "LoadBalancerConfigCommand failed due to uanble to copy haproxy configuration file" );
13681380 }
13691381
1382+ final String command = String .format ("%s%s %s" , "/root/" , VRScripts .LB , args );
1383+
13701384 if (s_logger .isDebugEnabled ()) {
1371- s_logger .debug ("Run command on domain router " + routerIp + ", /root/loadbalancer.sh " + args );
1385+ s_logger .debug ("Run command on domain router " + routerIp + command );
13721386 }
13731387
1374- result = SshHelper .sshExecute (controlIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , "/root/loadbalancer.sh " + args );
1388+ result = SshHelper .sshExecute (controlIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , command );
13751389
13761390 if (!result .first ()) {
13771391 final String msg = "LoadBalancerConfigCommand on domain router " + routerIp + " failed. message: " + result .second ();
@@ -1406,19 +1420,16 @@ protected Answer execute(final SavePasswordCommand cmd) {
14061420 final String vmIpAddress = cmd .getVmIpAddress ();
14071421
14081422 // Run save_password_to_domr.sh
1409- String args = " -v " + vmIpAddress ;
1423+ final String command = String . format ( "%s%s %s %s %s %s" , "/opt/cloud/bin/" , VRScripts . PASSWORD , "-v" , vmIpAddress , "-p" , password ) ;
14101424
14111425 if (s_logger .isDebugEnabled ()) {
1412- s_logger . debug ( "Run command on domain router " + controlIp + ", /opt/cloud/bin/savepassword.sh " + args + " -p " +
1413- StringUtils . getMaskedPasswordForDisplay ( cmd . getPassword ()) );
1426+ final String debugCommand = String . format ( "%s%s %s %s %s %s " , " /opt/cloud/bin/" , VRScripts . PASSWORD , "-v" , vmIpAddress , "-p" , StringUtils . getMaskedPasswordForDisplay ( cmd . getPassword ()));
1427+ s_logger . debug ( "Run command on domain router " + controlIp + debugCommand );
14141428 }
14151429
1416- args += " -p " + password ;
1417-
14181430 try {
14191431
1420- final Pair <Boolean , String > result = SshHelper .sshExecute (controlIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , "/opt/cloud/bin/savepassword.sh " +
1421- args );
1432+ final Pair <Boolean , String > result = SshHelper .sshExecute (controlIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , command );
14221433
14231434 if (!result .first ()) {
14241435 s_logger .error ("savepassword command on domain router " + controlIp + " failed, message: " + result .second ());
@@ -1518,11 +1529,10 @@ protected Answer execute(final VmDataCommand cmd) {
15181529 s_logger .debug ("VM data JSON IS:" + json );
15191530
15201531 json = Base64 .encodeBase64String (json .getBytes (Charset .forName ("UTF-8" )));
1521-
1522- final String args = "-d " + json ;
1532+ final String command = String .format ("%s%s %s %s" , "/opt/cloud/bin/" , VRScripts .VMDATA , "-d" , json );
15231533
15241534 try {
1525- final Pair <Boolean , String > result = SshHelper .sshExecute (controlIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , "/opt/cloud/bin/vmdata.py " + args );
1535+ final Pair <Boolean , String > result = SshHelper .sshExecute (controlIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , command );
15261536 if (!result .first ()) {
15271537 s_logger .error ("vm_data command on domain router " + controlIp + " failed. messge: " + result .second ());
15281538 return new Answer (cmd , false , "VmDataCommand failed due to " + result .second ());
@@ -1573,13 +1583,15 @@ protected Answer execute(final DhcpEntryCommand cmd) {
15731583 args += " -N" ;
15741584 }
15751585
1586+ final String command = String .format ("%s%s %s" , "/root/" , VRScripts .DHCP , args );
1587+
15761588 if (s_logger .isDebugEnabled ()) {
1577- s_logger .debug ("Run command on domR " + cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP ) + ", /root/edithosts.sh " + args );
1589+ s_logger .debug ("Run command on domR " + cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP ) + command );
15781590 }
15791591
15801592 try {
15811593 final String controlIp = getRouterSshControlIp (cmd );
1582- final Pair <Boolean , String > result = SshHelper .sshExecute (controlIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , "/root/edithosts.sh " + args );
1594+ final Pair <Boolean , String > result = SshHelper .sshExecute (controlIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , command );
15831595
15841596 if (!result .first ()) {
15851597 s_logger .error ("dhcp_entry command on domR " + controlIp + " failed, message: " + result .second ());
@@ -1665,7 +1677,9 @@ protected Answer execute(final DnsMasqConfigCommand cmd) {
16651677 }
16661678
16671679 try {
1668- final Pair <Boolean , String > result = SshHelper .sshExecute (controlIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , "/root/dnsmasq.sh " + args );
1680+ final String command = String .format ("%s%s %s" , "/root/" , VRScripts .DHCP , args );
1681+
1682+ final Pair <Boolean , String > result = SshHelper .sshExecute (controlIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , command );
16691683 if (s_logger .isDebugEnabled ()) {
16701684 s_logger .debug ("Run command on domain router " + routerIp + ", /root/dnsmasq.sh" );
16711685 }
@@ -1997,12 +2011,14 @@ protected void assignPublicIpAddress(final String vmName, final String privateIp
19972011 args += " -n " ;
19982012 }
19992013
2014+ final String command = String .format ("%s%s %s" ,"/opt/cloud/bin/" , VRScripts .IPASSOC ,args );
2015+
20002016 if (s_logger .isDebugEnabled ()) {
2001- s_logger .debug ("Run command on domain router " + privateIpAddress + ", /opt/cloud/bin/ipassoc.sh " + args );
2017+ s_logger .debug ("Run command on domain router " + privateIpAddress + command );
20022018 }
20032019
20042020 final Pair <Boolean , String > result =
2005- SshHelper .sshExecute (privateIpAddress , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , "/opt/cloud/bin/ipassoc.sh " + args );
2021+ SshHelper .sshExecute (privateIpAddress , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , command );
20062022
20072023 if (!result .first ()) {
20082024 s_logger .error ("ipassoc command on domain router " + privateIpAddress + " failed. message: " + result .second ());
@@ -2015,15 +2031,17 @@ protected void assignPublicIpAddress(final String vmName, final String privateIp
20152031 }
20162032
20172033 protected Answer execute (final GetDomRVersionCmd cmd ) {
2034+ final String command = String .format ("%s%s" , "/opt/cloud/bin/" , VRScripts .VERSION );
2035+
20182036 if (s_logger .isDebugEnabled ()) {
20192037 s_logger .debug ("Executing resource GetDomRVersionCmd: " + s_gson .toJson (cmd ));
2020- s_logger .debug ("Run command on domR " + cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP ) + ", /opt/cloud/bin/get_template_version.sh " );
2038+ s_logger .debug ("Run command on domR " + cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP ) + command );
20212039 }
20222040
20232041 Pair <Boolean , String > result ;
20242042 try {
20252043 final String controlIp = getRouterSshControlIp (cmd );
2026- result = SshHelper .sshExecute (controlIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , "/opt/cloud/bin/get_template_version.sh " );
2044+ result = SshHelper .sshExecute (controlIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , command );
20272045
20282046 if (!result .first ()) {
20292047 s_logger .error ("GetDomRVersionCmd on domR " + cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP ) + " failed, message: " + result .second ());
@@ -2108,13 +2126,12 @@ protected Answer execute(final SetMonitorServiceCommand cmd) {
21082126
21092127 final String controlIp = getRouterSshControlIp (cmd );
21102128 final String config = cmd .getConfiguration ();
2129+ final String args = String .format (" %s %s" , "-c" , config );
21112130
2112- String args = "" ;
2113-
2114- args += " -c " + config ;
2131+ final String command = String .format ("%s%s %s" , "/opt/cloud/bin/" , VRScripts .MONITOR_SERVICE , args );
21152132
21162133 try {
2117- final Pair <Boolean , String > result = SshHelper .sshExecute (controlIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , "/opt/cloud/bin/monitor_service.sh " + args );
2134+ final Pair <Boolean , String > result = SshHelper .sshExecute (controlIp , DEFAULT_DOMR_SSHPORT , "root" , getSystemVMKeyFile (), null , command );
21182135
21192136 if (!result .first ()) {
21202137 final String msg = "monitor_service.sh failed on domain router " + controlIp + " failed " + result .second ();
0 commit comments