Skip to content

Commit a4d0f91

Browse files
anthonyxuAlena Prokharchyk
authored andcommitted
VPC : use routerProxy to call l2tpVpn
Conflicts: core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
1 parent d70d2f8 commit a4d0f91

9 files changed

Lines changed: 67 additions & 126 deletions

File tree

core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java

Lines changed: 63 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,15 @@
8282
public class VirtualRoutingResource implements Manager {
8383
private static final Logger s_logger = Logger.getLogger(VirtualRoutingResource.class);
8484
private String _savepasswordPath; // This script saves a random password to the DomR file system
85-
private String _ipassocPath;
8685
private String _publicIpAddress;
8786
private String _firewallPath;
8887
private String _loadbPath;
8988
private String _dhcpEntryPath;
9089
private String _vmDataPath;
9190
private String _publicEthIf;
9291
private String _privateEthIf;
93-
private String _getRouterStatusPath;
9492
private String _bumpUpPriorityPath;
95-
private String _l2tpVpnPath;
96-
private String _getDomRVersionPath;
97-
93+
private String _routerProxyPath;
9894

9995
private int _timeout;
10096
private int _startTimeout;
@@ -146,37 +142,41 @@ public Answer executeRequest(final Command cmd) {
146142
}
147143

148144
private Answer execute(VpnUsersCfgCommand cmd) {
149-
for (VpnUsersCfgCommand.UsernamePassword userpwd: cmd.getUserpwds()) {
150-
Script command = new Script(_l2tpVpnPath, _timeout, s_logger);
151-
command.add(cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP));
145+
for (VpnUsersCfgCommand.UsernamePassword userpwd: cmd.getUserpwds()) {
146+
String args = "";
152147
if (!userpwd.isAdd()) {
153-
command.add("-U ", userpwd.getUsername());
148+
args +="-U ";
149+
args +=userpwd.getUsername();
154150
} else {
155-
command.add("-u ", userpwd.getUsernamePassword());
151+
args +="-u ";
152+
args += userpwd.getUsernamePassword();
156153
}
157-
String result = command.execute();
154+
String result = routerProxy("vpn_l2tp.sh", cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP), args);
158155
if (result != null) {
159156
return new Answer(cmd, false, "Configure VPN user failed for user " + userpwd.getUsername());
160157
}
161-
}
162-
158+
}
163159
return new Answer(cmd);
164160
}
165161

166162
private Answer execute(RemoteAccessVpnCfgCommand cmd) {
167-
Script command = new Script(_l2tpVpnPath, _timeout, s_logger);
168-
command.add(cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP));
163+
String args = "";
169164
if (cmd.isCreate()) {
170-
command.add("-r ", cmd.getIpRange());
171-
command.add("-p ", cmd.getPresharedKey());
172-
command.add("-s ", cmd.getVpnServerIp());
173-
command.add("-l ", cmd.getLocalIp());
174-
command.add("-c ");
165+
args += "-r ";
166+
args += cmd.getIpRange();
167+
args += " -p ";
168+
args += cmd.getPresharedKey();
169+
args += " -s ";
170+
args += cmd.getVpnServerIp();
171+
args += " -l ";
172+
args += cmd.getLocalIp();
173+
args += " -c ";
175174
} else {
176-
command.add("-d ");
177-
command.add("-s ", cmd.getVpnServerIp());
175+
args +="-d ";
176+
args += " -s ";
177+
args += cmd.getVpnServerIp();
178178
}
179-
String result = command.execute();
179+
String result = routerProxy("vpn_l2tp.sh", cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP), args);
180180
if (result != null) {
181181
return new Answer(cmd, false, "Configure VPN failed");
182182
}
@@ -474,9 +474,18 @@ protected synchronized Answer execute (final DhcpEntryCommand cmd) {
474474
}
475475

