use of com.cloud.dc.StorageNetworkIpRangeVO in project cloudstack by apache.
the class StorageNetworkManagerImpl method deleteIpRange.
@Override
@DB
public void deleteIpRange(DeleteStorageNetworkIpRangeCmd cmd) {
final long rangeId = cmd.getId();
StorageNetworkIpRangeVO range = _sNwIpRangeDao.findById(rangeId);
if (range == null) {
throw new CloudRuntimeException("Can not find storage network ip range " + rangeId);
}
if (_sNwIpDao.countInUseIpByRangeId(rangeId) > 0) {
throw new CloudRuntimeException(getInUseIpAddress(rangeId));
}
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
StorageNetworkIpRangeVO range = null;
try {
range = _sNwIpRangeDao.acquireInLockTable(rangeId);
if (range == null) {
String msg = "Unable to acquire lock on storage network ip range id=" + rangeId + ", delete failed";
s_logger.warn(msg);
throw new CloudRuntimeException(msg);
}
/*
* entries in op_dc_storage_network_ip_address will be deleted automatically due to
* fk_storage_ip_address__range_id constraint key
*/
_sNwIpRangeDao.remove(rangeId);
} finally {
if (range != null) {
_sNwIpRangeDao.releaseFromLockTable(rangeId);
}
}
}
});
}
use of com.cloud.dc.StorageNetworkIpRangeVO in project cloudstack by apache.
the class StorageNetworkManagerImpl method createIpRange.
@Override
@DB
public StorageNetworkIpRange createIpRange(final CreateStorageNetworkIpRangeCmd cmd) throws SQLException {
final Long podId = cmd.getPodId();
final String startIp = cmd.getStartIp();
String endIp = cmd.getEndIp();
final Integer vlan = cmd.getVlan();
final String netmask = cmd.getNetmask();
if (endIp == null) {
endIp = startIp;
}
if (!NetUtils.isValidIp4Netmask(netmask)) {
throw new CloudRuntimeException("Invalid netmask:" + netmask);
}
HostPodVO pod = _podDao.findById(podId);
if (pod == null) {
throw new CloudRuntimeException("Cannot find pod " + podId);
}
final Long zoneId = pod.getDataCenterId();
List<NetworkVO> nws = _networkDao.listByZoneAndTrafficType(zoneId, TrafficType.Storage);
if (nws.size() == 0) {
throw new CloudRuntimeException("Cannot find storage network in zone " + zoneId);
}
if (nws.size() > 1) {
throw new CloudRuntimeException("Find more than one storage network in zone " + zoneId + "," + nws.size() + " found");
}
final NetworkVO nw = nws.get(0);
checkOverlapPrivateIpRange(podId, startIp, endIp);
checkOverlapStorageIpRange(podId, startIp, endIp);
StorageNetworkIpRangeVO range = null;
final String endIpFinal = endIp;
return Transaction.execute(new TransactionCallbackWithException<StorageNetworkIpRangeVO, SQLException>() {
@Override
public StorageNetworkIpRangeVO doInTransaction(TransactionStatus status) throws SQLException {
StorageNetworkIpRangeVO range = new StorageNetworkIpRangeVO(zoneId, podId, nw.getId(), startIp, endIpFinal, vlan, netmask, cmd.getGateWay());
_sNwIpRangeDao.persist(range);
try {
createStorageIpEntires(TransactionLegacy.currentTxn(), range.getId(), startIp, endIpFinal, zoneId);
} catch (SQLException e) {
StringBuilder err = new StringBuilder();
err.append("Create storage network range failed.");
err.append("startIp=" + startIp);
err.append("endIp=" + endIpFinal);
err.append("netmask=" + netmask);
err.append("zoneId=" + zoneId);
s_logger.debug(err.toString(), e);
throw e;
}
return range;
}
});
}
use of com.cloud.dc.StorageNetworkIpRangeVO in project cloudstack by apache.
the class StorageNetworkManagerImpl method updateIpRange.
@Override
@DB
public StorageNetworkIpRange updateIpRange(UpdateStorageNetworkIpRangeCmd cmd) {
final Integer vlan = cmd.getVlan();
final Long rangeId = cmd.getId();
String startIp = cmd.getStartIp();
String endIp = cmd.getEndIp();
final String netmask = cmd.getNetmask();
if (netmask != null && !NetUtils.isValidIp4Netmask(netmask)) {
throw new CloudRuntimeException("Invalid netmask:" + netmask);
}
if (_sNwIpDao.countInUseIpByRangeId(rangeId) > 0) {
throw new CloudRuntimeException("Cannot update the range," + getInUseIpAddress(rangeId));
}
StorageNetworkIpRangeVO range = _sNwIpRangeDao.findById(rangeId);
if (range == null) {
throw new CloudRuntimeException("Cannot find storage ip range " + rangeId);
}
if (startIp != null || endIp != null) {
long podId = range.getPodId();
startIp = startIp == null ? range.getStartIp() : startIp;
endIp = endIp == null ? range.getEndIp() : endIp;
checkOverlapPrivateIpRange(podId, startIp, endIp);
checkOverlapStorageIpRange(podId, startIp, endIp);
}
final String startIpFinal = startIp;
final String endIpFinal = endIp;
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
StorageNetworkIpRangeVO range = null;
try {
range = _sNwIpRangeDao.acquireInLockTable(rangeId);
if (range == null) {
throw new CloudRuntimeException("Cannot acquire lock on storage ip range " + rangeId);
}
StorageNetworkIpRangeVO vo = _sNwIpRangeDao.createForUpdate();
if (vlan != null) {
vo.setVlan(vlan);
}
if (startIpFinal != null) {
vo.setStartIp(startIpFinal);
}
if (endIpFinal != null) {
vo.setEndIp(endIpFinal);
}
if (netmask != null) {
vo.setNetmask(netmask);
}
_sNwIpRangeDao.update(rangeId, vo);
} finally {
if (range != null) {
_sNwIpRangeDao.releaseFromLockTable(range.getId());
}
}
}
});
return _sNwIpRangeDao.findById(rangeId);
}
Aggregations