bug 11455: add vpn support in kvm

Reviewed-by:Murali.Reddy@citrix.com
This commit is contained in:
Edison Su 2011-09-16 11:13:32 -07:00
parent b67fb37382
commit 9cc518f4b5
1 changed files with 52 additions and 1 deletions

View File

@ -52,6 +52,7 @@ import com.cloud.agent.api.routing.IpAssocAnswer;
import com.cloud.agent.api.routing.IpAssocCommand;
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
import com.cloud.agent.api.routing.NetworkElementCommand;
import com.cloud.agent.api.routing.RemoteAccessVpnCfgCommand;
import com.cloud.agent.api.routing.SavePasswordCommand;
import com.cloud.agent.api.routing.SetFirewallRulesAnswer;
import com.cloud.agent.api.routing.SetFirewallRulesCommand;
@ -60,6 +61,7 @@ import com.cloud.agent.api.routing.SetPortForwardingRulesCommand;
import com.cloud.agent.api.routing.SetStaticNatRulesAnswer;
import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
import com.cloud.agent.api.routing.VmDataCommand;
import com.cloud.agent.api.routing.VpnUsersCfgCommand;
import com.cloud.agent.api.to.IpAddressTO;
import com.cloud.agent.api.to.PortForwardingRuleTO;
import com.cloud.agent.api.to.StaticNatRuleTO;
@ -93,6 +95,7 @@ public class VirtualRoutingResource implements Manager {
private String _privateEthIf;
private String _getRouterStatusPath;
private String _bumpUpPriorityPath;
private String _l2tpVpnPath;
private int _timeout;
@ -129,7 +132,12 @@ public class VirtualRoutingResource implements Manager {
return execute((SetFirewallRulesCommand)cmd);
} else if (cmd instanceof BumpUpPriorityCommand) {
return execute((BumpUpPriorityCommand)cmd);
} else {
} else if (cmd instanceof RemoteAccessVpnCfgCommand) {
return execute((RemoteAccessVpnCfgCommand)cmd);
} else if (cmd instanceof VpnUsersCfgCommand) {
return execute((VpnUsersCfgCommand)cmd);
}
else {
return Answer.createUnsupportedCommandAnswer(cmd);
}
} catch (final IllegalArgumentException e) {
@ -137,6 +145,44 @@ public class VirtualRoutingResource implements Manager {
}
}
private Answer execute(VpnUsersCfgCommand cmd) {
for (VpnUsersCfgCommand.UsernamePassword userpwd: cmd.getUserpwds()) {
Script command = new Script(_l2tpVpnPath, _timeout, s_logger);
command.add(cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP));
if (!userpwd.isAdd()) {
command.add("-U ", userpwd.getUsername());
} else {
command.add("-u ", userpwd.getUsernamePassword());
}
String result = command.execute();
if (result != null) {
return new Answer(cmd, false, "Configure VPN user failed for user " + userpwd.getUsername());
}
}
return new Answer(cmd);
}
private Answer execute(RemoteAccessVpnCfgCommand cmd) {
Script command = new Script(_l2tpVpnPath, _timeout, s_logger);
command.add(cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP));
if (cmd.isCreate()) {
command.add("-r ", cmd.getIpRange());
command.add("-p ", cmd.getPresharedKey());
command.add("-s ", cmd.getVpnServerIp());
command.add("-l ", cmd.getLocalIp());
command.add("-c ");
} else {
command.add("-d ");
command.add("-s ", cmd.getVpnServerIp());
}
String result = command.execute();
if (result != null) {
return new Answer(cmd, false, "Configure VPN failed");
}
return new Answer(cmd);
}
private Answer execute(SetFirewallRulesCommand cmd) {
String[] results = new String[cmd.getRules().length];
for (int i =0; i < cmd.getRules().length; i++) {
@ -775,6 +821,11 @@ public class VirtualRoutingResource implements Manager {
if(_bumpUpPriorityPath == null) {
throw new ConfigurationException("Unable to find bumpUpPriority.sh");
}
_l2tpVpnPath = findScript("l2tp_vpn.sh");
if (_l2tpVpnPath == null) {
throw new ConfigurationException("Unable to find l2tp_vpn.sh");
}
return true;
}