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);
}
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);
}
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);
}
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);
}
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());
}
}
}
Aggregations