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);
}
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;
}
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;
}
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;
}
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);
}
Aggregations