Search in sources :

Example 1 with State

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);
    }
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) State(com.cloud.network.IpAddress.State) Ip(com.cloud.utils.net.Ip) IPAddressVO(com.cloud.network.dao.IPAddressVO) Test(org.junit.Test)

Example 2 with State

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;
}
Also used : IpAddresses(com.cloud.network.Network.IpAddresses) State(com.cloud.network.IpAddress.State) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) IPAddressVO(com.cloud.network.dao.IPAddressVO) DB(com.cloud.utils.db.DB)

Aggregations

State (com.cloud.network.IpAddress.State)2 IPAddressVO (com.cloud.network.dao.IPAddressVO)2 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 IpAddresses (com.cloud.network.Network.IpAddresses)1 DB (com.cloud.utils.db.DB)1 Ip (com.cloud.utils.net.Ip)1 Test (org.junit.Test)1