Search in sources :

Example 96 with IPAddressVO

use of com.cloud.network.dao.IPAddressVO in project cloudstack by apache.

the class VpcManagerImpl method assignSourceNatIpAddressToVpc.

@Override
public PublicIp assignSourceNatIpAddressToVpc(final Account owner, final Vpc vpc) throws InsufficientAddressCapacityException, ConcurrentOperationException {
    final long dcId = vpc.getZoneId();
    final IPAddressVO sourceNatIp = getExistingSourceNatInVpc(owner.getId(), vpc.getId());
    PublicIp ipToReturn = null;
    if (sourceNatIp != null) {
        ipToReturn = PublicIp.createFromAddrAndVlan(sourceNatIp, _vlanDao.findById(sourceNatIp.getVlanId()));
    } else {
        ipToReturn = _ipAddrMgr.assignDedicateIpAddress(owner, null, vpc.getId(), dcId, true);
    }
    return ipToReturn;
}
Also used : PublicIp(com.cloud.network.addr.PublicIp) IPAddressVO(com.cloud.network.dao.IPAddressVO)

Example 97 with IPAddressVO

use of com.cloud.network.dao.IPAddressVO in project cloudstack by apache.

the class ConfigurationManagerTest method runDedicatePublicIpRangeInvalidZone.

