mirror of https://github.com/apache/cloudstack.git
Fixed ipAssoc command to throw an exception when virtual network is null
This commit is contained in:
parent
d6360707c7
commit
4ca2b8808b
|
|
@ -30,6 +30,7 @@ import com.cloud.api.response.IPAddressResponse;
|
|||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.IpAddress;
|
||||
|
|
@ -87,7 +88,7 @@ public class AssociateIPAddrCmd extends BaseCmd {
|
|||
|
||||
List<? extends Network> networks = _networkService.getVirtualNetworksOwnedByAccountInZone(getAccountName(), getDomainId(), getZoneId());
|
||||
if (networks.size() == 0) {
|
||||
return null;
|
||||
throw new InvalidParameterValueException("Account name=" + getAccountName() + " domainId=" + getDomainId() + " doesn't have virtual networks in zone " + getZoneId());
|
||||
}
|
||||
assert (networks.size() <= 1) : "Too many virtual networks. This logic should be obsolete";
|
||||
return networks.get(0).getId();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import javax.ejb.Local;
|
|||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
|
|
@ -63,17 +64,17 @@ public class DomainRouterElement extends AdapterBase implements NetworkElement {
|
|||
@Inject UserVmManager _userVmMgr;
|
||||
@Inject UserVmDao _userVmDao;
|
||||
@Inject DomainRouterDao _routerDao;
|
||||
@Inject DataCenterDao _dataCenterDao;
|
||||
|
||||
|
||||
private boolean canHandle(GuestIpType ipType, DeployDestination dest) {
|
||||
DataCenter dc = dest.getDataCenter();
|
||||
private boolean canHandle(GuestIpType ipType, DataCenter dc) {
|
||||
String provider = dc.getGatewayProvider();
|
||||
return (ipType == GuestIpType.Virtual && provider.equals(Providers.VirtualRouter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean implement(Network guestConfig, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException {
|
||||
if (canHandle(offering.getGuestIpType(), dest)) {
|
||||
if (canHandle(offering.getGuestIpType(), dest.getDataCenter())) {
|
||||
DomainRouterVO router = _routerMgr.deployVirtualRouter(guestConfig, dest, context.getAccount());
|
||||
if (router == null) {
|
||||
throw new ResourceUnavailableException("Unable to deploy the router for " + guestConfig);
|
||||
|
|
@ -87,8 +88,7 @@ public class DomainRouterElement extends AdapterBase implements NetworkElement {
|
|||
|
||||
@Override
|
||||
public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientNetworkCapacityException, ResourceUnavailableException {
|
||||
if (canHandle(config.getGuestType(), dest)) {
|
||||
|
||||
if (canHandle(config.getGuestType(), dest.getDataCenter())) {
|
||||
if (vm.getType() != VirtualMachine.Type.User) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -118,12 +118,22 @@ public class DomainRouterElement extends AdapterBase implements NetworkElement {
|
|||
|
||||
@Override
|
||||
public boolean applyRules(Network config, List<? extends FirewallRule> rules) throws ResourceUnavailableException {
|
||||
return true;
|
||||
DataCenter dc = _dataCenterDao.findById(config.getDataCenterId());
|
||||
if (canHandle(config.getGuestType(),dc)) {
|
||||
return _routerMgr.applyFirewallRules(config, rules);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyIps(Network network, List<? extends IpAddress> ipAddress) throws ResourceUnavailableException {
|
||||
return _routerMgr.associateIP(network, ipAddress);
|
||||
DataCenter dc = _dataCenterDao.findById(network.getDataCenterId());
|
||||
if (canHandle(network.getGuestType(),dc)) {
|
||||
return _routerMgr.associateIP(network, ipAddress);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ package com.cloud.network.router;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.agent.manager.Commands;
|
||||
import com.cloud.api.commands.UpgradeRouterCmd;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.HostPodVO;
|
||||
|
|
@ -32,11 +31,11 @@ import com.cloud.exception.InsufficientNetworkCapacityException;
|
|||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.IPAddressVO;
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.RemoteAccessVpnVO;
|
||||
import com.cloud.network.VpnUserVO;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.uservm.UserVm;
|
||||
|
|
@ -163,4 +162,6 @@ public interface DomainRouterManager extends Manager {
|
|||
DomainRouterVO addVirtualMachineIntoNetwork(Network config, NicProfile nic, VirtualMachineProfile<UserVm> vm, DeployDestination dest, ReservationContext context, Boolean startDhcp) throws ConcurrentOperationException, InsufficientNetworkCapacityException, ResourceUnavailableException;
|
||||
|
||||
boolean associateIP (Network network, List<? extends IpAddress> ipAddress);
|
||||
|
||||
boolean applyFirewallRules(Network network, List<? extends FirewallRule> rules);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ import com.cloud.agent.api.routing.DhcpEntryCommand;
|
|||
import com.cloud.agent.api.routing.IPAssocCommand;
|
||||
import com.cloud.agent.api.routing.RemoteAccessVpnCfgCommand;
|
||||
import com.cloud.agent.api.routing.SavePasswordCommand;
|
||||
import com.cloud.agent.api.routing.SetPortForwardingRulesCommand;
|
||||
import com.cloud.agent.api.routing.VmDataCommand;
|
||||
import com.cloud.agent.api.routing.VpnUsersCfgCommand;
|
||||
import com.cloud.agent.manager.Commands;
|
||||
|
|
@ -131,7 +130,7 @@ import com.cloud.network.dao.NetworkRuleConfigDao;
|
|||
import com.cloud.network.dao.RemoteAccessVpnDao;
|
||||
import com.cloud.network.dao.VpnUserDao;
|
||||
import com.cloud.network.router.VirtualRouter.Role;
|
||||
import com.cloud.network.rules.PortForwardingRule;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.network.rules.PortForwardingRuleVO;
|
||||
import com.cloud.network.rules.RulesManager;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
|
|
@ -2733,4 +2732,10 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
|
|||
throw new ResourceUnavailableException("Unable to assign ip addresses, domR is not in right state " + router.getState());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyFirewallRules(Network network, List<? extends FirewallRule> rules) {
|
||||
//TODO - apply port forwarding and load balancing rules here
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue