From 843cfc8793a7ca38d7721ce50a67bc22d9cf1bf2 Mon Sep 17 00:00:00 2001 From: abhishek Date: Wed, 22 Sep 2010 11:27:03 -0700 Subject: [PATCH] merging 6271 int0 2.1.x --- .../cloud/network/dao/IPAddressDaoImpl.java | 5 +-- .../ConfigurationManagerImpl.java | 14 ++++---- .../src/com/cloud/vm/UserVmManagerImpl.java | 35 +++++++++++++++++-- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/core/src/com/cloud/network/dao/IPAddressDaoImpl.java b/core/src/com/cloud/network/dao/IPAddressDaoImpl.java index 2d06d3a3d8c..38f6de25ee9 100644 --- a/core/src/com/cloud/network/dao/IPAddressDaoImpl.java +++ b/core/src/com/cloud/network/dao/IPAddressDaoImpl.java @@ -142,8 +142,9 @@ public class IPAddressDaoImpl extends GenericDaoBase implem txn.commit(); return ip.getAddress(); } else { - txn.rollback(); - s_logger.error("Unable to find an available IP address with related vlan, vlanDbId: " + vlanDbId); + txn.rollback(); + //we do not log this as an error now, as there can be multiple vlans across which we iterate + s_logger.warn("Unable to find an available IP address with related vlan, vlanDbId: " + vlanDbId); } } catch (Exception e) { s_logger.warn("Unable to assign IP", e); diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 423e3ddc0b0..8d050fe4a12 100644 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -988,13 +988,13 @@ public class ConfigurationManagerImpl implements ConfigurationManager { } // Make sure the specified account isn't already assigned to a VLAN in this zone - List accountVlanMaps = _accountVlanMapDao.listAccountVlanMapsByAccount(accountId); - for (AccountVlanMapVO accountVlanMap : accountVlanMaps) { - VlanVO vlan = _vlanDao.findById(accountVlanMap.getVlanDbId()); - if (vlan.getDataCenterId() == zone.getId().longValue()) { - throw new InvalidParameterValueException("The account " + account.getAccountName() + " is already assigned to the VLAN with ID " + vlan.getVlanId() + " in zone " + zone.getName() + "."); - } - } +// List accountVlanMaps = _accountVlanMapDao.listAccountVlanMapsByAccount(accountId); +// for (AccountVlanMapVO accountVlanMap : accountVlanMaps) { +// VlanVO vlan = _vlanDao.findById(accountVlanMap.getVlanDbId()); +// if (vlan.getDataCenterId() == zone.getId().longValue()) { +// throw new InvalidParameterValueException("The account " + account.getAccountName() + " is already assigned to the VLAN with ID " + vlan.getVlanId() + " in zone " + zone.getName() + "."); +// } +// } } } } diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 60291366360..57c5dee40f8 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -2447,7 +2447,8 @@ public class UserVmManagerImpl implements UserVmManager { Set avoids = new HashSet(); VlanVO guestVlan = null; List vlansForAccount = _vlanDao.listVlansForAccountByType(dc.getId(), account.getId(), VlanType.DirectAttached); - + List vlansForPod = null; + boolean forAccount = false; if (vlansForAccount.size() > 0) { forAccount = true; @@ -2472,7 +2473,7 @@ public class UserVmManagerImpl implements UserVmManager { s_logger.debug("Attempting to create direct attached vm in pod " + pod.first().getName()); } if (!forAccount && !forZone) { - List vlansForPod = _vlanDao.listVlansForPodByType(pod.first().getId(), VlanType.DirectAttached); + vlansForPod = _vlanDao.listVlansForPodByType(pod.first().getId(), VlanType.DirectAttached); if (vlansForPod.size() < 1) { avoids.add(pod.first().getId()); if (s_logger.isDebugEnabled()) { @@ -2499,7 +2500,35 @@ public class UserVmManagerImpl implements UserVmManager { } routerId = router.getId(); } - String guestIp = _ipAddressDao.assignIpAddress(accountId, account.getDomainId().longValue(), guestVlan.getId(), false); + + + String guestIp = null; + + if(forAccount) + { + for(VlanVO vlanForAcc : vlansForAccount) + { + guestIp = _ipAddressDao.assignIpAddress(accountId, account.getDomainId(), vlanForAcc.getId(), false); + if(guestIp!=null) + break; //got an ip + } + } + else if(!forAccount && !forZone) + { + //i.e. for pod + for(VlanVO vlanForPod : vlansForPod) + { + guestIp = _ipAddressDao.assignIpAddress(accountId, account.getDomainId(), vlanForPod.getId(), false); + if(guestIp!=null) + break;//got an ip + } + } + else + { + //for zone + guestIp = _ipAddressDao.assignIpAddress(accountId, account.getDomainId().longValue(), guestVlan.getId(), false); + } + if (guestIp == null) { s_logger.debug("No guest IP available in pod id=" + pod.first().getId()); avoids.add(pod.first().getId());