void runDedicatePublicIpRangeInvalidZone() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runDedicatePublicIpRangeInvalidZone");
    when(configurationMgr._vlanDao.findById(anyLong())).thenReturn(vlan);
    when(configurationMgr._accountVlanMapDao.listAccountVlanMapsByVlan(anyLong())).thenReturn(null);
    // public ip range belongs to zone of type basic
    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.Basic, null, null, true, true, null, null);
    when(configurationMgr._zoneDao.findById(anyLong())).thenReturn(dc);
    List<IPAddressVO> ipAddressList = new ArrayList<IPAddressVO>();
    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 (Exception e) {
        Assert.assertTrue(e.getMessage().contains("Public IP range can be dedicated to an account only in the zone of type Advanced"));
    } finally {
        txn.close("runDedicatePublicIpRangeInvalidZone");
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Ip(com.cloud.utils.net.Ip) ArrayList(java.util.ArrayList) IPAddressVO(com.cloud.network.dao.IPAddressVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 98 with IPAddressVO

use of com.cloud.network.dao.IPAddressVO in project cloudstack by apache.

the class ConfigurationManagerTest method runDedicatePublicIpRangeDedicatedRange.

void runDedicatePublicIpRangeDedicatedRange() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runDedicatePublicIpRangeDedicatedRange");
    when(configurationMgr._vlanDao.findById(anyLong())).thenReturn(vlan);
    // public ip range is already dedicated
    List<AccountVlanMapVO> accountVlanMaps = new ArrayList<AccountVlanMapVO>();
    AccountVlanMapVO accountVlanMap = new AccountVlanMapVO(1, 1);
    accountVlanMaps.add(accountVlanMap);
    when(configurationMgr._accountVlanMapDao.listAccountVlanMapsByVlan(anyLong())).thenReturn(accountVlanMaps);
    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, true, null, null);
    when(configurationMgr._zoneDao.findById(anyLong())).thenReturn(dc);
    List<IPAddressVO> ipAddressList = new ArrayList<IPAddressVO>();
    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 (Exception e) {
        Assert.assertTrue(e.getMessage().contains("Public IP range has already been dedicated"));
    } finally {
        txn.close("runDedicatePublicIpRangePublicIpRangeDedicated");
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Ip(com.cloud.utils.net.Ip) ArrayList(java.util.ArrayList) AccountVlanMapVO(com.cloud.dc.AccountVlanMapVO) IPAddressVO(com.cloud.network.dao.IPAddressVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 99 with IPAddressVO

use of com.cloud.network.dao.IPAddressVO in project cloudstack by apache.

the class ConfigurationManagerTest method runDedicatePublicIpRangeIPAdressAllocated.

void runDedicatePublicIpRangeIPAdressAllocated() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runDedicatePublicIpRangeIPAdressAllocated");
    when(configurationMgr._vlanDao.findById(anyLong())).thenReturn(vlan);
    when(configurationMgr._accountVlanMapDao.listAccountVlanMapsByAccount(anyLong())).thenReturn(null);
    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, true, null, null);
    when(configurationMgr._zoneDao.findById(anyLong())).thenReturn(dc);
    // one of the ip addresses of the range is allocated to different account
    List<IPAddressVO> ipAddressList = new ArrayList<IPAddressVO>();
    IPAddressVO ipAddress = new IPAddressVO(new Ip("75.75.75.75"), 1, 0xaabbccddeeffL, 10, false);
    ipAddress.setAllocatedToAccountId(1L);
    ipAddressList.add(ipAddress);
    when(configurationMgr._publicIpAddressDao.listByVlanId(anyLong())).thenReturn(ipAddressList);
    try {
        configurationMgr.dedicatePublicIpRange(dedicatePublicIpRangesCmd);
    } catch (Exception e) {
        Assert.assertTrue(e.getMessage().contains("Public IP address in range is allocated to another account"));
    } finally {
        txn.close("runDedicatePublicIpRangeIPAdressAllocated");
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Ip(com.cloud.utils.net.Ip) ArrayList(java.util.ArrayList) IPAddressVO(com.cloud.network.dao.IPAddressVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 100 with IPAddressVO

use of com.cloud.network.dao.IPAddressVO in project cloudstack by apache.

the class ConfigurationManagerTest method runReleasePublicIpRangePostiveTest2.

void runReleasePublicIpRangePostiveTest2() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runReleasePublicIpRangePostiveTest2");
    when(configurationMgr._vlanDao.findById(anyLong())).thenReturn(vlan);
    List<AccountVlanMapVO> accountVlanMaps = new ArrayList<AccountVlanMapVO>();
    AccountVlanMapVO accountVlanMap = new AccountVlanMapVO(1, 1);
    accountVlanMaps.add(accountVlanMap);
    when(configurationMgr._accountVlanMapDao.listAccountVlanMapsByVlan(anyLong())).thenReturn(accountVlanMaps);
    when(configurationMgr._publicIpAddressDao.countIPs(anyLong(), anyLong(), anyBoolean())).thenReturn(1);
    List<IPAddressVO> ipAddressList = new ArrayList<IPAddressVO>();
    IPAddressVO ipAddress = new IPAddressVO(new Ip("75.75.75.75"), 1, 0xaabbccddeeffL, 10, false);
    ipAddressList.add(ipAddress);
    when(configurationMgr._publicIpAddressDao.listByVlanId(anyLong())).thenReturn(ipAddressList);
    when(configurationMgr._firewallDao.countRulesByIpId(anyLong())).thenReturn(0L);
    when(configurationMgr._ipAddrMgr.disassociatePublicIpAddress(anyLong(), anyLong(), any(Account.class))).thenReturn(true);
    when(configurationMgr._vlanDao.releaseFromLockTable(anyLong())).thenReturn(true);
    when(configurationMgr._accountVlanMapDao.remove(anyLong())).thenReturn(true);
    try {
        Boolean result = configurationMgr.releasePublicIpRange(releasePublicIpRangesCmd);
        Assert.assertTrue(result);
    } catch (Exception e) {
        s_logger.info("exception in testing runReleasePublicIpRangePostiveTest2 message: " + e.toString());
    } finally {
        txn.close("runReleasePublicIpRangePostiveTest2");
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Account(com.cloud.user.Account) Ip(com.cloud.utils.net.Ip) ArrayList(java.util.ArrayList) AccountVlanMapVO(com.cloud.dc.AccountVlanMapVO) IPAddressVO(com.cloud.network.dao.IPAddressVO) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

IPAddressVO (com.cloud.network.dao.IPAddressVO)109 ArrayList (java.util.ArrayList)43 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)42 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)39 Account (com.cloud.user.Account)37 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)32 DB (com.cloud.utils.db.DB)28 TransactionStatus (com.cloud.utils.db.TransactionStatus)26 Network (com.cloud.network.Network)25 PublicIp (com.cloud.network.addr.PublicIp)22 DataCenter (com.cloud.dc.DataCenter)17 VlanVO (com.cloud.dc.VlanVO)16 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)16 List (java.util.List)15 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)14 Ip (com.cloud.utils.net.Ip)14 NetworkOffering (com.cloud.offering.NetworkOffering)13 TransactionCallbackWithException (com.cloud.utils.db.TransactionCallbackWithException)13 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)12 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)11