diff --git a/patches/systemvm/debian/config/root/savepassword.sh b/patches/systemvm/debian/config/root/savepassword.sh new file mode 100755 index 00000000000..e756acb0c54 --- /dev/null +++ b/patches/systemvm/debian/config/root/savepassword.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Usage +# save_password -v -p +# + +while getopts 'v:p:' OPTION +do + case $OPTION in + v) VM_IP="$OPTARG" + ;; + p) + ENCODEDPASSWORD="$OPTARG" + PASSWORD=$(echo $ENCODEDPASSWORD | tr '[a-m][n-z][A-M][N-Z]' '[n-z][a-m][N-Z][A-M]') + ;; + ?) echo "Incorrect usage" + exit 1 + ;; + esac +done + +if [ ! -f /root/passwords ]; + then + touch /root/passwords; +fi + +sed -i /$VM_IP/d /root/passwords +echo "$VM_IP=$PASSWORD" >> /root/passwords + +if [ $? -ne 0 ] +then + exit 1 +fi + +exit 0 diff --git a/patches/systemvm/debian/config/root/userdata.py b/patches/systemvm/debian/config/root/userdata.py new file mode 100644 index 00000000000..db4776b40ca --- /dev/null +++ b/patches/systemvm/debian/config/root/userdata.py @@ -0,0 +1,64 @@ +#!/usr/bin/python + +import sys +import base64 + +def vm_data(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", "/root/userdata.sh", "-v", vm_ip, "-F", vmDataFolder, "-f", vmDataFile] + + fd = None + tmp_path = None + if (vmDataValue != "none"): + try: + fd,tmp_path = tempfile.mkstemp() + tmpfile = open(tmp_path, 'w') + + if (vmDataFolder == "userdata"): + vmDataValue = base64.urlsafe_b64decode(vmDataValue) + + 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 parseFileData(fileName): + args = [] + fd = open(fileName) + + line = fd.readline() + while (line != ""): + args.append(line) + line = fd.readline() + + return args + +vmdata(parseFileData("/tmp/" + sys.argv[1])) diff --git a/patches/systemvm/debian/config/root/userdata.sh b/patches/systemvm/debian/config/root/userdata.sh new file mode 100644 index 00000000000..ab4322ed918 --- /dev/null +++ b/patches/systemvm/debian/config/root/userdata.sh @@ -0,0 +1,106 @@ +#!/bin/bash + +usage() { + printf "Usage: %s: -v -F -f -d \n" $(basename $0) >&2 + exit 2 +} + +set -x + +PORT=3922 + +create_htaccess() { + local vmIp=$1 + local folder=$2 + local file=$3 + + local result=0 + + entry="RewriteRule ^$file$ ../$folder/%{REMOTE_ADDR}/$file [L,NC,QSA]" + htaccessFolder="/var/www/html/latest" + htaccessFile=$htaccessFolder/.htaccess + mkdir -p $htaccessFolder + touch $htaccessFile + grep -F \"$entry\" $htaccessFile + if [ \$? -gt 0 ]; then + echo -e \"$entry\" >> $htaccessFile; + fi + result=$? + + if [ $result -eq 0 ]; then + entry="Options -Indexes\\nOrder Deny,Allow\\nDeny from all\\nAllow from $vmIp" + htaccessFolder="/var/www/html/$folder/$vmIp" + htaccessFile=$htaccessFolder/.htaccess + + mkdir -p $htaccessFolder + echo -e \"$entry\" > $htaccessFile + result=$? + fi + + return $result +} + +copy_vm_data_file() { + local vmIp=$1 + local folder=$2 + local file=$3 + local dataFile=$4 + + chmod +r $dataFile + cp $dataFile /var/www/html/$folder/$vmIp/$file >/dev/null + return $? +} + +delete_vm_data_file() { + local domrIp=$1 + local vmIp=$2 + local folder=$3 + local file=$4 + + vmDataFilePath="/var/www/html/$folder/$vmIp/$file" + if [ -f $vmDataFilePath ]; then + rm -rf $vmDataFilePath + fi + return $? +} + +vmIp= +folder= +file= +dataFile= + +while getopts 'v:F:f:d:' OPTION +do + case $OPTION in + v) vmIp="$OPTARG" + ;; + F) folder="$OPTARG" + ;; + f) file="$OPTARG" + ;; + d) dataFile="$OPTARG" + ;; + ?) usage + exit 1 + ;; + esac +done + +[ "$vmIp" == "" ] || [ "$folder" == "" ] || [ "$file" == "" ] && usage +[ "$folder" != "userdata" ] && [ "$folder" != "metadata" ] && usage + +if [ "$dataFile" != "" ] +then + create_htaccess $vmIp $folder $file + + if [ $? -gt 0 ] + then + exit 1 + fi + + copy_vm_data_file $vmIp $folder $file $dataFile +else + delete_vm_data_file $vmIp $folder $file +fi + +exit $? diff --git a/server/src/com/cloud/network/router/DomainRouterManagerImpl.java b/server/src/com/cloud/network/router/DomainRouterManagerImpl.java index 2ea76d3af3b..3cf60624575 100644 --- a/server/src/com/cloud/network/router/DomainRouterManagerImpl.java +++ b/server/src/com/cloud/network/router/DomainRouterManagerImpl.java @@ -100,6 +100,7 @@ import com.cloud.ha.HighAvailabilityManager; import com.cloud.host.Host; import com.cloud.host.HostVO; import com.cloud.host.dao.HostDao; +import com.cloud.hypervisor.Hypervisor; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.FirewallRuleVO; import com.cloud.network.IPAddressVO; @@ -900,7 +901,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach String privateIpAddress = null; String privateNetMask = null; - if(_defaultHypervisorType == null || !_defaultHypervisorType.equalsIgnoreCase("VmWare")) { + if(_defaultHypervisorType == null || !_defaultHypervisorType.equalsIgnoreCase(Hypervisor.HypervisorType.VmWare.toString())) { privateIpAddress = _dcDao.allocateLinkLocalPrivateIpAddress(router.getDataCenterId(), routingHost.getPodId(), router.getId()); privateNetMask = NetUtils.getLinkLocalNetMask(); } else { @@ -994,7 +995,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach router.setPrivateIpAddress(null); - if(_defaultHypervisorType == null || !_defaultHypervisorType.equalsIgnoreCase("VmWare")) + if(_defaultHypervisorType == null || !_defaultHypervisorType.equalsIgnoreCase(Hypervisor.HypervisorType.VmWare.toString())) _dcDao.releaseLinkLocalPrivateIpAddress(privateIpAddress, router.getDataCenterId(), router.getId()); else _dcDao.releasePrivateIpAddress(privateIpAddress, router.getDataCenterId(), router.getId()); @@ -1407,7 +1408,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach String value = configs.get("start.retry"); _retry = NumbersUtil.parseInt(value, 2); - _defaultHypervisorType = (String)params.get(Config.HypervisorDefaultType.key()); + _defaultHypervisorType = _configDao.getValue(Config.HypervisorDefaultType.key()); value = configs.get("router.stats.interval"); _routerStatsInterval = NumbersUtil.parseInt(value, 300); @@ -1515,7 +1516,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach String privateIpAddress = router.getPrivateIpAddress(); if (privateIpAddress != null) { - if(_defaultHypervisorType == null || !_defaultHypervisorType.equalsIgnoreCase("VmWare")) + if(_defaultHypervisorType == null || !_defaultHypervisorType.equalsIgnoreCase(Hypervisor.HypervisorType.VmWare.toString())) _dcDao.releaseLinkLocalPrivateIpAddress(privateIpAddress, router.getDataCenterId(), router.getId()); else _dcDao.releasePrivateIpAddress(privateIpAddress, router.getDataCenterId(), router.getId());