use of com.cloud.legacymodel.network.vpc.StaticRoute in project cosmic by MissionCriticalCloud.
the class NetworkServiceImpl method deleteNetwork.
@Override
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_DELETE, eventDescription = "deleting network", async = true)
public boolean deleteNetwork(final long networkId, final boolean forced) {
final Account caller = CallContext.current().getCallingAccount();
// Verify network id
final NetworkVO network = _networksDao.findById(networkId);
if (network == null) {
// see NetworkVO.java
final InvalidParameterValueException ex = new InvalidParameterValueException("unable to find network with specified id");
ex.addProxyObject(String.valueOf(networkId), "networkId");
throw ex;
}
// don't allow to delete system network
if (isNetworkSystem(network)) {
final InvalidParameterValueException ex = new InvalidParameterValueException("Network with specified id is system and can't be removed");
ex.addProxyObject(network.getUuid(), "networkId");
throw ex;
}
final Account owner = _accountMgr.getAccount(network.getAccountId());
// Only Admin can delete Shared networks
if (network.getGuestType() == GuestType.Shared && !_accountMgr.isAdmin(caller.getId())) {
throw new InvalidParameterValueException("Only Admins can delete network with guest type " + GuestType.Shared);
}
// Perform permission check
_accountMgr.checkAccess(caller, null, true, network);
if (forced && !_accountMgr.isRootAdmin(caller.getId())) {
throw new InvalidParameterValueException("Delete network with 'forced' option can only be called by root admins");
}
// VPC networks should be checked for static routes before deletion
if (network.getVpcId() != null) {
// don't allow to remove network tier when there are static routes pointing to an ipaddress in the tier CIDR.
final List<? extends StaticRoute> routes = _staticRouteDao.listByVpcIdAndNotRevoked(network.getVpcId());
for (final StaticRoute route : routes) {
if (NetUtils.isIpWithtInCidrRange(route.getGwIpAddress(), network.getCidr())) {
throw new CloudRuntimeException("Can't delete network " + network.getName() + " as it has static routes " + "applied pointing to the CIDR of the network (" + network.getCidr() + "). Example static route: " + route.getCidr() + " to " + route.getGwIpAddress() + ". Please remove all the routes pointing to the " + "network tier CIDR before attempting to delete it.");
}
}
}
final User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
final ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
return _networkMgr.destroyNetwork(networkId, context, forced);
}
use of com.cloud.legacymodel.network.vpc.StaticRoute in project cosmic by MissionCriticalCloud.
the class VpcManagerImpl method deleteVpcPrivateGateway.
@Override
@ActionEvent(eventType = EventTypes.EVENT_PRIVATE_GATEWAY_DELETE, eventDescription = "deleting private gateway")
@DB
public boolean deleteVpcPrivateGateway(final long gatewayId) throws ConcurrentOperationException, ResourceUnavailableException {
final VpcGatewayVO gatewayVO = _vpcGatewayDao.acquireInLockTable(gatewayId);
if (gatewayVO == null || gatewayVO.getType() != VpcGateway.Type.Private) {
throw new ConcurrentOperationException("Unable to lock gateway " + gatewayId);
}
try {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
// don't allow to remove gateway when there are static routes pointing to an ipaddress in the private gateway CIDR.
final List<? extends StaticRoute> routes = _staticRouteDao.listByVpcIdAndNotRevoked(gatewayVO.getVpcId());
final NetworkVO network = _ntwkDao.findById(gatewayVO.getNetworkId());
final List<String> wrongCidrs = new LinkedList<>();
for (final StaticRoute route : routes) {
if (NetUtils.isIpWithtInCidrRange(route.getGwIpAddress(), network.getCidr())) {
wrongCidrs.add(route.getCidr());
}
}
if (!wrongCidrs.isEmpty()) {
throw new InvalidParameterValueException("Unable to delete Private Gateway. Please remove these static routes pointing to the private gateway CIDR" + " before attempting to delete the gateway: " + wrongCidrs);
}
gatewayVO.setState(VpcGateway.State.Deleting);
_vpcGatewayDao.update(gatewayVO.getId(), gatewayVO);
s_logger.debug("Marked gateway " + gatewayVO + " with state " + VpcGateway.State.Deleting);
}
});
// Delete the gateway on the backend
final List<Provider> providersToImplement = getVpcProviders(gatewayVO.getVpcId());
final PrivateGateway gateway = getVpcPrivateGateway(gatewayId);
for (final VpcProvider provider : getVpcElements()) {
if (providersToImplement.contains(provider.getProvider())) {
if (provider.deletePrivateGateway(gateway)) {
s_logger.debug("Private gateway " + gateway + " was applied succesfully on the backend");
} else {
s_logger.warn("Private gateway " + gateway + " failed to apply on the backend");
gatewayVO.setState(VpcGateway.State.Ready);
_vpcGatewayDao.update(gatewayVO.getId(), gatewayVO);
s_logger.debug("Marked gateway " + gatewayVO + " with state " + VpcGateway.State.Ready);
return false;
}
}
}
return deletePrivateGatewayFromTheDB(gateway);
} finally {
_vpcGatewayDao.releaseFromLockTable(gatewayId);
}
}
Aggregations