476476
public String getRouterStatus(String routerIP) {
477-
final Script command = new Script(_getRouterStatusPath, _timeout, s_logger);
477+
return routerProxy("checkrouter.sh", routerIP, null);
478+
}
479+
480+
481+
public String routerProxy(String script, String routerIP, String args) {
482+
final Script command = new Script(_routerProxyPath, _timeout, s_logger);
478483
final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
484+
command.add(script);
479485
command.add(routerIP);
486+
if ( args != null ) {
487+
command.add(args);
488+
}
480489
String result = command.execute(parser);
481490
if (result == null) {
482491
return parser.getLine();
@@ -507,14 +516,7 @@ protected Answer execute(BumpUpPriorityCommand cmd) {
507516
}
508517

509518
protected String getDomRVersion(String routerIP) {
510-
final Script command = new Script(_getDomRVersionPath, _timeout, s_logger);
511-
final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
512-
command.add(routerIP);
513-
String result = command.execute(parser);
514-
if (result == null) {
515-
return parser.getLine();
516-
}
517-
return null;
519+
return routerProxy("netusage.sh", routerIP, null);
518520
}
519521

520522
protected Answer execute(GetDomRVersionCmd cmd) {
@@ -592,16 +594,17 @@ public synchronized String savePassword(final String privateIpAddress, final Str
592594

593595

594596
public String assignPublicIpAddress(final String vmName, final long id, final String vnet, final String privateIpAddress, final String macAddress, final String publicIpAddress) {
595-
596-
final Script command = new Script(_ipassocPath, _timeout, s_logger);
597-
command.add("-A");
598-
command.add("-f"); //first ip is source nat ip
599-
command.add("-r", vmName);
600-
command.add("-i", privateIpAddress);
601-
command.add("-a", macAddress);
602-
command.add("-l", publicIpAddress);
603-
604-
return command.execute();
597+
String args ="-A";
598+
args += " -f"; //first ip is source nat ip
599+
args += " -r ";
600+
args += vmName;
601+
args += " -i ";
602+
args += privateIpAddress;
603+
args += " -a ";
604+
args += macAddress;
605+
args += " -l ";
606+
args += publicIpAddress;
607+
return routerProxy("ipassoc.sh", privateIpAddress, args);
605608
}
606609

607610
public String assignPublicIpAddress(final String vmName,
@@ -610,30 +613,29 @@ public String assignPublicIpAddress(final String vmName,
610613
final String vlanId, final String vlanGateway,
611614
final String vlanNetmask, final String vifMacAddress, String guestIp, int nicNum){
612615

613-
final Script command = new Script(_ipassocPath, _timeout, s_logger);
614-
command.add( privateIpAddress);
616+
String args = "";
615617
if (add) {
616-
command.add("-A");
618+
args += "-A";
617619
} else {
618-
command.add("-D");
620+
args += "-D";
619621
}
620-
622+
String cidrSize = Long.toString(NetUtils.getCidrSize(vlanNetmask));
621623
if (sourceNat) {
622-
command.add("-s");
623-
}
624+
args +=" -s";
625+
}
624626
if (firstIP) {
625-
command.add( "-f");
626-
627+
args += " -f";
627628
}
628-
String cidrSize = Long.toString(NetUtils.getCidrSize(vlanNetmask));
629-
command.add( "-l", publicIpAddress + "/" + cidrSize);
629+
args += " -l ";
630+
args += publicIpAddress + "/" + cidrSize;
631+
630632
String publicNic = "eth" + nicNum;
631-
command.add("-c", publicNic);
632-
633-
command.add("-g", vlanGateway);
634-
633+
args += " -c ";
634+
args += publicNic;
635635

636-
return command.execute();
636+
args +=" -g ";
637+
args += vlanGateway;
638+
return routerProxy("ipassoc.sh", privateIpAddress, args);
637639
}
638640

639641
private void deletExitingLinkLocalRoutTable(String linkLocalBr) {
@@ -801,12 +803,6 @@ public boolean configure(final String name, final Map<String, Object> params) th
801803
value = (String)params.get("ssh.port");
802804
_port = NumbersUtil.parseInt(value, 3922);
803805

804-
_ipassocPath = findScript("ipassoc.sh");
805-
if (_ipassocPath == null) {
806-
throw new ConfigurationException("Unable to find the ipassoc.sh");
807-
}
808-
s_logger.info("ipassoc.sh found in " + _ipassocPath);
809-
810806
_publicIpAddress = (String)params.get("public.ip.address");
811807
if (_publicIpAddress != null) {
812808
s_logger.warn("Incoming public ip address is overriden. Will always be using the same ip address: " + _publicIpAddress);
@@ -837,11 +833,6 @@ public boolean configure(final String name, final Map<String, Object> params) th
837833
throw new ConfigurationException("Unable to find user_data.sh");
838834
}
839835

840-
_getRouterStatusPath = findScript("getRouterStatus.sh");
841-
if(_getRouterStatusPath == null) {
842-
throw new ConfigurationException("Unable to find getRouterStatus.sh");
843-
}
844-
845836
_publicEthIf = (String)params.get("public.network.device");
846837
if (_publicEthIf == null) {
847838
_publicEthIf = "xenbr1";
@@ -859,14 +850,9 @@ public boolean configure(final String name, final Map<String, Object> params) th
859850
throw new ConfigurationException("Unable to find bumpUpPriority.sh");
860851
}
861852

862-
_l2tpVpnPath = findScript("l2tp_vpn.sh");
863-
if (_l2tpVpnPath == null) {
864-
throw new ConfigurationException("Unable to find l2tp_vpn.sh");
865-
}
866-
867-
_getDomRVersionPath = findScript("getDomRVersion.sh");
868-
if(_getDomRVersionPath == null) {
869-
throw new ConfigurationException("Unable to find getDomRVersion.sh");
853+
_routerProxyPath = findScript("routerProxy.sh");
854+
if (_routerProxyPath == null) {
855+
throw new ConfigurationException("Unable to find routerProxy.sh");
870856
}
871857

872858
return true;

core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ protected synchronized Answer execute(final DhcpEntryCommand cmd) {
15881588

15891589
protected synchronized Answer execute(final RemoteAccessVpnCfgCommand cmd) {
15901590
Connection conn = getConnection();
1591-
String args = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
1591+
String args = "vpn_l2tp.sh " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
15921592
if (cmd.isCreate()) {
15931593
args += " -r " + cmd.getIpRange();
15941594
args += " -p " + cmd.getPresharedKey();
@@ -1600,7 +1600,7 @@ protected synchronized Answer execute(final RemoteAccessVpnCfgCommand cmd) {
16001600
args += " -d ";
16011601
args += " -s " + cmd.getVpnServerIp();
16021602
}
1603-
String result = callHostPlugin(conn, "vmops", "lt2p_vpn", "args", args);
1603+
String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args);
16041604
if (result == null || result.isEmpty()) {
16051605
return new Answer(cmd, false, "Configure VPN failed");
16061606
}

scripts/network/domr/l2tp_vpn.sh

Lines changed: 0 additions & 26 deletions
This file was deleted.

scripts/vm/hypervisor/xenserver/vmops

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -232,21 +232,6 @@ def saveDhcpEntry(session, args):
232232

233233
return txt
234234

235-
@echo
236-
def lt2p_vpn(session, args):
237-
sargs = args['args']
238-
cmd = sargs.split(' ')
239-
cmd.insert(0, "/opt/xensource/bin/l2tp_vpn.sh")
240-
cmd.insert(0, "/bin/bash")
241-
try:
242-
txt = util.pread2(cmd)
243-
txt = 'success'
244-
except:
245-
util.SMlog("l2tp vpn failed " )
246-
txt = ''
247-
248-
return txt
249-
250235
@echo
251236
def setLinkLocalIP(session, args):
252237
brName = args['brName']
@@ -1434,7 +1419,7 @@ if __name__ == "__main__":
14341419
"destroy_network_rules_for_vm":destroy_network_rules_for_vm,
14351420
"default_network_rules_systemvm":default_network_rules_systemvm,
14361421
"get_rule_logs_for_vms":get_rule_logs_for_vms,
1437-
"setLinkLocalIP":setLinkLocalIP, "lt2p_vpn":lt2p_vpn,
1422+
"setLinkLocalIP":setLinkLocalIP,
14381423
"cleanup_rules":cleanup_rules,
14391424
"bumpUpPriority":bumpUpPriority,
14401425
"kill_copy_process":kill_copy_process})

scripts/vm/hypervisor/xenserver/xcpserver/patch

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ vm_data.sh=../../../../network/domr/,0755,/opt/xensource/bin
2828
save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin
2929
call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin
3030
call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin
31-
l2tp_vpn.sh=../../../../network/domr/,0755,/opt/xensource/bin
3231
cloud-setup-bonding.sh=..,0755,/opt/xensource/bin
3332
copy_vhd_to_secondarystorage.sh=..,0755,/opt/xensource/bin
3433
copy_vhd_from_secondarystorage.sh=..,0755,/opt/xensource/bin

scripts/vm/hypervisor/xenserver/xenserver56/patch

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin
2727
call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin
2828
call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin
2929
router_proxy.sh=../../../../network/domr/,0755,/opt/xensource/bin
30-
l2tp_vpn.sh=../../../../network/domr/,0755,/opt/xensource/bin
3130
copy_vhd_to_secondarystorage.sh=..,0755,/opt/xensource/bin
3231
copy_vhd_from_secondarystorage.sh=..,0755,/opt/xensource/bin
3332
kill_copy_process.sh=..,0755,/opt/xensource/bin

scripts/vm/hypervisor/xenserver/xenserver56fp1/patch

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin
2626
call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin
2727
call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin
2828
router_proxy.sh=../../../../network/domr/,0755,/opt/xensource/bin
29-
l2tp_vpn.sh=../../../../network/domr/,0755,/opt/xensource/bin
3029
cloud-setup-bonding.sh=..,0755,/opt/xensource/bin
3130
copy_vhd_to_secondarystorage.sh=..,0755,/opt/xensource/bin
3231
copy_vhd_from_secondarystorage.sh=..,0755,/opt/xensource/bin

scripts/vm/hypervisor/xenserver/xenserver60/patch

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin
3131
call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin
3232
call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin
3333
router_proxy.sh=../../../../network/domr/,0755,/opt/xensource/bin
34-
l2tp_vpn.sh=../../../../network/domr/,0755,/opt/xensource/bin
3534
cloud-setup-bonding.sh=..,0755,/opt/xensource/bin
3635
copy_vhd_to_secondarystorage.sh=..,0755,/opt/xensource/bin
3736
copy_vhd_from_secondarystorage.sh=..,0755,/opt/xensource/bin

wscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# the following two variables are used by the target "waf dist"
55
# if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog
66

7-
VERSION = '3.0.3.2012-06-06T23:43:59Z'
7+
VERSION = '3.0.3.2012-06-07T00:17:43Z'
88
APPNAME = 'cloud'
99

1010
import shutil,os

0 commit comments

Comments
 (0)