Search in sources :

Example 1 with ReservationStrategy

use of com.cloud.vm.Nic.ReservationStrategy in project cloudstack by apache.

the class DirectPodBasedNetworkGuru method allocate.

@Override
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {
    DataCenterVO dc = _dcDao.findById(network.getDataCenterId());
    ReservationStrategy rsStrategy = ReservationStrategy.Start;
    _dcDao.loadDetails(dc);
    String dhcpStrategy = dc.getDetail(ZoneConfig.DhcpStrategy.key());
    if ("external".equalsIgnoreCase(dhcpStrategy)) {
        rsStrategy = ReservationStrategy.Create;
    }
    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) {
        String mac = _networkModel.getNextAvailableMacAddressInNetwork(network.getId());
        nic.setMacAddress(mac);
    }
    return nic;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ReservationStrategy(com.cloud.vm.Nic.ReservationStrategy) NicProfile(com.cloud.vm.NicProfile)

Example 2 with ReservationStrategy

use of com.cloud.vm.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.utils.exception.CloudRuntimeException) ReservationStrategy(com.cloud.vm.Nic.ReservationStrategy) NicProfile(com.cloud.vm.NicProfile)

Aggregations

DataCenterVO (com.cloud.dc.DataCenterVO)2 ReservationStrategy (com.cloud.vm.Nic.ReservationStrategy)2 NicProfile (com.cloud.vm.NicProfile)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1