use of com.cloud.dc.AccountVlanMapVO in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerTest method runDedicatePublicIpRangeDedicatedRange.
void runDedicatePublicIpRangeDedicatedRange() throws Exception {
final TransactionLegacy txn = TransactionLegacy.open("runDedicatePublicIpRangeDedicatedRange");
when(configurationMgr._vlanDao.findById(anyLong())).thenReturn(vlan);
// public ip range is already dedicated
final List<AccountVlanMapVO> accountVlanMaps = new ArrayList<>();
final AccountVlanMapVO accountVlanMap = new AccountVlanMapVO(1, 1);
accountVlanMaps.add(accountVlanMap);
when(configurationMgr._accountVlanMapDao.listAccountVlanMapsByVlan(anyLong())).thenReturn(accountVlanMaps);
final DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", null, null, NetworkType.Advanced, null, null, true, null, null);
when(configurationMgr._zoneDao.findById(anyLong())).thenReturn(dc);
final List<IPAddressVO> ipAddressList = new ArrayList<>();
final IPAddressVO ipAddress = new IPAddressVO(new Ip("75.75.75.75"), 1, 0xaabbccddeeffL, 10, false);
ipAddressList.add(ipAddress);
when(configurationMgr._publicIpAddressDao.listByVlanId(anyLong())).thenReturn(ipAddressList);
try {
configurationMgr.dedicatePublicIpRange(dedicatePublicIpRangesCmd);
} catch (final Exception e) {
Assert.assertTrue(e.getMessage().contains("Public IP range has already been dedicated"));
} finally {
txn.close("runDedicatePublicIpRangePublicIpRangeDedicated");
}
}
use of com.cloud.dc.AccountVlanMapVO in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerTest method setup.
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
configurationMgr._accountMgr = _accountMgr;
configurationMgr._projectMgr = _projectMgr;
configurationMgr._resourceLimitMgr = _resourceLimitMgr;
configurationMgr._networkMgr = _networkMgr;
configurationMgr._accountDao = _accountDao;
configurationMgr._vlanDao = _vlanDao;
configurationMgr._accountVlanMapDao = _accountVlanMapDao;
configurationMgr._domainVlanMapDao = _domainVlanMapDao;
configurationMgr._publicIpAddressDao = _publicIpAddressDao;
configurationMgr._zoneDao = _zoneDao;
configurationMgr._firewallDao = _firewallDao;
configurationMgr._ipAddrMgr = _ipAddrMgr;
configurationMgr._networkModel = _networkModel;
configurationMgr._privateIpAddressDao = _privateIpAddressDao;
configurationMgr._volumeDao = _volumeDao;
configurationMgr._hostDao = _hostDao;
configurationMgr._vmInstanceDao = _vmInstanceDao;
configurationMgr._clusterDao = _clusterDao;
configurationMgr._podDao = _podDao;
configurationMgr._physicalNetworkDao = _physicalNetworkDao;
final Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
when(configurationMgr._accountMgr.getAccount(anyLong())).thenReturn(account);
when(configurationMgr._accountDao.findActiveAccount(anyString(), anyLong())).thenReturn(account);
when(configurationMgr._accountMgr.getActiveAccountById(anyLong())).thenReturn(account);
final UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user, account);
when(configurationMgr._publicIpAddressDao.countIPs(anyLong(), anyLong(), anyBoolean())).thenReturn(1);
doNothing().when(configurationMgr._resourceLimitMgr).checkResourceLimit(any(Account.class), any(ResourceType.class), anyLong());
when(configurationMgr._accountVlanMapDao.persist(any(AccountVlanMapVO.class))).thenReturn(new AccountVlanMapVO());
when(configurationMgr._vlanDao.acquireInLockTable(anyLong(), anyInt())).thenReturn(vlan);
final Field dedicateIdField = _dedicatePublicIpRangeClass.getDeclaredField("id");
dedicateIdField.setAccessible(true);
dedicateIdField.set(dedicatePublicIpRangesCmd, 1L);
final Field accountNameField = _dedicatePublicIpRangeClass.getDeclaredField("accountName");
accountNameField.setAccessible(true);
accountNameField.set(dedicatePublicIpRangesCmd, "accountname");
final Field projectIdField = _dedicatePublicIpRangeClass.getDeclaredField("projectId");
projectIdField.setAccessible(true);
projectIdField.set(dedicatePublicIpRangesCmd, null);
final Field domainIdField = _dedicatePublicIpRangeClass.getDeclaredField("domainId");
domainIdField.setAccessible(true);
domainIdField.set(dedicatePublicIpRangesCmd, 1L);
final Field releaseIdField = _releasePublicIpRangeClass.getDeclaredField("id");
releaseIdField.setAccessible(true);
releaseIdField.set(releasePublicIpRangesCmd, 1L);
}
use of com.cloud.dc.AccountVlanMapVO in project cosmic by MissionCriticalCloud.
the class VlanDaoImpl method listVlansForAccountByType.
@Override
public List<VlanVO> listVlansForAccountByType(final Long zoneId, final long accountId, final VlanType vlanType) {
// FIXME: use a join statement to improve the performance (should be minor since we expect only one or two)
final List<AccountVlanMapVO> vlanMaps = _accountVlanMapDao.listAccountVlanMapsByAccount(accountId);
final List<VlanVO> result = new ArrayList<>();
for (final AccountVlanMapVO acvmvo : vlanMaps) {
final VlanVO vlan = findById(acvmvo.getVlanDbId());
if (vlan.getVlanType() == vlanType && (zoneId == null || vlan.getDataCenterId() == zoneId)) {
result.add(vlan);
}
}
return result;
}
use of com.cloud.dc.AccountVlanMapVO in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerImpl method dedicatePublicIpRange.
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_DEDICATE, eventDescription = "dedicating vlan ip range", async = false)
public Vlan dedicatePublicIpRange(final DedicatePublicIpRangeCmd cmd) throws ResourceAllocationException {
final Long vlanDbId = cmd.getId();
final String accountName = cmd.getAccountName();
final Long domainId = cmd.getDomainId();
final Long projectId = cmd.getProjectId();
// Check if account is valid
Account vlanOwner = null;
if (projectId != null) {
if (accountName != null) {
throw new InvalidParameterValueException("accountName and projectId are mutually exclusive");
}
final Project project = _projectMgr.getProject(projectId);
if (project == null) {
throw new InvalidParameterValueException("Unable to find project by id " + projectId);
}
vlanOwner = _accountMgr.getAccount(project.getProjectAccountId());
if (vlanOwner == null) {
throw new InvalidParameterValueException("Please specify a valid projectId");
}
}
Domain domain = null;
if (accountName != null && domainId != null) {
vlanOwner = _accountDao.findActiveAccount(accountName, domainId);
if (vlanOwner == null) {
throw new InvalidParameterValueException("Unable to find account by name " + accountName);
} else if (vlanOwner.getId() == Account.ACCOUNT_ID_SYSTEM) {
throw new InvalidParameterValueException("Please specify a valid account. Cannot dedicate IP range to system account");
}
} else if (domainId != null) {
domain = _domainDao.findById(domainId);
if (domain == null) {
throw new InvalidParameterValueException("Please specify a valid domain id");
}
}
// Check if range is valid
final VlanVO vlan = _vlanDao.findById(vlanDbId);
if (vlan == null) {
throw new InvalidParameterValueException("Unable to find vlan by id " + vlanDbId);
}
// Check if range has already been dedicated
final List<AccountVlanMapVO> maps = _accountVlanMapDao.listAccountVlanMapsByVlan(vlanDbId);
if (maps != null && !maps.isEmpty()) {
throw new InvalidParameterValueException("Specified Public IP range has already been dedicated");
}
final List<DomainVlanMapVO> domainmaps = _domainVlanMapDao.listDomainVlanMapsByVlan(vlanDbId);
if (domainmaps != null && !domainmaps.isEmpty()) {
throw new InvalidParameterValueException("Specified Public IP range has already been dedicated to a domain");
}
// Verify that zone exists and is advanced
final Long zoneId = vlan.getDataCenterId();
final DataCenterVO zone = _zoneDao.findById(zoneId);
if (zone == null) {
throw new InvalidParameterValueException("Unable to find zone by id " + zoneId);
}
if (zone.getNetworkType() == NetworkType.Basic) {
throw new InvalidParameterValueException("Public IP range can be dedicated to an account only in the zone of type " + NetworkType.Advanced);
}
// Check Public IP resource limits
if (vlanOwner != null) {
final int accountPublicIpRange = _publicIpAddressDao.countIPs(zoneId, vlanDbId, false);
_resourceLimitMgr.checkResourceLimit(vlanOwner, ResourceType.public_ip, accountPublicIpRange);
}
// Check if any of the Public IP addresses is allocated to another
// account
final List<IPAddressVO> ips = _publicIpAddressDao.listByVlanId(vlanDbId);
for (final IPAddressVO ip : ips) {
final Long allocatedToAccountId = ip.getAllocatedToAccountId();
if (allocatedToAccountId != null) {
final Account accountAllocatedTo = _accountMgr.getActiveAccountById(allocatedToAccountId);
if (!accountAllocatedTo.getAccountName().equalsIgnoreCase(accountName)) {
throw new InvalidParameterValueException(ip.getAddress() + " Public IP address in range is allocated to another account ");
}
if (vlanOwner == null && domain != null && domain.getId() != accountAllocatedTo.getDomainId()) {
throw new InvalidParameterValueException(ip.getAddress() + " Public IP address in range is allocated to another domain/account ");
}
}
}
if (vlanOwner != null) {
// Create an AccountVlanMapVO entry
final AccountVlanMapVO accountVlanMapVO = new AccountVlanMapVO(vlanOwner.getId(), vlan.getId());
_accountVlanMapDao.persist(accountVlanMapVO);
} else if (domain != null) {
// Create an DomainVlanMapVO entry
final DomainVlanMapVO domainVlanMapVO = new DomainVlanMapVO(domain.getId(), vlan.getId());
_domainVlanMapDao.persist(domainVlanMapVO);
}
// increment resource count for dedicated public ip's
if (vlanOwner != null) {
_resourceLimitMgr.incrementResourceCount(vlanOwner.getId(), ResourceType.public_ip, new Long(ips.size()));
}
return vlan;
}
use of com.cloud.dc.AccountVlanMapVO in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerImpl method commitVlanAndIpRange.
private VlanVO commitVlanAndIpRange(final long zoneId, final long networkId, final long physicalNetworkId, final Long podId, final String startIP, final String endIP, final String vlanGateway, final String vlanNetmask, final String vlanId, final Domain domain, final Account vlanOwner, final String vlanIp6Gateway, final String vlanIp6Cidr, final boolean ipv4, final Zone zone, final VlanType vlanType, final String ipv6Range, final String ipRange) {
return Transaction.execute(new TransactionCallback<VlanVO>() {
@Override
public VlanVO doInTransaction(final TransactionStatus status) {
VlanVO vlan = new VlanVO(vlanType, vlanId, vlanGateway, vlanNetmask, zone.getId(), ipRange, networkId, physicalNetworkId, vlanIp6Gateway, vlanIp6Cidr, ipv6Range);
s_logger.debug("Saving vlan range " + vlan);
vlan = _vlanDao.persist(vlan);
// public ip range
if (ipv4) {
if (!savePublicIPRange(startIP, endIP, zoneId, vlan.getId(), networkId, physicalNetworkId)) {
throw new CloudRuntimeException("Failed to save IPv4 range. Please contact Cloud Support.");
}
}
if (vlanOwner != null) {
// This VLAN is account-specific, so create an AccountVlanMapVO
// entry
final AccountVlanMapVO accountVlanMapVO = new AccountVlanMapVO(vlanOwner.getId(), vlan.getId());
_accountVlanMapDao.persist(accountVlanMapVO);
final List<IPAddressVO> ips = _publicIpAddressDao.listByVlanId(vlan.getId());
// increment resource count for dedicated public ip's
_resourceLimitMgr.incrementResourceCount(vlanOwner.getId(), ResourceType.public_ip, new Long(ips.size()));
} else if (domain != null) {
// This VLAN is domain-wide, so create a DomainVlanMapVO entry
final DomainVlanMapVO domainVlanMapVO = new DomainVlanMapVO(domain.getId(), vlan.getId());
_domainVlanMapDao.persist(domainVlanMapVO);
} else if (podId != null) {
// This VLAN is pod-wide, so create a PodVlanMapVO entry
final PodVlanMapVO podVlanMapVO = new PodVlanMapVO(podId, vlan.getId());
_podVlanMapDao.persist(podVlanMapVO);
}
return vlan;
}
});
}
Aggregations