@@ -111,7 +111,7 @@ public class VirtualRoutingResource implements Manager {
111111 private String _routerProxyPath ;
112112 private String _createIpAliasPath ;
113113 private String _deleteIpAliasPath ;
114- private String _configDhcpPath ;
114+ private String _callDnsMasqPath ;
115115
116116 private int _timeout ;
117117 private int _startTimeout ;
@@ -625,7 +625,8 @@ protected Answer execute(final CreateIpAliasCommand cmd) {
625625 String routerIp = cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP );
626626 final Script command = new Script (_createIpAliasPath , _timeout , s_logger );
627627 List <IpAliasTO > ipAliasTOs = cmd .getIpAliasList ();
628- String args =routerIp +" " ;
628+ String args = "" ;
629+ command .add (routerIp );
629630 for (IpAliasTO ipaliasto : ipAliasTOs ) {
630631 args = args + ipaliasto .getAlias_count ()+":" +ipaliasto .getRouterip ()+":" +ipaliasto .getNetmask ()+"-" ;
631632 }
@@ -637,7 +638,8 @@ protected Answer execute(final CreateIpAliasCommand cmd) {
637638 protected Answer execute (final DeleteIpAliasCommand cmd ) {
638639 final Script command = new Script (_deleteIpAliasPath , _timeout , s_logger );
639640 String routerIp = cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP );
640- String args = "" ;
641+ String args ="" ;
642+ command .add (routerIp );
641643 List <IpAliasTO > revokedIpAliasTOs = cmd .getDeleteIpAliasTos ();
642644 for (IpAliasTO ipAliasTO : revokedIpAliasTOs ) {
643645 args = args + ipAliasTO .getAlias_count ()+":" +ipAliasTO .getRouterip ()+":" +ipAliasTO .getNetmask ()+"-" ;
@@ -653,32 +655,26 @@ protected Answer execute(final DeleteIpAliasCommand cmd) {
653655 }
654656
655657 protected Answer execute (final DnsMasqConfigCommand cmd ) {
656- final Script command = new Script (_configDhcpPath , _timeout , s_logger );
658+ final Script command = new Script (_callDnsMasqPath , _timeout , s_logger );
657659 String routerIp = cmd .getAccessDetail (NetworkElementCommand .ROUTER_IP );
658660 DnsMasqConfigurator configurator = new DnsMasqConfigurator ();
659661 String [] config = configurator .generateConfiguration (cmd );
660- File tmpCfgFile = null ;
662+ String cfgFileName = routerIp .replace ("." ,"-" )+"dns.cgf" ;
663+ String tmpCfgFileContents = "" ;
664+ for (int i = 0 ; i < config .length ; i ++) {
665+ tmpCfgFileContents += config [i ];
666+ tmpCfgFileContents += "\n " ;
667+ }
668+ File permKey = new File ("/root/.ssh/id_rsa.cloud" );
669+ String cfgFilePath = "/tmp/" +cfgFileName ;
661670 try {
662- String cfgFilePath = "" ;
663- if (routerIp != null ) {
664- tmpCfgFile = File .createTempFile (routerIp .replace ('.' , '_' ), "cfg" );
665- final PrintWriter out
666- = new PrintWriter (new BufferedWriter (new FileWriter (tmpCfgFile )));
667- for (int i =0 ; i < config .length ; i ++) {
668- out .println (config [i ]);
669- }
670- out .close ();
671- cfgFilePath = tmpCfgFile .getAbsolutePath ();
672- }
671+ SshHelper .scpTo (routerIp , 3922 , "root" , permKey , null , "/tmp/" , tmpCfgFileContents .getBytes (), cfgFileName , null );
672+ command .add (routerIp );
673673 command .add (cfgFilePath );
674674 final String result = command .execute ();
675675 return new Answer (cmd , result == null , result );
676- } catch (final IOException e ) {
676+ } catch (Exception e ) {
677677 return new Answer (cmd , false , e .getMessage ());
678- } finally {
679- if (tmpCfgFile != null ) {
680- tmpCfgFile .delete ();
681- }
682678 }
683679 }
684680
@@ -1209,6 +1205,18 @@ public boolean configure(final String name, final Map<String, Object> params) th
12091205 if (_routerProxyPath == null ) {
12101206 throw new ConfigurationException ("Unable to find router_proxy.sh" );
12111207 }
1208+ _createIpAliasPath = findScript ("createipAlias.sh" );
1209+ if (_createIpAliasPath == null ) {
1210+ throw new ConfigurationException ("unable to find createipAlias.sh" );
1211+ }
1212+ _deleteIpAliasPath = findScript ("deleteipAlias.sh" );
1213+ if (_deleteIpAliasPath == null ) {
1214+ throw new ConfigurationException ("unable to find deleteipAlias.sh" );
1215+ }
1216+ _callDnsMasqPath = findScript ("call_dnsmasq.sh" );
1217+ if (_callDnsMasqPath == null ) {
1218+ throw new ConfigurationException ("unable to find call_dnsmasq.sh" );
1219+ }
12121220
12131221 return true ;
12141222 }
0 commit comments