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
This commit is contained in:
abhishek 2010-09-22 10:56:39 -07:00
parent 91f77b6cc5
commit 242a55f120
3 changed files with 35 additions and 12 deletions

View File

@ -142,8 +142,9 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, String> 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);

View File

@ -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<AccountVlanMapVO> 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<AccountVlanMapVO> 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)) {

View File

@ -2654,7 +2654,8 @@ public class UserVmManagerImpl implements UserVmManager {
Set<Long> avoids = new HashSet<Long>();
VlanVO guestVlan = null;
List<VlanVO> vlansForAccount = _vlanDao.listVlansForAccountByType(dc.getId(), account.getId(), VlanType.DirectAttached);
List<VlanVO> 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<VlanVO> 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());