From 242a55f120cbc524796497ff7a3f7d4beae416eb Mon Sep 17 00:00:00 2001 From: abhishek Date: Wed, 22 Sep 2010 10:56:39 -0700 Subject: [PATCH] bug 6271: Fixed the issue of us not iterating over all vlans, in the direct attached case. now, we consider all vlan ranges before we error out saying no ip address available status 6271: resolved fixed --- .../cloud/network/dao/IPAddressDaoImpl.java | 5 ++-- .../ConfigurationManagerImpl.java | 14 +++++----- .../src/com/cloud/vm/UserVmManagerImpl.java | 28 +++++++++++++++++-- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/core/src/com/cloud/network/dao/IPAddressDaoImpl.java b/core/src/com/cloud/network/dao/IPAddressDaoImpl.java index c7cefff591f..de01b197ddd 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 bf6f06e668f..9d48953e0b9 100644 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -1056,13 +1056,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()) { - throw new InvalidParameterValueException("The account " + account.getAccountName() + " is already assigned to an IP range in zone " + zone.getName() + "."); - } - } +// List accountVlanMaps = _accountVlanMapDao.listAccountVlanMapsByAccount(accountId); +// for (AccountVlanMapVO accountVlanMap : accountVlanMaps) { +// VlanVO vlan = _vlanDao.findById(accountVlanMap.getVlanDbId()); +// if (vlan.getDataCenterId() == zone.getId()) { +// throw new InvalidParameterValueException("The account " + account.getAccountName() + " is already assigned to an IP range in zone " + zone.getName() + "."); +// } +// } } else if (podId != null) { // Pod-wide VLANs must be untagged if (!vlanId.equals(Vlan.UNTAGGED)) { diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 25771648030..eccd831c6c6 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -2654,7 +2654,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; boolean forZone = false; if (vlansForAccount.size() > 0) { @@ -2680,7 +2681,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()) { @@ -2707,7 +2708,28 @@ public class UserVmManagerImpl implements UserVmManager { } routerId = router.getId(); } - String guestIp = _ipAddressDao.assignIpAddress(accountId, account.getDomainId(), 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 + } + } + if (guestIp == null) { s_logger.debug("No guest IP available in pod id=" + pod.first().getId()); avoids.add(pod.first().getId());