From 2cc15ecc0872a1ff96998f3c56a5200a46f6ff64 Mon Sep 17 00:00:00 2001 From: Edison Su Date: Fri, 27 Jan 2012 10:57:43 -0800 Subject: [PATCH 1/5] add new guest os type: windows pv, tell kvm that this windows guest has windows pv driver installed --- setup/db/db/schema-2213to2214.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup/db/db/schema-2213to2214.sql b/setup/db/db/schema-2213to2214.sql index c1fd41c5d3b..cae090f9e58 100644 --- a/setup/db/db/schema-2213to2214.sql +++ b/setup/db/db/schema-2213to2214.sql @@ -33,4 +33,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"); From b622fc60ae15d4214a978bd4106d597276e1e7c0 Mon Sep 17 00:00:00 2001 From: Kelven Yang Date: Fri, 27 Jan 2012 15:16:58 -0800 Subject: [PATCH 2/5] bug 13369: recycle roger hung worker VMs in vCenter --- .../vmware/resource/VmwareResource.java | 88 +++++++++++++++---- .../hypervisor/vmware/mo/TestVmwareMO.java | 34 +++++-- .../src/com/cloud/configuration/Config.java | 1 + .../hypervisor/vmware/VmwareManagerImpl.java | 6 ++ setup/db/db/schema-2213to2214.sql | 2 + utils/src/com/cloud/utils/DateUtil.java | 1 + 6 files changed, 110 insertions(+), 22 deletions(-) diff --git a/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index fbea4977419..f571ded0cd7 100755 --- a/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -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; @@ -3084,6 +3086,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 +3331,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa details.put("NativeHA", "true"); } } - + protected HashMap sync() { HashMap changes = new HashMap(); HashMap oldStates = null; @@ -3851,22 +3901,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 +3929,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; diff --git a/core/test/com/cloud/hypervisor/vmware/mo/TestVmwareMO.java b/core/test/com/cloud/hypervisor/vmware/mo/TestVmwareMO.java index 125d0592b54..5f9c0c714da 100755 --- a/core/test/com/cloud/hypervisor/vmware/mo/TestVmwareMO.java +++ b/core/test/com/cloud/hypervisor/vmware/mo/TestVmwareMO.java @@ -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) { diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index 31ac1987ef2..f60ffe96316 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -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), diff --git a/server/src/com/cloud/hypervisor/vmware/VmwareManagerImpl.java b/server/src/com/cloud/hypervisor/vmware/VmwareManagerImpl.java index 9253fd6feea..a488f86b8ad 100755 --- a/server/src/com/cloud/hypervisor/vmware/VmwareManagerImpl.java +++ b/server/src/com/cloud/hypervisor/vmware/VmwareManagerImpl.java @@ -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 diff --git a/setup/db/db/schema-2213to2214.sql b/setup/db/db/schema-2213to2214.sql index cae090f9e58..597b454c923 100644 --- a/setup/db/db/schema-2213to2214.sql +++ b/setup/db/db/schema-2213to2214.sql @@ -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'); diff --git a/utils/src/com/cloud/utils/DateUtil.java b/utils/src/com/cloud/utils/DateUtil.java index 67a6536e2a3..426a25bd36f 100644 --- a/utils/src/com/cloud/utils/DateUtil.java +++ b/utils/src/com/cloud/utils/DateUtil.java @@ -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; From 7b4b4c0ed898880e0018db192d1bd7664b61246e Mon Sep 17 00:00:00 2001 From: frank Date: Fri, 27 Jan 2012 16:42:02 -0800 Subject: [PATCH 3/5] Bug 13374 - cloud-setup-databases script failed to execute due to AttributeError status 13374: resolved fixed --- setup/bindir/cloud-setup-databases.in | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/setup/bindir/cloud-setup-databases.in b/setup/bindir/cloud-setup-databases.in index e24d8b7ae52..2c64c44fd3a 100755 --- a/setup/bindir/cloud-setup-databases.in +++ b/setup/bindir/cloud-setup-databases.in @@ -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() From 88a9b2f97349986d746562f19b700ff05580b0f2 Mon Sep 17 00:00:00 2001 From: Naredula Janardhana Reddy Date: Mon, 30 Jan 2012 16:50:02 +0530 Subject: [PATCH 4/5] Bug 13375: Summary of changes : - Added a new flag "-s" to ipassoc command to carry if the ip address is used for SNAT or not. - SNAT is completly decoupled from the first flag. first flag is used to decide if the ip address is first ip address of the interface. - -s and -f are independent, SNAT can be enabled on the non-first ip also. --- .../VirtualRoutingResource.java | 6 +- .../vmware/resource/VmwareResource.java | 7 +- .../xen/resource/CitrixResourceBase.java | 7 +- .../systemvm/debian/config/root/ipassoc.sh | 103 +++++++++++------- 4 files changed, 74 insertions(+), 49 deletions(-) diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java index ff467db2190..e1bb37bcc92 100755 --- a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java @@ -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 { diff --git a/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index f571ded0cd7..896805bc999 100755 --- a/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -729,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; diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 1f6d2fedf8b..82af103b498 100755 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -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; diff --git a/patches/systemvm/debian/config/root/ipassoc.sh b/patches/systemvm/debian/config/root/ipassoc.sh index 65007268c4b..63505e3a14e 100644 --- a/patches/systemvm/debian/config/root/ipassoc.sh +++ b/patches/systemvm/debian/config/root/ipassoc.sh @@ -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 . +# - # - # 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 . - # # $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 From 606708e0a37c185a8e2f9708cb0b74926265ce11 Mon Sep 17 00:00:00 2001 From: abhi Date: Mon, 30 Jan 2012 18:10:37 +0530 Subject: [PATCH 5/5] bug 12849: remove agent will kickstart HA if the host status is Down or Alert. The update is therefore moved before it reviewed by: kishan --- server/src/com/cloud/agent/manager/AgentManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/server/src/com/cloud/agent/manager/AgentManagerImpl.java index 537cdc7d77b..bc76cc128dc 100755 --- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java @@ -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; }