mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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
This commit is contained in:
parent
eea3bb84d5
commit
ac59a4f136
@ -465,7 +465,6 @@ public class VirtualRoutingResource implements Manager {
|
||||
}
|
||||
|
||||
protected Answer execute(VmDataCommand cmd) {
|
||||
List<String[]> vmData = cmd.getVmData();
|
||||
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
|
||||
Map<String, List<String[]>> data = new HashMap<String, List<String[]>>();
|
||||
data.put(cmd.getVmIpAddress(), cmd.getVmData());
|
||||
@ -477,7 +476,7 @@ public class VirtualRoutingResource implements Manager {
|
||||
|
||||
String args = "-d " + json;
|
||||
|
||||
final String result = routerProxy("vmdata_kvm.py", routerIp, args);
|
||||
final String result = routerProxy("vmdata.py", routerIp, args);
|
||||
if (result != null) {
|
||||
return new Answer(cmd, false, "VmDataCommand failed, check agent logs");
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
// under the License.
|
||||
package com.cloud.hypervisor.xen.resource;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
@ -54,6 +55,7 @@ import javax.naming.ConfigurationException;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import com.cloud.agent.api.to.DhcpTO;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.xmlrpc.XmlRpcException;
|
||||
import org.w3c.dom.Document;
|
||||
@ -2220,25 +2222,14 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
||||
protected Answer execute(final VmDataCommand cmd) {
|
||||
Connection conn = getConnection();
|
||||
String routerPrivateIpAddress = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
|
||||
String vmIpAddress = cmd.getVmIpAddress();
|
||||
List<String[]> vmData = cmd.getVmData();
|
||||
String[] vmDataArgs = new String[vmData.size() * 2 + 4];
|
||||
vmDataArgs[0] = "routerIP";
|
||||
vmDataArgs[1] = routerPrivateIpAddress;
|
||||
vmDataArgs[2] = "vmIP";
|
||||
vmDataArgs[3] = vmIpAddress;
|
||||
int i = 4;
|
||||
for (String[] vmDataEntry : vmData) {
|
||||
String folder = vmDataEntry[0];
|
||||
String file = vmDataEntry[1];
|
||||
String contents = (vmDataEntry[2] != null) ? vmDataEntry[2] : "none";
|
||||
Map<String, List<String[]>> data = new HashMap<String, List<String[]>>();
|
||||
data.put(cmd.getVmIpAddress(), cmd.getVmData());
|
||||
String json = new Gson().toJson(data);
|
||||
json = Base64.encodeBase64String(json.getBytes());
|
||||
|
||||
vmDataArgs[i] = folder + "," + file;
|
||||
vmDataArgs[i + 1] = contents;
|
||||
i += 2;
|
||||
}
|
||||
String args = "vmdata.py " + routerPrivateIpAddress + " -d " + json;
|
||||
|
||||
String result = callHostPlugin(conn, "vmops", "vm_data", vmDataArgs);
|
||||
String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args);
|
||||
|
||||
if (result == null || result.isEmpty()) {
|
||||
return new Answer(cmd, false, "vm_data failed");
|
||||
|
||||
@ -1,147 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
# $Id: vm_data.sh 9307 2010-06-08 00:43:08Z chiradeep $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/vm/hypervisor/xenserver/patch/vm_data.sh $
|
||||
# @VERSION@
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -r <domr-ip> -v <vm ip> -F <vm data folder> -f <vm data file> -d <data to put in file> \n" $(basename $0) >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
set -x
|
||||
cert="/root/.ssh/id_rsa.cloud"
|
||||
PORT=3922
|
||||
|
||||
create_htaccess() {
|
||||
local domrIp=$1
|
||||
local vmIp=$2
|
||||
local folder=$3
|
||||
local file=$4
|
||||
|
||||
local result=0
|
||||
#rewrite rule in top level /latest folder to redirect
|
||||
#to vm specific folder based on source ip
|
||||
entry="RewriteRule ^$file$ ../$folder/%{REMOTE_ADDR}/$file [L,NC,QSA]"
|
||||
htaccessFolder="/var/www/html/latest"
|
||||
htaccessFile=$htaccessFolder/.htaccess
|
||||
ssh -p $PORT -o StrictHostKeyChecking=no -i $cert root@$domrIp "mkdir -p $htaccessFolder; touch $htaccessFile; grep -F \"$entry\" $htaccessFile; if [ \$? -gt 0 ]; then echo -e \"$entry\" >> $htaccessFile; fi" >/dev/null
|
||||
result=$?
|
||||
|
||||
if [ $result -eq 0 ]
|
||||
then
|
||||
#ensure that vm specific folder cannot be listed and that only
|
||||
#the vm that owns the data can access the items in this directory
|
||||
entry="Options -Indexes\\nOrder Deny,Allow\\nDeny from all\\nAllow from $vmIp"
|
||||
htaccessFolder="/var/www/html/$folder/$vmIp"
|
||||
htaccessFile=$htaccessFolder/.htaccess
|
||||
ssh -p $PORT -o StrictHostKeyChecking=no -i $cert root@$domrIp "mkdir -p $htaccessFolder; echo -e \"$entry\" > $htaccessFile" >/dev/null
|
||||
result=$?
|
||||
fi
|
||||
|
||||
#support access by http://<dhcp server>/latest/<metadata key> (legacy, see above) also
|
||||
# http://<dhcp server>/latest/meta-data/<metadata key> (correct)
|
||||
if [ "$folder" == "metadata" ] || [ "$folder" == "meta-data" ]
|
||||
then
|
||||
entry="RewriteRule ^meta-data/(.+)$ ../$folder/%{REMOTE_ADDR}/\\\$1 [L,NC,QSA]"
|
||||
htaccessFolder="/var/www/html/latest"
|
||||
htaccessFile=$htaccessFolder/.htaccess
|
||||
ssh -p $PORT -o StrictHostKeyChecking=no -i $cert root@$domrIp "grep -F \"$entry\" $htaccessFile; if [ \$? -gt 0 ]; then echo -e \"$entry\" >> $htaccessFile; fi" >/dev/null
|
||||
entry="RewriteRule ^meta-data/$ ../$folder/%{REMOTE_ADDR}/meta-data [L,NC,QSA]"
|
||||
ssh -p $PORT -o StrictHostKeyChecking=no -i $cert root@$domrIp "grep -F \"$entry\" $htaccessFile; if [ \$? -gt 0 ]; then echo -e \"$entry\" >> $htaccessFile; fi" >/dev/null
|
||||
result=$?
|
||||
fi
|
||||
|
||||
return $result
|
||||
}
|
||||
|
||||
copy_vm_data_file() {
|
||||
local domrIp=$1
|
||||
local vmIp=$2
|
||||
local folder=$3
|
||||
local file=$4
|
||||
local dataFile=$5
|
||||
|
||||
dest=/var/www/html/$folder/$vmIp/$file
|
||||
metamanifest=/var/www/html/$folder/$vmIp/meta-data
|
||||
scp -P $PORT -o StrictHostKeyChecking=no -i $cert $dataFile root@$domrIp:$dest >/dev/null
|
||||
ssh -p $PORT -o StrictHostKeyChecking=no -i $cert root@$domrIp "chmod 644 $dest" > /dev/null
|
||||
ssh -p $PORT -o StrictHostKeyChecking=no -i $cert root@$domrIp "touch $metamanifest; chmod 644 $metamanifest" > /dev/null
|
||||
if [ "$folder" == "metadata" ] || [ "$folder" == "meta-data" ]
|
||||
then
|
||||
ssh -p $PORT -o StrictHostKeyChecking=no -i $cert root@$domrIp "sed -i '/$file/d' $metamanifest; echo $file >> $metamanifest" > /dev/null
|
||||
fi
|
||||
|
||||
return $?
|
||||
}
|
||||
|
||||
delete_vm_data_file() {
|
||||
local domrIp=$1
|
||||
local vmIp=$2
|
||||
local folder=$3
|
||||
local file=$4
|
||||
|
||||
vmDataFilePath="/var/www/html/$folder/$vmIp/$file"
|
||||
ssh -p $PORT -o StrictHostKeyChecking=no -i $cert root@$domrIp "if [ -f $vmDataFilePath ]; then rm -rf $vmDataFilePath; fi" >/dev/null
|
||||
return $?
|
||||
}
|
||||
|
||||
domrIp=
|
||||
vmIp=
|
||||
folder=
|
||||
file=
|
||||
dataFile=
|
||||
|
||||
while getopts 'r:v:F:f:d:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
r) domrIp="$OPTARG"
|
||||
;;
|
||||
v) vmIp="$OPTARG"
|
||||
;;
|
||||
F) folder="$OPTARG"
|
||||
;;
|
||||
f) file="$OPTARG"
|
||||
;;
|
||||
d) dataFile="$OPTARG"
|
||||
;;
|
||||
?) usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
[ "$domrIp" == "" ] || [ "$vmIp" == "" ] || [ "$folder" == "" ] || [ "$file" == "" ] && usage
|
||||
[ "$folder" != "userdata" ] && [ "$folder" != "metadata" ] && usage
|
||||
|
||||
if [ "$dataFile" != "" ]
|
||||
then
|
||||
create_htaccess $domrIp $vmIp $folder $file
|
||||
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
copy_vm_data_file $domrIp $vmIp $folder $file $dataFile
|
||||
else
|
||||
delete_vm_data_file $domrIp $vmIp $folder $file
|
||||
fi
|
||||
|
||||
exit $?
|
||||
@ -168,55 +168,6 @@ def pingxenserver(session, args):
|
||||
txt = 'success'
|
||||
return txt
|
||||
|
||||
@echo
|
||||
def vm_data(session, args):
|
||||
router_ip = args.pop('routerIP')
|
||||
vm_ip = args.pop('vmIP')
|
||||
|
||||
util.SMlog(" adding vmdata for VM with IP: " + vm_ip + " to router with IP: " + router_ip)
|
||||
|
||||
for pair in args:
|
||||
pairList = pair.split(',')
|
||||
vmDataFolder = pairList[0]
|
||||
vmDataFile = pairList[1]
|
||||
vmDataValue = args[pair]
|
||||
cmd = ["/bin/bash", "/opt/xensource/bin/vm_data.sh", "-r", router_ip, "-v", vm_ip, "-F", vmDataFolder, "-f", vmDataFile]
|
||||
|
||||
fd = None
|
||||
tmp_path = None
|
||||
|
||||
try:
|
||||
fd,tmp_path = tempfile.mkstemp()
|
||||
tmpfile = open(tmp_path, 'w')
|
||||
|
||||
if vmDataFolder == "userdata" and vmDataValue != "none":
|
||||
vmDataValue = base64.urlsafe_b64decode(vmDataValue)
|
||||
|
||||
if vmDataValue != "none":
|
||||
tmpfile.write(vmDataValue)
|
||||
|
||||
tmpfile.close()
|
||||
cmd.append("-d")
|
||||
cmd.append(tmp_path)
|
||||
except:
|
||||
util.SMlog(" vmdata failed to write tempfile " )
|
||||
os.close(fd)
|
||||
os.remove(tmp_path)
|
||||
return ''
|
||||
|
||||
try:
|
||||
txt = util.pread2(cmd)
|
||||
txt = 'success'
|
||||
except:
|
||||
util.SMlog(" vmdata failed with folder: " + vmDataFolder + " and file: " + vmDataFile)
|
||||
txt = ''
|
||||
|
||||
if (fd != None):
|
||||
os.close(fd)
|
||||
os.remove(tmp_path)
|
||||
|
||||
return txt
|
||||
|
||||
def pingtest(session, args):
|
||||
sargs = args['args']
|
||||
cmd = sargs.split(' ')
|
||||
@ -1714,7 +1665,7 @@ if __name__ == "__main__":
|
||||
XenAPIPlugin.dispatch({"pingtest": pingtest, "setup_iscsi":setup_iscsi, "gethostvmstats": gethostvmstats,
|
||||
"getvncport": getvncport, "getgateway": getgateway, "preparemigration": preparemigration,
|
||||
"setIptables": setIptables, "pingdomr": pingdomr, "pingxenserver": pingxenserver,
|
||||
"vm_data": vm_data, "savePassword": savePassword,
|
||||
"savePassword": savePassword,
|
||||
"saveDhcpEntry": saveDhcpEntry, "setFirewallRule": setFirewallRule, "routerProxy": routerProxy,
|
||||
"setLoadBalancerRule": setLoadBalancerRule, "createFile": createFile, "deleteFile": deleteFile,
|
||||
"network_rules":network_rules,
|
||||
|
||||
@ -41,7 +41,6 @@ setup_iscsi.sh=..,0755,/usr/lib/xcp/bin
|
||||
pingtest.sh=../../..,0755,/usr/lib/xcp/bin
|
||||
dhcp_entry.sh=../../../../network/domr/,0755,/usr/lib/xcp/bin
|
||||
ipassoc.sh=../../../../network/domr/,0755,/usr/lib/xcp/bin
|
||||
vm_data.sh=../../../../network/domr/,0755,/usr/lib/xcp/bin
|
||||
save_password_to_domr.sh=../../../../network/domr/,0755,/usr/lib/xcp/bin
|
||||
networkUsage.sh=../../../../network/domr/,0755,/usr/lib/xcp/bin
|
||||
call_firewall.sh=../../../../network/domr/,0755,/usr/lib/xcp/bin
|
||||
|
||||
@ -171,55 +171,6 @@ def ipassoc(session, args):
|
||||
|
||||
return txt
|
||||
|
||||
@echo
|
||||
def vm_data(session, args):
|
||||
router_ip = args.pop('routerIP')
|
||||
vm_ip = args.pop('vmIP')
|
||||
|
||||
util.SMlog(" adding vmdata for VM with IP: " + vm_ip + " to router with IP: " + router_ip)
|
||||
|
||||
for pair in args:
|
||||
pairList = pair.split(',')
|
||||
vmDataFolder = pairList[0]
|
||||
vmDataFile = pairList[1]
|
||||
vmDataValue = args[pair]
|
||||
cmd = ["/bin/bash", "/usr/lib/xcp/bin/vm_data.sh", "-r", router_ip, "-v", vm_ip, "-F", vmDataFolder, "-f", vmDataFile]
|
||||
|
||||
fd = None
|
||||
tmp_path = None
|
||||
|
||||
try:
|
||||
fd,tmp_path = tempfile.mkstemp()
|
||||
tmpfile = open(tmp_path, 'w')
|
||||
|
||||
if vmDataFolder == "userdata" and vmDataValue != "none":
|
||||
vmDataValue = base64.urlsafe_b64decode(vmDataValue)
|
||||
|
||||
if vmDataValue != "none":
|
||||
tmpfile.write(vmDataValue)
|
||||
|
||||
tmpfile.close()
|
||||
cmd.append("-d")
|
||||
cmd.append(tmp_path)
|
||||
except:
|
||||
util.SMlog(" vmdata failed to write tempfile " )
|
||||
os.close(fd)
|
||||
os.remove(tmp_path)
|
||||
return ''
|
||||
|
||||
try:
|
||||
txt = util.pread2(cmd)
|
||||
txt = 'success'
|
||||
except:
|
||||
util.SMlog(" vmdata failed with folder: " + vmDataFolder + " and file: " + vmDataFile)
|
||||
txt = ''
|
||||
|
||||
if (fd != None):
|
||||
os.close(fd)
|
||||
os.remove(tmp_path)
|
||||
|
||||
return txt
|
||||
|
||||
def pingtest(session, args):
|
||||
sargs = args['args']
|
||||
cmd = sargs.split(' ')
|
||||
@ -1549,7 +1500,7 @@ if __name__ == "__main__":
|
||||
XenAPIPlugin.dispatch({"pingtest": pingtest, "setup_iscsi":setup_iscsi, "gethostvmstats": gethostvmstats,
|
||||
"getvncport": getvncport, "getgateway": getgateway, "preparemigration": preparemigration,
|
||||
"setIptables": setIptables, "pingdomr": pingdomr, "pingxenserver": pingxenserver,
|
||||
"ipassoc": ipassoc, "vm_data": vm_data, "savePassword": savePassword,
|
||||
"ipassoc": ipassoc, "savePassword": savePassword,
|
||||
"saveDhcpEntry": saveDhcpEntry, "setFirewallRule": setFirewallRule,
|
||||
"setLoadBalancerRule": setLoadBalancerRule, "createFile": createFile, "deleteFile": deleteFile,
|
||||
"networkUsage": networkUsage, "network_rules":network_rules,
|
||||
|
||||
@ -43,7 +43,6 @@ dhcp_entry.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
createipAlias.sh=..,0755,/opt/xensource/bin
|
||||
deleteipAlias.sh=..,0755,/opt/xensource/bin
|
||||
router_proxy.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
vm_data.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
|
||||
@ -41,7 +41,6 @@ pingtest.sh=../../..,0755,/opt/xensource/bin
|
||||
createipAlias.sh=..,0755,/opt/xensource/bin
|
||||
deleteipAlias.sh=..,0755,/opt/xensource/bin
|
||||
dhcp_entry.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
vm_data.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
|
||||
@ -40,7 +40,6 @@ pingtest.sh=../../..,0755,/opt/xensource/bin
|
||||
createipAlias.sh=..,0755,/opt/xensource/bin
|
||||
deleteipAlias.sh=..,0755,/opt/xensource/bin
|
||||
dhcp_entry.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
vm_data.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
|
||||
@ -45,7 +45,6 @@ deleteipAlias.sh=..,0755,/opt/xensource/bin
|
||||
setup_iscsi.sh=..,0755,/opt/xensource/bin
|
||||
pingtest.sh=../../..,0755,/opt/xensource/bin
|
||||
dhcp_entry.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
vm_data.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
save_password_to_domr.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
call_firewall.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
call_loadbalancer.sh=../../../../network/domr/,0755,/opt/xensource/bin
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user