Search in sources :

Example 1 with ReservationStrategy

use of com.cloud.legacymodel.network.Nic.ReservationStrategy in project cosmic by MissionCriticalCloud.

the class DirectPodBasedNetworkGuru method allocate.

@Override
public NicProfile allocate(final Network network, NicProfile nic, final VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {
    final DataCenterVO dc = _dcDao.findById(network.getDataCenterId());
    ReservationStrategy rsStrategy = ReservationStrategy.Start;
    _dcDao.loadDetails(dc);
    final String dhcpStrategy = dc.getDetail(ZoneConfig.DhcpStrategy.key());
    if ("external".equalsIgnoreCase(dhcpStrategy)) {
        rsStrategy = ReservationStrategy.Create;
    }
    if (nic != null && nic.getRequestedIPv4() != null) {
        throw new CloudRuntimeException("Does not support custom ip allocation at this time: " + nic);
    }
    if (nic == null) {
        nic = new NicProfile(rsStrategy, null, null, null, null);
    } else if (nic.getIPv4Address() == null) {
        nic.setReservationStrategy(ReservationStrategy.Start);
    } else {
        nic.setReservationStrategy(ReservationStrategy.Create);
    }
    if (rsStrategy == ReservationStrategy.Create) {
        final String mac = _networkModel.getNextAvailableMacAddressInNetwork(network.getId());
        nic.setMacAddress(mac);
    }
    return nic;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ReservationStrategy(com.cloud.legacymodel.network.Nic.ReservationStrategy) NicProfile(com.cloud.vm.NicProfile)

Aggregations

DataCenterVO (com.cloud.dc.DataCenterVO)1 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1 ReservationStrategy (com.cloud.legacymodel.network.Nic.ReservationStrategy)1 NicProfile (com.cloud.vm.NicProfile)1