use of com.cloud.network.vpc.StaticRoute in project cloudstack by apache.
the class ListStaticRoutesCmd method execute.
@Override
public void execute() {
Pair<List<? extends StaticRoute>, Integer> result = _vpcService.listStaticRoutes(this);
ListResponse<StaticRouteResponse> response = new ListResponse<StaticRouteResponse>();
List<StaticRouteResponse> routeResponses = new ArrayList<StaticRouteResponse>();
for (StaticRoute route : result.first()) {
StaticRouteResponse ruleData = _responseGenerator.createStaticRouteResponse(route);
routeResponses.add(ruleData);
}
response.setResponses(routeResponses, result.second());
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of com.cloud.network.vpc.StaticRoute in project cloudstack by apache.
the class CreateStaticRouteCmd method create.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void create() throws ResourceAllocationException {
try {
StaticRoute result = _vpcService.createStaticRoute(getGatewayId(), getCidr());
setEntityId(result.getId());
setEntityUuid(result.getUuid());
} catch (NetworkRuleConflictException ex) {
s_logger.info("Network rule conflict: " + ex.getMessage());
s_logger.trace("Network rule conflict: ", ex);
throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage());
}
}
use of com.cloud.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.network.vpc.StaticRoute in project cosmic by MissionCriticalCloud.
the class CreateStaticRouteCmd method create.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void create() throws ResourceAllocationException {
try {
checkDeprecatedParameters();
final StaticRoute result = _vpcService.createStaticRoute(getVpcId(), getCidr(), getNextHop());
setEntityId(result.getId());
setEntityUuid(result.getUuid());
} catch (final NetworkRuleConflictException ex) {
s_logger.info("Network rule conflict: " + ex.getMessage());
s_logger.trace("Network rule conflict: ", ex);
throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage());
}
}
use of com.cloud.network.vpc.StaticRoute in project cloudstack by apache.
the class CreateStaticRouteCmd method execute.
@Override
public void execute() throws ResourceUnavailableException {
boolean success = false;
StaticRoute route = null;
try {
CallContext.current().setEventDetails("Static route Id: " + getEntityId());
success = _vpcService.applyStaticRoute(getEntityId());
// State is different after the route is applied, so retrieve the object only here
route = _entityMgr.findById(StaticRoute.class, getEntityId());
StaticRouteResponse routeResponse = new StaticRouteResponse();
if (route != null) {
routeResponse = _responseGenerator.createStaticRouteResponse(route);
setResponseObject(routeResponse);
}
routeResponse.setResponseName(getCommandName());
} finally {
if (!success || route == null) {
_entityMgr.remove(StaticRoute.class, getEntityId());
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create static route");
}
}
}
Aggregations