listVlanIpRanges api: for Account specific Virtual ip range return account information taken from account_vlan_map table instead of taking it from corresponding network

This commit is contained in:
alena 2011-01-21 10:54:59 -08:00
parent 835835dd0b
commit 4d0d47f6fc
4 changed files with 37 additions and 14 deletions

View File

@ -31,6 +31,7 @@ import com.cloud.exception.InvalidParameterValueException;
import com.cloud.offering.DiskOffering;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.ServiceOffering;
import com.cloud.user.Account;
public interface ConfigurationService {
@ -188,5 +189,7 @@ public interface ConfigurationService {
NetworkOffering getNetworkOffering(long id);
Integer getNetworkRate(long networkOfferingId);
Account getVlanAccount(long vlanId);
}

View File

@ -528,4 +528,8 @@ public class ApiDBUtils {
return _configMgr.getNetworkRate(networkOfferingId);
}
public static Account getVlanAccount(long vlanId) {
return _configMgr.getVlanAccount(vlanId);
}
}

View File

@ -568,20 +568,12 @@ public class ApiResponseHelper implements ResponseGenerator {
vlanResponse.setStartIp(range[0]);
vlanResponse.setEndIp(range[1]);
Long networkId = vlan.getNetworkId();
if (networkId != null) {
vlanResponse.setNetworkId(vlan.getNetworkId());
Network network = ApiDBUtils.findNetworkById(networkId);
if (network != null) {
Long accountId = network.getAccountId();
//Set account information
if (accountId != null) {
Account account = ApiDBUtils.findAccountById(accountId);
vlanResponse.setAccountName(account.getAccountName());
vlanResponse.setDomainId(account.getDomainId());
vlanResponse.setDomainName(ApiDBUtils.findDomainById(account.getDomainId()).getName());
}
}
vlanResponse.setNetworkId(vlan.getNetworkId());
Account owner = ApiDBUtils.getVlanAccount(vlan.getId());
if (owner != null) {
vlanResponse.setAccountName(owner.getAccountName());
vlanResponse.setDomainId(owner.getDomainId());
vlanResponse.setDomainName(ApiDBUtils.findDomainById(owner.getDomainId()).getName());
}
vlanResponse.setObjectName("vlan");

View File

@ -2782,4 +2782,28 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
return networkRate;
}
@Override
public Account getVlanAccount(long vlanId) {
Vlan vlan = _vlanDao.findById(vlanId);
Long accountId = null;
//if vlan is Virtual Account specific, get vlan information from the accountVlanMap; otherwise get account information from the network
if (vlan.getVlanType() == VlanType.VirtualNetwork) {
List<AccountVlanMapVO> maps = _accountVlanMapDao.listAccountVlanMapsByVlan(vlanId);
if (maps != null && !maps.isEmpty()) {
return _accountMgr.getAccount(maps.get(0).getAccountId());
}
}
Long networkId = vlan.getNetworkId();
if (networkId != null) {
Network network = _networkMgr.getNetwork(networkId);
if (network != null) {
accountId = network.getAccountId();
}
}
return _accountMgr.getAccount(accountId);
}
}