Skip to content

Commit ac59a4f

Browse files
author
Marcus Sorensen
committed
Summary: Move Xen vmdata to new, non-ssh method
Detail: KVM recently got a patch that did away with a few dozen ssh calls when programming virtual router (CLOUDSTACK-3163), saving several seconds for each vm served by the virtual router when the router is rebooted. This patch updates Xen to use the same method, and cleans up the old script refs. Reviewed-by: Sheng Yang, Prasanna Santhanam
1 parent eea3bb8 commit ac59a4f

11 files changed

Lines changed: 13 additions & 273 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,6 @@ private Answer execute(LoadBalancerConfigCommand cmd) {
465465
}
466466

467467
protected Answer execute(VmDataCommand cmd) {
468-
List<String[]> vmData = cmd.getVmData();
469468
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
470469
Map<String, List<String[]>> data = new HashMap<String, List<String[]>>();
471470
data.put(cmd.getVmIpAddress(), cmd.getVmData());
@@ -477,7 +476,7 @@ protected Answer execute(VmDataCommand cmd) {
477476

478477
String args = "-d " + json;
479478

480-
final String result = routerProxy("vmdata_kvm.py", routerIp, args);
479+
final String result = routerProxy("vmdata.py", routerIp, args);
481480
if (result != null) {
482481
return new Answer(cmd, false, "VmDataCommand failed, check agent logs");
483482
}

patches/systemvm/debian/config/opt/cloud/bin/vmdata_kvm.py renamed to patches/systemvm/debian/config/opt/cloud/bin/vmdata.py

File renamed without changes.

plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package com.cloud.hypervisor.xen.resource;
1818

19+
import com.google.gson.Gson;
1920

2021
import java.beans.BeanInfo;
2122
import java.beans.IntrospectionException;
@@ -54,6 +55,7 @@
5455
import javax.xml.parsers.DocumentBuilderFactory;
5556

5657
import com.cloud.agent.api.to.DhcpTO;
58+
import org.apache.commons.codec.binary.Base64;
5759
import org.apache.log4j.Logger;
5860
import org.apache.xmlrpc.XmlRpcException;
5961
import org.w3c.dom.Document;
@@ -2220,25 +2222,14 @@ protected synchronized Answer execute(final VpnUsersCfgCommand cmd) {
22202222
protected Answer execute(final VmDataCommand cmd) {
22212223
Connection conn = getConnection();
22222224
String routerPrivateIpAddress = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
2223-
String vmIpAddress = cmd.getVmIpAddress();
2224-
List<String[]> vmData = cmd.getVmData();
2225-
String[] vmDataArgs = new String[vmData.size() * 2 + 4];
2226-
vmDataArgs[0] = "routerIP";
2227-
vmDataArgs[1] = routerPrivateIpAddress;
2228-
vmDataArgs[2] = "vmIP";
2229-
vmDataArgs[3] = vmIpAddress;
2230-
int i = 4;
2231-
for (String[] vmDataEntry : vmData) {
2232-
String folder = vmDataEntry[0];
2233-
String file = vmDataEntry[1];
2234-
String contents = (vmDataEntry[2] != null) ? vmDataEntry[2] : "none";
2235-
2236-
vmDataArgs[i] = folder + "," + file;
2237-
vmDataArgs[i + 1] = contents;
2238-
i += 2;
2239-
}
2240-
2241-
String result = callHostPlugin(conn, "vmops", "vm_data", vmDataArgs);
2225+
Map<String, List<String[]>> data = new HashMap<String, List<String[]>>();
2226+
data.put(cmd.getVmIpAddress(), cmd.getVmData());
2227+
String json = new Gson().toJson(data);
2228+
json = Base64.encodeBase64String(json.getBytes());
2229+
2230+
String args = "vmdata.py " + routerPrivateIpAddress + " -d " + json;
2231+
2232+
String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args);
22422233

22432234
if (result == null || result.isEmpty()) {
22442235
return new Answer(cmd, false, "vm_data failed");

scripts/network/domr/vm_data.sh

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

scripts/vm/hypervisor/xenserver/vmops

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -168,55 +168,6 @@ def pingxenserver(session, args):
168168
txt = 'success'
169169
return txt
170170

171-
@echo
172-
def vm_data(session, args):
173-
router_ip = args.pop('routerIP')
174-
vm_ip = args.pop('vmIP')
175-
176-
util.SMlog(" adding vmdata for VM with IP: " + vm_ip + " to router with IP: " + router_ip)
177-
178-
for pair in args:
179-
pairList = pair.split(',')
180-
vmDataFolder = pairList[0]
181-
vmDataFile = pairList[1]
182-
vmDataValue = args[pair]
183-
cmd = ["/bin/bash", "/opt/xensource/bin/vm_data.sh", "-r", router_ip, "-v", vm_ip, "-F", vmDataFolder, "-f", vmDataFile]
184-
185-
fd = None
186-
tmp_path = None
187-
188-
try:
189-
fd,tmp_path = tempfile.mkstemp()
190-
tmpfile = open(tmp_path, 'w')
191-
192-
if vmDataFolder == "userdata" and vmDataValue != "none":
193-
vmDataValue = base64.urlsafe_b64decode(vmDataValue)
194-
195-
if vmDataValue != "none":
196-
tmpfile.write(vmDataValue)
197-
198-
tmpfile.close()
199-
cmd.append("-d")
200-
cmd.append(tmp_path)
201-
except:
202-
util.SMlog(" vmdata failed to write tempfile " )
203-
os.close(fd)
204-
os.remove(tmp_path)
205-
return ''
206-
207-
try:
208-
txt = util.pread2(cmd)
209-
txt = 'success'
210-
except:
211-
util.SMlog(" vmdata failed with folder: " + vmDataFolder + " and file: " + vmDataFile)
212-
txt = ''
213-
214-
if (fd != None):
215-
os.close(fd)
216-
os.remove(tmp_path)
217-
218-
return txt
219-
220171
def pingtest(session, args):
221172
sargs = args['args']
222173
cmd = sargs.split(' ')
@@ -1714,7 +1665,7 @@ if __name__ == "__main__":
17141665
XenAPIPlugin.dispatch({"pingtest": pingtest, "setup_iscsi":setup_iscsi, "gethostvmstats": gethostvmstats,
17151666
"getvncport": getvncport, "getgateway": getgateway, "preparemigration": preparemigration,
17161667
"setIptables": setIptables, "pingdomr": pingdomr, "pingxenserver": pingxenserver,
1717-
"vm_data": vm_data, "savePassword": savePassword,
1668+
"savePassword": savePassword,
17181669
"saveDhcpEntry": saveDhcpEntry, "setFirewallRule": setFirewallRule, "routerProxy": routerProxy,
17191670
"setLoadBalancerRule": setLoadBalancerRule, "createFile": createFile, "deleteFile": deleteFile,
17201671
"network_rules":network_rules,

scripts/vm/hypervisor/xenserver/xcposs/patch

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ setup_iscsi.sh=..,0755,/usr/lib/xcp/bin
4141
pingtest.sh=../../..,0755,/usr/lib/xcp/bin
4242
dhcp_entry.sh=../../../../network/domr/,0755,/usr/lib/xcp/bin
4343
ipassoc.sh=../../../../network/domr/,0755,/usr/lib/xcp/bin
44-
vm_data.sh=../../../../network/domr/,0755,/usr/lib/xcp/bin
4544
save_password_to_domr.sh=../../../../network/domr/,0755,/usr/lib/xcp/bin
4645
networkUsage.sh=../../../../network/domr/,0755,/usr/lib/xcp/bin
4746
call_firewall.sh=../../../../network/domr/,0755,/usr/lib/xcp/bin

scripts/vm/hypervisor/xenserver/xcposs/vmops

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -171,55 +171,6 @@ def ipassoc(session, args):
171171

172172
return txt
173173

174-
@echo
175-
def vm_data(session, args):
176-
router_ip = args.pop('routerIP')
177-
vm_ip = args.pop('vmIP')
178-
179-
util.SMlog(" adding vmdata for VM with IP: " + vm_ip + " to router with IP: " + router_ip)
180-
181-
for pair in args:
182-
pairList = pair.split(',')
183-
vmDataFolder = pairList[0]
184-
vmDataFile = pairList[1]
185-
vmDataValue = args[pair]
186-
cmd = ["/bin/bash", "/usr/lib/xcp/bin/vm_data.sh", "-r", router_ip, "-v", vm_ip, "-F", vmDataFolder, "-f", vmDataFile]
187-
188-
fd = None
189-
tmp_path = None
190-
191-
try:
192-
fd,tmp_path = tempfile.mkstemp()
193-
tmpfile = open(tmp_path, 'w')
194-
195-
if vmDataFolder == "userdata" and vmDataValue != "none":
196-
vmDataValue = base64.urlsafe_b64decode(vmDataValue)
197-
198-
if vmDataValue != "none":
199-
tmpfile.write(vmDataValue)
200-
201-
tmpfile.close()
202-
cmd.append("-d")
203-
cmd.append(tmp_path)
204-
except:
205-
util.SMlog(" vmdata failed to write tempfile " )
206-
os.close(fd)
207-
os.remove(tmp_path)
208-
return ''
209-
210-
try:
211-
txt = util.pread2(cmd)
212-
txt = 'success'
213-
except:
214-
util.SMlog(" vmdata failed with folder: " + vmDataFolder + " and file: " + vmDataFile)
215-
txt = ''
216-
217-
if (fd != None):
218-
os.close(fd)
219-
os.remove(tmp_path)
220-
221-
return txt
222-
223174
def pingtest(session, args):
224175
sargs = args['args']
225176
cmd = sargs.split(' ')
@@ -1549,7 +1500,7 @@ if __name__ == "__main__":
15491500
XenAPIPlugin.dispatch({"pingtest": pingtest, "setup_iscsi":setup_iscsi, "gethostvmstats": gethostvmstats,
15501501
"getvncport": getvncport, "getgateway": getgateway, "preparemigration": preparemigration,
15511502
"setIptables": setIptables, "pingdomr": pingdomr, "pingxenserver": pingxenserver,
1552-
"ipassoc": ipassoc, "vm_data": vm_data, "savePassword": savePassword,
1503+
"ipassoc": ipassoc, "savePassword": savePassword,
15531504
"saveDhcpEntry": saveDhcpEntry, "setFirewallRule": setFirewallRule,
15541505
"setLoadBalancerRule": setLoadBalancerRule, "createFile": createFile, "deleteFile": deleteFile,
15551506
"networkUsage": networkUsage, "network_rules":network_rules,

scripts/vm/hypervisor/xenserver/xcpserver/patch

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ dhcp_entry.sh=../../../../network/domr/,0755,/opt/xensource/bin
4343
createipAlias.sh=..,0755,/opt/xensource/bin
4444
deleteipAlias.sh=..,0755,/opt/xensource/bin
4545
router_proxy.sh=../../../../network/domr/,0755,/opt/xensource/bin
46-
vm_data.sh=../../../../network/domr/,0755,/opt/xensource/bin
4746
save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin
4847
call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin
4948
call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin

scripts/vm/hypervisor/xenserver/xenserver56/patch

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ pingtest.sh=../../..,0755,/opt/xensource/bin
4141
createipAlias.sh=..,0755,/opt/xensource/bin
4242
deleteipAlias.sh=..,0755,/opt/xensource/bin
4343
dhcp_entry.sh=../../../../network/domr/,0755,/opt/xensource/bin
44-
vm_data.sh=../../../../network/domr/,0755,/opt/xensource/bin
4544
save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin
4645
call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin
4746
call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin

scripts/vm/hypervisor/xenserver/xenserver56fp1/patch

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ pingtest.sh=../../..,0755,/opt/xensource/bin
4040
createipAlias.sh=..,0755,/opt/xensource/bin
4141
deleteipAlias.sh=..,0755,/opt/xensource/bin
4242
dhcp_entry.sh=../../../../network/domr/,0755,/opt/xensource/bin
43-
vm_data.sh=../../../../network/domr/,0755,/opt/xensource/bin
4443
save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin
4544
call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin
4645
call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin

0 commit comments

Comments
 (0)