Search in sources :

Example 1 with StorageNetworkIpAddressVO

use of com.cloud.dc.StorageNetworkIpAddressVO in project cloudstack by apache.

the class StorageNetworkGuru method reserve.

@Override
public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    if (!_sNwMgr.isStorageIpRangeAvailable(dest.getDataCenter().getId())) {
        super.reserve(nic, network, vm, dest, context);
        return;
    }
    Pod pod = dest.getPod();
    Integer vlan = null;
    StorageNetworkIpAddressVO ip = _sNwMgr.acquireIpAddress(pod.getId());
    if (ip == null) {
        throw new InsufficientAddressCapacityException("Unable to get a storage network ip address", Pod.class, pod.getId());
    }
    vlan = ip.getVlan();
    nic.setIPv4Address(ip.getIpAddress());
    nic.setMacAddress(NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ip.getMac(), NetworkModel.MACIdentifier.value())));
    nic.setFormat(AddressFormat.Ip4);
    nic.setIPv4Netmask(ip.getNetmask());
    nic.setBroadcastType(BroadcastDomainType.Storage);
    nic.setIPv4Gateway(ip.getGateway());
    if (vlan != null) {
        nic.setBroadcastUri(BroadcastDomainType.Storage.toUri(vlan));
    } else {
        nic.setBroadcastUri(null);
    }
    nic.setIsolationUri(null);
    s_logger.debug("Allocated a storage nic " + nic + " for " + vm);
}
Also used : Pod(com.cloud.dc.Pod) StorageNetworkIpAddressVO(com.cloud.dc.StorageNetworkIpAddressVO) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException)

Example 2 with StorageNetworkIpAddressVO

use of com.cloud.dc.StorageNetworkIpAddressVO in project cosmic by MissionCriticalCloud.

the class StorageNetworkIpAddressDaoImpl method takeIpAddress.

@Override
@DB
public StorageNetworkIpAddressVO takeIpAddress(final long rangeId) {
    final SearchCriteria<StorageNetworkIpAddressVO> sc = untakenIp.create();
    sc.setParameters("rangeId", rangeId);
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    final StorageNetworkIpAddressVO ip = lockOneRandomRow(sc, true);
    if (ip == null) {
        txn.rollback();
        return null;
    }
    ip.setTakenAt(new Date());
    update(ip.getId(), ip);
    txn.commit();
    return ip;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) StorageNetworkIpAddressVO(com.cloud.dc.StorageNetworkIpAddressVO) Date(java.util.Date) DB(com.cloud.utils.db.DB)

Example 3 with StorageNetworkIpAddressVO

use of com.cloud.dc.StorageNetworkIpAddressVO in project cosmic by MissionCriticalCloud.

the class StorageNetworkManagerImpl method acquireIpAddress.

@Override
public StorageNetworkIpAddressVO acquireIpAddress(final long podId) {
    final List<StorageNetworkIpRangeVO> ranges = _sNwIpRangeDao.listByPodId(podId);
    for (StorageNetworkIpRangeVO r : ranges) {
        try {
            final Long rangeId = r.getId();
            r = _sNwIpRangeDao.acquireInLockTable(rangeId);
            if (r == null) {
                final String msg = "Unable to acquire lock on storage network ip range id=" + rangeId + ", delete failed";
                s_logger.warn(msg);
                throw new CloudRuntimeException(msg);
            }
            final StorageNetworkIpAddressVO ip = _sNwIpDao.takeIpAddress(r.getId());
            if (ip != null) {
                return ip;
            }
        } finally {
            if (r != null) {
                _sNwIpRangeDao.releaseFromLockTable(r.getId());
            }
        }
    }
    return null;
}
Also used : StorageNetworkIpRangeVO(com.cloud.dc.StorageNetworkIpRangeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StorageNetworkIpAddressVO(com.cloud.dc.StorageNetworkIpAddressVO)

Example 4 with StorageNetworkIpAddressVO

use of com.cloud.dc.StorageNetworkIpAddressVO in project cloudstack by apache.

the class StorageNetworkIpAddressDaoImpl method takeIpAddress.

@Override
@DB
public StorageNetworkIpAddressVO takeIpAddress(long rangeId) {
    SearchCriteria<StorageNetworkIpAddressVO> sc = untakenIp.create();
    sc.setParameters("rangeId", rangeId);
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    StorageNetworkIpAddressVO ip = lockOneRandomRow(sc, true);
    if (ip == null) {
        txn.rollback();
        return null;
    }
    ip.setTakenAt(new Date());
    update(ip.getId(), ip);
    txn.commit();
    return ip;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) StorageNetworkIpAddressVO(com.cloud.dc.StorageNetworkIpAddressVO) Date(java.util.Date) DB(com.cloud.utils.db.DB)

Example 5 with StorageNetworkIpAddressVO

use of com.cloud.dc.StorageNetworkIpAddressVO in project cloudstack by apache.

the class StorageNetworkIpAddressDaoImpl method releaseIpAddress.

@Override
public void releaseIpAddress(String ip) {
    SearchCriteria<StorageNetworkIpAddressVO> sc = ipSearch.create();
    sc.setParameters("ipAddress", ip);
    StorageNetworkIpAddressVO vo = createForUpdate();
    vo.setTakenAt(null);
    update(vo, sc);
}
Also used : StorageNetworkIpAddressVO(com.cloud.dc.StorageNetworkIpAddressVO)

Aggregations

StorageNetworkIpAddressVO (com.cloud.dc.StorageNetworkIpAddressVO)8 Pod (com.cloud.dc.Pod)2 StorageNetworkIpRangeVO (com.cloud.dc.StorageNetworkIpRangeVO)2 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)2 DB (com.cloud.utils.db.DB)2 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 Date (java.util.Date)2