Search in sources :

Example 41 with IPAddressVO

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

the class LoadBalanceRuleHandlerTest method testFindElbVmWithCapacityWhenIpAddrIsNull.

@Test
public void testFindElbVmWithCapacityWhenIpAddrIsNull() throws Exception {
    IPAddressVO ipAddr = null;
    DomainRouterVO actual = loadBalanceRuleHandler.findElbVmWithCapacity(ipAddr);
    assertNull(actual);
}
Also used : IPAddressVO(com.cloud.network.dao.IPAddressVO) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Example 42 with IPAddressVO

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

the class LoadBalanceRuleHandlerTest method testFindElbVmWithCapacityWhenThereAreUnusedElbVmsAndOneMatchesThePodId.

@Test
public void testFindElbVmWithCapacityWhenThereAreUnusedElbVmsAndOneMatchesThePodId() throws Exception {
    Long podId = 1L;
    IPAddressVO ipAddrMock = mock(IPAddressVO.class);
    when(ipAddrMock.getVlanId()).thenReturn(podId);
    PodVlanMapVO podVlanMapVoMock = mock(PodVlanMapVO.class);
    when(podVlanMapVoMock.getPodId()).thenReturn(podId);
    when(podVlanMapDao.listPodVlanMapsByVlan(podId)).thenReturn(podVlanMapVoMock);
    DomainRouterVO unusedElbVmThatMatchesPodId = mock(DomainRouterVO.class);
    when(unusedElbVmThatMatchesPodId.getPodIdToDeployIn()).thenReturn(podId);
    List<DomainRouterVO> unusedElbVms = Arrays.asList(new DomainRouterVO[] { unusedElbVmThatMatchesPodId, mock(DomainRouterVO.class) });
    when(this.elasticLbVmMapDao.listUnusedElbVms()).thenReturn(unusedElbVms);
    DomainRouterVO expected = unusedElbVmThatMatchesPodId;
    DomainRouterVO actual = loadBalanceRuleHandler.findElbVmWithCapacity(ipAddrMock);
    assertNotNull(actual);
    assertEquals(expected, actual);
}
Also used : PodVlanMapVO(com.cloud.dc.PodVlanMapVO) IPAddressVO(com.cloud.network.dao.IPAddressVO) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Example 43 with IPAddressVO

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

the class LoadBalanceRuleHandler method releaseIp.

private void releaseIp(final long ipId, final long userId, final Account caller) {
    s_logger.info("ELB: Release public IP for loadbalancing " + ipId);
    final IPAddressVO ipvo = _ipAddressDao.findById(ipId);
    ipvo.setAssociatedWithNetworkId(null);
    _ipAddressDao.update(ipvo.getId(), ipvo);
    _ipAddrMgr.disassociatePublicIpAddress(ipId, userId, caller);
    _ipAddressDao.unassignIpAddress(ipId);
}
Also used : IPAddressVO(com.cloud.network.dao.IPAddressVO)

Example 44 with IPAddressVO

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

the class NetworkProviderTest method createFloatingIp.

public IPAddressVO createFloatingIp(Network network, UserVm vm) throws Exception {
    BaseCmd cmd = new AssociateIPAddrCmd();
    BaseCmd proxy = ComponentContext.inject(cmd);
    Account system = _accountMgr.getSystemAccount();
    DataCenter zone = _server.getZone();
    ManagementServerMock.setParameter(proxy, "accountName", BaseCmd.CommandType.STRING, system.getAccountName());
    ManagementServerMock.setParameter(proxy, "domainId", BaseCmd.CommandType.LONG, Domain.ROOT_DOMAIN);
    ManagementServerMock.setParameter(proxy, "zoneId", BaseCmd.CommandType.LONG, zone.getId());
    ManagementServerMock.setParameter(proxy, "networkId", BaseCmd.CommandType.LONG, network.getId());
    try {
        ((AssociateIPAddrCmd) cmd).create();
        ((AssociateIPAddrCmd) cmd).execute();
    } catch (Exception e) {
        s_logger.debug("AssociateIPAddrCmd exception: " + e);
        e.printStackTrace();
        throw e;
    }
    SearchBuilder<IPAddressVO> searchBuilder = _ipAddressDao.createSearchBuilder();
    searchBuilder.and("sourceNat", searchBuilder.entity().isSourceNat(), Op.EQ);
    searchBuilder.and("network", searchBuilder.entity().getAssociatedWithNetworkId(), Op.EQ);
    searchBuilder.and("dataCenterId", searchBuilder.entity().getDataCenterId(), Op.EQ);
    searchBuilder.and("associatedWithVmId", searchBuilder.entity().getAssociatedWithVmId(), Op.NULL);
    SearchCriteria<IPAddressVO> sc = searchBuilder.create();
    sc.setParameters("sourceNat", false);
    sc.setParameters("network", network.getId());
    List<IPAddressVO> publicIps = _ipAddressDao.search(sc, null);
    assertNotNull(publicIps);
    cmd = new EnableStaticNatCmd();
    proxy = ComponentContext.inject(cmd);
    ManagementServerMock.setParameter(proxy, "ipAddressId", BaseCmd.CommandType.LONG, publicIps.get(0).getId());
    ManagementServerMock.setParameter(proxy, "networkId", BaseCmd.CommandType.LONG, network.getId());
    ManagementServerMock.setParameter(proxy, "virtualMachineId", BaseCmd.CommandType.LONG, vm.getId());
    try {
        proxy.execute();
    } catch (Exception e) {
        s_logger.debug("EnableStaticNatCmd exception: " + e);
        e.printStackTrace();
        throw e;
    }
    return publicIps.get(0);
}
Also used : Account(com.cloud.user.Account) DataCenter(com.cloud.dc.DataCenter) AssociateIPAddrCmd(org.apache.cloudstack.api.command.user.address.AssociateIPAddrCmd) IPAddressVO(com.cloud.network.dao.IPAddressVO) EnableStaticNatCmd(org.apache.cloudstack.api.command.user.nat.EnableStaticNatCmd) BaseCmd(org.apache.cloudstack.api.BaseCmd) CloudException(com.cloud.exception.CloudException) IOException(java.io.IOException)

Example 45 with IPAddressVO

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

the class ConfigurationManagerImpl method checkOverlapPublicIpRange.

private void checkOverlapPublicIpRange(final Long zoneId, final String startIp, final String endIp) {
    final long privateStartIp = NetUtils.ip2Long(startIp);
    final long privateEndIp = NetUtils.ip2Long(endIp);
    final List<IPAddressVO> existingPublicIPs = _publicIpAddressDao.listByDcId(zoneId);
    for (final IPAddressVO publicIPVO : existingPublicIPs) {
        final long publicIP = NetUtils.ip2Long(publicIPVO.getAddress().addr());
        if (publicIP >= privateStartIp && publicIP <= privateEndIp) {
            throw new InvalidParameterValueException("The Start IP and endIP address range overlap with Public IP :" + publicIPVO.getAddress().addr());
        }
    }
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) IPAddressVO(com.cloud.network.dao.IPAddressVO)

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