use of com.cloud.network.IpAddress.State in project cloudstack by apache.
the class NetworkOrchestratorTest method validateLockedRequestedIpTestNotFreeLockedIp.
@Test
public void validateLockedRequestedIpTestNotFreeLockedIp() {
IPAddressVO ipVoSpy = Mockito.spy(new IPAddressVO(new Ip("192.168.100.100"), 0l, 0l, 0l, true));
State[] states = State.values();
for (int i = 0; i < states.length; i++) {
boolean expectedException = false;
if (states[i] == State.Free) {
continue;
}
IPAddressVO lockedIp = ipVoSpy;
lockedIp.setState(states[i]);
try {
testOrchastrator.validateLockedRequestedIp(ipVoSpy, lockedIp);
} catch (InvalidParameterValueException e) {
expectedException = true;
}
Assert.assertTrue(expectedException);
}
}
use of com.cloud.network.IpAddress.State in project cloudstack by apache.
the class Ipv6AddressManagerImpl method acquireGuestIpv6Address.
/**
* Allocates a guest IPv6 address for the guest NIC. It will throw exceptions in the following cases:
* <ul>
* <li>there is no IPv6 address available in the network;</li>
* <li>IPv6 address is equals to the Gateway;</li>
* <li>the network offering is empty;</li>
* <li>the IPv6 address is not in the network;</li>
* <li>the requested IPv6 address is already in use in the network.</li>
* </ul>
*/
@Override
@DB
public String acquireGuestIpv6Address(Network network, String requestedIpv6) throws InsufficientAddressCapacityException {
if (!_networkModel.areThereIPv6AddressAvailableInNetwork(network.getId())) {
throw new InsufficientAddressCapacityException(String.format("There is no IPv6 address available in the network [name=%s, network id=%s]", network.getName(), network.getId()), DataCenter.class, network.getDataCenterId());
}
if (NetUtils.isIPv6EUI64(requestedIpv6)) {
throw new InsufficientAddressCapacityException(String.format("Requested IPv6 address [%s] may not be a EUI-64 address", requestedIpv6), DataCenter.class, network.getDataCenterId());
}
checkIfCanAllocateIpv6Address(network, requestedIpv6);
IpAddresses requestedIpPair = new IpAddresses(null, requestedIpv6);
_networkModel.checkRequestedIpAddresses(network.getId(), requestedIpPair);
IPAddressVO ip = ipAddressDao.findByIpAndSourceNetworkId(network.getId(), requestedIpv6);
if (ip != null) {
State ipState = ip.getState();
if (ipState != State.Free) {
throw new InsufficientAddressCapacityException(String.format("Requested ip address [%s] is not free [ip state=%]", requestedIpv6, ipState), DataCenter.class, network.getDataCenterId());
}
}
return requestedIpv6;
}
Aggregations