Merge branch '2.2.y' of ssh://git.cloud.com/var/lib/git/cloudstack-oss into 2.2.y

This commit is contained in:
anthony 2012-01-30 16:45:13 -08:00
commit d7967b7afe
11 changed files with 190 additions and 75 deletions

View File

@ -583,9 +583,9 @@ public class VirtualRoutingResource implements Manager {
}
String cidrSize = Long.toString(NetUtils.getCidrSize(vlanNetmask));
if (sourceNat) {
command.add("-f");
command.add("-l", publicIpAddress + "/" + cidrSize);
} else if (firstIP) {
command.add("-s");
}
if (firstIP) {
command.add( "-f");
command.add( "-l", publicIpAddress + "/" + cidrSize);
} else {

View File

@ -16,6 +16,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -252,6 +253,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
protected float _memOverprovisioningFactor = 1;
protected boolean _reserveMem = false;
protected boolean _recycleHungWorker = false;
protected DiskControllerType _rootDiskController = DiskControllerType.ide;
protected ManagedObjectReference _morHyperHost;
@ -727,10 +729,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
}
String cidrSize = Long.toString(NetUtils.getCidrSize(vlanNetmask));
if (sourceNat) {
args += " -f ";
args += " -l ";
args += publicIpAddress + "/" + cidrSize;
} else if (firstIP) {
args += " -s ";
}
if (firstIP) {
args += " -f ";
args += " -l ";
args += publicIpAddress + "/" + cidrSize;
@ -3084,6 +3085,54 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
if(hyperHost.isHyperHostConnected()) {
mgr.gcLeftOverVMs(context);
if(_recycleHungWorker) {
s_logger.info("Scan hung worker VM to recycle");
// GC worker that has been running for too long
ObjectContent[] ocs = hyperHost.getVmPropertiesOnHyperHost(
new String[] {"name", "config.template", "runtime.powerState", "runtime.bootTime"});
if(ocs != null) {
for(ObjectContent oc : ocs) {
DynamicProperty[] props = oc.getPropSet();
if(props != null) {
String name = null;
boolean template = false;
VirtualMachinePowerState powerState = VirtualMachinePowerState.poweredOff;
GregorianCalendar bootTime = null;
for(DynamicProperty prop : props) {
if(prop.getName().equals("name"))
name = prop.getVal().toString();
else if(prop.getName().equals("config.template"))
template = (Boolean)prop.getVal();
else if(prop.getName().equals("runtime.powerState"))
powerState = (VirtualMachinePowerState)prop.getVal();
else if(prop.getName().equals("runtime.bootTime"))
bootTime = (GregorianCalendar)prop.getVal();
}
if(!template && name.matches("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")) {
boolean recycle = false;
// recycle stopped worker VM and VM that has been running for too long (hard-coded 10 hours for now)
if(powerState == VirtualMachinePowerState.poweredOff)
recycle = true;
else if(bootTime != null && (new Date().getTime() - bootTime.getTimeInMillis() > 10*3600*1000))
recycle = true;
if(recycle) {
s_logger.info("Recycle pending worker VM: " + name);
VirtualMachineMO vmMo = new VirtualMachineMO(hyperHost.getContext(), oc.getObj());
vmMo.powerOff();
vmMo.destroy();
}
}
}
}
}
}
} else {
s_logger.error("Host is no longer connected.");
return null;
@ -3281,7 +3330,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
details.put("NativeHA", "true");
}
}
protected HashMap<String, State> sync() {
HashMap<String, State> changes = new HashMap<String, State>();
HashMap<String, State> oldStates = null;
@ -3851,22 +3900,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
_cluster = (String) params.get("cluster");
_guid = (String) params.get("guid");
String value = (String) params.get("cpu.overprovisioning.factor");
if(value != null)
_cpuOverprovisioningFactor = Float.parseFloat(value);
value = (String) params.get("vmware.reserve.cpu");
if(value != null && value.equalsIgnoreCase("true"))
_reserveCpu = true;
value = (String) params.get("mem.overprovisioning.factor");
if(value != null)
_memOverprovisioningFactor = Float.parseFloat(value);
value = (String) params.get("vmware.reserve.mem");
if(value != null && value.equalsIgnoreCase("true"))
_reserveMem = true;
String[] tokens = _guid.split("@");
_vCenterAddress = tokens[1];
_morHyperHost = new ManagedObjectReference();
@ -3895,6 +3928,26 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
_publicNetworkVSwitchName = (String) params.get("public.network.vswitch.name");
_guestNetworkVSwitchName = (String) params.get("guest.network.vswitch.name");
String value = (String) params.get("cpu.overprovisioning.factor");
if(value != null)
_cpuOverprovisioningFactor = Float.parseFloat(value);
value = (String) params.get("vmware.reserve.cpu");
if(value != null && value.equalsIgnoreCase("true"))
_reserveCpu = true;
value = (String) params.get("vmware.recycle.hung.wokervm");
if(value != null && value.equalsIgnoreCase("true"))
_recycleHungWorker = true;
value = (String) params.get("mem.overprovisioning.factor");
if(value != null)
_memOverprovisioningFactor = Float.parseFloat(value);
value = (String) params.get("vmware.reserve.mem");
if(value != null && value.equalsIgnoreCase("true"))
_reserveMem = true;
value = (String)params.get("vmware.root.disk.controller");
if(value != null && value.equalsIgnoreCase("scsi"))
_rootDiskController = DiskControllerType.scsi;

View File

@ -1584,10 +1584,9 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
}
String cidrSize = Long.toString(NetUtils.getCidrSize(vlanNetmask));
if (sourceNat) {
args += " -f";
args += " -l ";
args += publicIpAddress + "/" + cidrSize;
} else if (firstIP) {
args += " -s";
}
if (firstIP) {
args += " -f";
args += " -l ";
args += publicIpAddress + "/" + cidrSize;

View File

@ -4,13 +4,17 @@
package com.cloud.hypervisor.vmware.mo;
import java.util.GregorianCalendar;
import org.apache.log4j.Logger;
import com.cloud.hypervisor.vmware.util.VmwareContext;
import com.cloud.serializer.GsonHelper;
import com.cloud.utils.testcase.Log4jEnabledTestCase;
import com.google.gson.Gson;
import com.vmware.vim25.DynamicProperty;
import com.vmware.vim25.ManagedObjectReference;
import com.vmware.vim25.ObjectContent;
import com.vmware.vim25.VirtualMachineConfigSpec;
// This test case needs a particular setup, only used for my own test
@ -22,11 +26,31 @@ public class TestVmwareMO extends Log4jEnabledTestCase {
VmwareContext context = TestVmwareContextFactory.create(
"10.223.80.29", "Administrator", "Suite219");
HostMO hostMo = new HostMO(context, "HostSystem", "host-9");
System.out.println("host Type " + hostMo.getHostType());
Gson gson = GsonHelper.getGsonLogger();
System.out.println(gson.toJson(hostMo.getHostFirewallSystemMO().getFirewallInfo()));
HostMO hostMo = new HostMO(context, "HostSystem", "host-10");
ObjectContent[] ocs = hostMo.getVmPropertiesOnHyperHost(new String[] {"name", "config.template", "runtime.bootTime"});
if(ocs != null) {
for(ObjectContent oc : ocs) {
DynamicProperty[] props = oc.getPropSet();
if(props != null) {
String name = null;
boolean template = false;
GregorianCalendar bootTime = null;
for(DynamicProperty prop : props) {
if(prop.getName().equals("name"))
name = prop.getVal().toString();
else if(prop.getName().equals("config.template"))
template = (Boolean)prop.getVal();
else if(prop.getName().equals("runtime.bootTime"))
bootTime = (GregorianCalendar)prop.getVal();
}
System.out.println("name: " + name + ", template: " + template + ", bootTime: " + bootTime);
}
System.out.println("");
}
}
context.close();
} catch(Exception e) {

View File

@ -1,29 +1,26 @@
#!/usr/bin/env bash
# Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
#
# This software is licensed under the GNU General Public License v3 or later.
#
# It is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
#
# This software is licensed under the GNU General Public License v3 or later.
#
# It is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# $Id: ipassoc.sh 9804 2010-06-22 18:36:49Z alex $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/network/domr/ipassoc.sh $
# ipassoc.sh -- associate/disassociate a public ip with an instance
#
#
# @VERSION@
source /root/func.sh
@ -207,10 +204,33 @@ add_routing() {
fi
return 0;
}
add_snat() {
if [ "$sflag" == "0" ]
then
return 0;
fi
add_nat_entry() {
local pubIp=$1
logger -t cloud "$(basename $0):Adding nat entry for ip $pubIp on interface $ethDev"
local ipNoMask=$(echo $1 | awk -F'/' '{print $1}')
logger -t cloud "$(basename $0):Added SourceNAT $pubIp on interface $ethDev"
sudo iptables -t nat -D POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask ;
sudo iptables -t nat -I POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask ;
return $?
}
remove_snat() {
if [ "$sflag" == "0" ]
then
return 0;
fi
local pubIp=$1
logger -t cloud "$(basename $0):Removing SourceNAT $pubIp on interface $ethDev"
sudo iptables -t nat -D POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask;
return $?
}
add_first_ip() {
local pubIp=$1
logger -t cloud "$(basename $0):Adding first ip $pubIp on interface $ethDev"
local ipNoMask=$(echo $1 | awk -F'/' '{print $1}')
local mask=$(echo $1 | awk -F'/' '{print $2}')
sudo ip link show $ethDev | grep "state DOWN" > /dev/null
@ -223,18 +243,20 @@ add_nat_entry() {
# remove if duplicat ip with 32 mask, this happens when we are promting the ip to primary
sudo ip addr del dev $ethDev $ipNoMask/32 > /dev/null
fi
sudo iptables -D FORWARD -i $ethDev -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -D FORWARD -i eth0 -o $ethDev -j ACCEPT
sudo iptables -t nat -D POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask ;
sudo iptables -A FORWARD -i $ethDev -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i eth0 -o $ethDev -j ACCEPT
sudo iptables -t nat -I POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask ;
add_snat $1
if [ $? -gt 0 -a $? -ne 2 ]
then
logger -t cloud "$(basename $0):Failed adding nat entry for ip $pubIp on interface $ethDev"
logger -t cloud "$(basename $0):Failed adding source nat entry for ip $pubIp on interface $ethDev"
return 1
fi
logger -t cloud "$(basename $0):Added nat entry for ip $pubIp on interface $ethDev"
logger -t cloud "$(basename $0):Added first ip $pubIp on interface $ethDev"
if [ $if_keep_state -ne 1 -o $old_state -ne 0 ]
then
sudo ip link set $ethDev up
@ -245,22 +267,24 @@ add_nat_entry() {
return 0
}
del_nat_entry() {
remove_first_ip() {
local pubIp=$1
logger -t cloud "$(basename $0):Deleting nat entry for ip $pubIp on interface $ethDev"
logger -t cloud "$(basename $0):Removing first ip $pubIp on interface $ethDev"
local ipNoMask=$(echo $1 | awk -F'/' '{print $1}')
local mask=$(echo $1 | awk -F'/' '{print $2}')
[ "$mask" == "" ] && mask="32"
sudo iptables -D FORWARD -i $ethDev -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -D FORWARD -i eth0 -o $ethDev -j ACCEPT
sudo iptables -t nat -D POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask;
remove_snat $1
sudo ip addr del dev $ethDev "$ipNoMask/$mask"
remove_routing $1
if [ $? -gt 0 -a $? -ne 2 ]
then
remove_routing $1
return 1
fi
remove_routing $1
return $?
}
@ -274,7 +298,7 @@ add_an_ip () {
local old_state=$?
sudo ip addr add dev $ethDev $pubIp ;
add_snat $1
if [ $if_keep_state -ne 1 -o $old_state -ne 0 ]
then
sudo ip link set $ethDev up
@ -292,12 +316,14 @@ remove_an_ip () {
local mask=$(echo $1 | awk -F'/' '{print $2}')
local existingIpMask=$(sudo ip addr show dev $ethDev | grep inet | awk '{print $2}' | grep -w $ipNoMask)
[ "$existingIpMask" == "" ] && return 0
remove_snat $1
local existingMask=$(echo $existingIpMask | awk -F'/' '{print $2}')
if [ "$existingMask" == "32" ]
then
sudo ip addr del dev $ethDev $existingIpMask
result=$?
fi
if [ "$existingMask" != "32" ]
then
replaceIpMask=`sudo ip addr show dev $ethDev | grep inet | grep -v $existingIpMask | awk '{print $2}' | sort -t/ -k2 -n|tail -1`
@ -306,21 +332,21 @@ remove_an_ip () {
sudo ip addr del dev $ethDev $replaceIpMask;
replaceIp=`echo $replaceIpMask | awk -F/ '{print $1}'`;
sudo ip addr add dev $ethDev $replaceIp/$existingMask;
sudo iptables -t nat -D POSTROUTING -j SNAT -o $ethDev --to-source $ipNoMask ;
sudo iptables -t nat -A POSTROUTING -j SNAT -o $ethDev --to-source $replaceIp ;
fi
result=$?
fi
remove_routing $1
if [ $result -gt 0 -a $result -ne 2 ]
then
remove_routing $1
return 1
fi
remove_routing $1
return 0
}
#set -x
sflag=0
lflag=
fflag=
cflag=
@ -344,7 +370,7 @@ then
if_keep_state=1
fi
while getopts 'fADa:l:c:g:' OPTION
while getopts 'sfADa:l:c:g:' OPTION
do
case $OPTION in
A) Aflag=1
@ -355,6 +381,8 @@ do
;;
f) fflag=1
;;
s) sflag=1
;;
l) lflag=1
publicIp="$OPTARG"
;;
@ -370,7 +398,6 @@ do
esac
done
#Either the A flag or the D flag but not both
if [ "$Aflag$Dflag" != "1" ]
then
@ -387,7 +414,7 @@ fi
if [ "$fflag" == "1" ] && [ "$Aflag" == "1" ]
then
add_nat_entry $publicIp &&
add_first_ip $publicIp &&
add_vpn_chain_for_ip $publicIp &&
add_fw_chain_for_ip $publicIp
unlock_exit $? $lock $locked
@ -402,7 +429,7 @@ fi
if [ "$fflag" == "1" ] && [ "$Dflag" == "1" ]
then
del_nat_entry $publicIp &&
remove_first_ip $publicIp &&
del_fw_chain_for_ip $publicIp &&
del_vpn_chain_for_ip $publicIp
unlock_exit $? $lock $locked

View File

@ -1110,8 +1110,8 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Deregistering link for " + hostId + " with state " + nextState);
}
removeAgent(attache, nextState, event, investigate);
_hostDao.disconnect(host, event, _nodeId);
removeAgent(attache, nextState, event, investigate);
return true;
}

View File

@ -243,6 +243,7 @@ public enum Config {
VmwareReserveMem("Advanced", ManagementServer.class, Boolean.class, "vmware.reserve.mem", "false", "Specify whether or not to reserve memory based on memory overprovisioning factor", null),
VmwareRootDiskControllerType("Advanced", ManagementServer.class, String.class, "vmware.root.disk.controller", "ide", "Specify the default disk controller for root volumes, valid values are scsi, ide", null),
VmwareSystemVmNicDeviceType("Advanced", ManagementServer.class, String.class, "vmware.systemvm.nic.device.type", "E1000", "Specify the default network device type for system VMs, valid values are E1000, PCNet32, Vmxnet2, Vmxnet3", null),
VmwareRecycleHungWorker("Advanced", ManagementServer.class, Boolean.class, "vmware.recycle.hung.wokervm", "false", "Specify whether or not to recycle hung worker VMs", null),
// KVM
KvmPublicNetwork("Advanced", ManagementServer.class, String.class, "kvm.public.network.device", null, "Specify the public bridge on host for public network", null),

View File

@ -113,6 +113,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
String _serviceConsoleName;
String _managemetPortGroupName;
String _defaultSystemVmNicAdapterType = VirtualEthernetCardType.E1000.toString();
String _recycleHungWorker = "false";
int _additionalPortRangeStart;
int _additionalPortRangeSize;
int _maxHostsPerCluster;
@ -253,6 +254,10 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
if(_reserveMem == null || _reserveMem.isEmpty())
_reserveMem = "false";
_recycleHungWorker = configDao.getValue(Config.VmwareRecycleHungWorker.key());
if(_recycleHungWorker == null || _recycleHungWorker.isEmpty())
_recycleHungWorker = "false";
_rootDiskController = configDao.getValue(Config.VmwareRootDiskControllerType.key());
if(_rootDiskController == null || _rootDiskController.isEmpty())
_rootDiskController = DiskControllerType.ide.toString();
@ -476,6 +481,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
params.put("mem.overprovisioning.factor", _memOverprovisioningFactor);
params.put("vmware.reserve.mem", _reserveMem);
params.put("vmware.root.disk.controller", _rootDiskController);
params.put("vmware.recycle.hung.wokervm", _recycleHungWorker);
}
@Override

View File

@ -45,6 +45,7 @@ class DBDeployer(object):
isDebug = False
dbConfPath = r"@MSCONF@"
dbFilesPath = r"@SETUPDATADIR@"
success = False
def preRun(self):
def backUpDbDotProperties():
@ -412,8 +413,7 @@ for full help
self.info("Mysql server port:%s"%self.port, True)
def validateParameters():
if self.encryptiontype != 'file' and self.encryptiontype != 'web':
self.errorAndExit('Wrong encryption type %s, --encrypt-type can only be "file" or "web'%self.encryptiontype)
pass
#---------------------- option parsing and command line checks ------------------------
usage = """%prog user:[password]@mysqlhost:[port] [--deploy-as=rootuser:[rootpassword]] [--auto=/path/to/server-setup.xml]
@ -468,6 +468,7 @@ for full help
self.grabSystemInfo()
self.prepareDBFiles()
self.setupDBSchema()
self.success = True
finally:
self.postRun()

View File

@ -20,6 +20,8 @@ CREATE TABLE `cloud`.`mshost_peer` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT IGNORE INTO configuration (category, instance, component, name, value, description) VALUES ('Advanced', 'DEFAULT', 'management-server', 'vmware.systemvm.nic.device.type', 'E1000', 'Specify the default network device type for system VMs, valid values are E1000, PCNet32, Vmxnet2, Vmxnet3');
INSERT IGNORE INTO configuration (category, instance, component, name, value, description) VALUES ('Advanced', 'DEFAULT', 'management-server', 'vmware.recycle.hung.wokervm', 'false', 'Specify whether or not to recycle hung worker VMs');
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Storage', 'DEFAULT', 'StorageManager', 'backup.snapshot.wait', '10800', 'In second, timeout for BackupSnapshotCommand');
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Storage', 'DEFAULT', 'StorageManager', 'copy.volume.wait', '10800', 'In second, timeout for copy volume command');
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Storage', 'DEFAULT', 'UserVmManager', 'create.private.template.from.snapshot.wait', '10800', 'In second, timeout for CreatePrivateTemplateFromSnapshotCommand');
@ -33,4 +35,5 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Premium', 'DEFAULT', 'manage
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Premium', 'DEFAULT', 'management-server', 'enable.usage.server', 'true', 'Flag for enabling usage');
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Premium', 'DEFAULT', 'management-server', 'direct.network.stats.interval', '86400', 'Interval (in seconds) to collect stats from Traffic Monitor');
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Premium', 'DEFAULT', 'management-server', 'usage.sanity.check.interval', null, 'Interval (in days) to check sanity of usage data');
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Premium', 'DEFAULT', 'management-server', 'usage.aggregation.timezone', 'GMT', 'The timezone to use for usage stats aggregation');
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Premium', 'DEFAULT', 'management-server', 'usage.aggregation.timezone', 'GMT', 'The timezone to use for usage stats aggregation');
INSERT IGNORE INTO `cloud`.`guest_os` (category_id, name, display_name) VALUES (6, NULL, "Windows PV");

View File

@ -25,6 +25,7 @@ import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import java.util.UUID;
import com.cloud.utils.exception.CloudRuntimeException;