Search in sources :

Example 1 with PrivateAllocationData

use of com.cloud.dc.dao.DataCenterDao.PrivateAllocationData in project cloudstack by apache.

the class PodBasedNetworkGuru method reserve.

@Override
public void reserve(NicProfile nic, Network config, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    Pod pod = dest.getPod();
    boolean forSystemVms = vm.getType().equals(VirtualMachine.Type.ConsoleProxy) || vm.getType().equals(VirtualMachine.Type.SecondaryStorageVm);
    PrivateAllocationData result = _dcDao.allocatePrivateIpAddress(dest.getDataCenter().getId(), dest.getPod().getId(), nic.getId(), context.getReservationId(), forSystemVms);
    if (result == null) {
        throw new InsufficientAddressCapacityException("Unable to get a management ip address", Pod.class, pod.getId());
    }
    Integer vlan = result.getVlan();
    nic.setIPv4Address(result.getIpAddress());
    nic.setMacAddress(NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(result.getMacAddress(), NetworkModel.MACIdentifier.value())));
    nic.setIPv4Gateway(pod.getGateway());
    nic.setFormat(AddressFormat.Ip4);
    String netmask = NetUtils.getCidrNetmask(pod.getCidrSize());
    nic.setIPv4Netmask(netmask);
    nic.setBroadcastType(BroadcastDomainType.Native);
    if (vlan != null) {
        nic.setBroadcastUri(BroadcastDomainType.Native.toUri(vlan));
    } else {
        nic.setBroadcastUri(null);
    }
    nic.setIsolationUri(null);
    s_logger.debug("Allocated a nic " + nic + " for " + vm);
}
Also used : Pod(com.cloud.dc.Pod) PrivateAllocationData(com.cloud.dc.dao.DataCenterDao.PrivateAllocationData) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException)

Aggregations

Pod (com.cloud.dc.Pod)1 PrivateAllocationData (com.cloud.dc.dao.DataCenterDao.PrivateAllocationData)1 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)1