mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
fixing import in virtual router element and checkstyle in dhcp entry related changes
Conflicts: server/src/com/cloud/network/element/VirtualRouterElement.java server/src/com/cloud/network/rules/DhcpEntryRules.java server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java server/src/org/apache/cloudstack/network/topology/BasicNetworkTopology.java server/src/org/apache/cloudstack/network/topology/BasicNetworkVisitor.java
This commit is contained in:
parent
869f0ad375
commit
0b78731bc7
@ -157,6 +157,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
|
||||
@Inject
|
||||
NetworkTopologyContext networkTopologyContext;
|
||||
|
||||
@Inject
|
||||
private RouterDeploymentDefinitionBuilder routerDeploymentDefinitionBuilder;
|
||||
|
||||
@ -959,6 +960,9 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
|
||||
}
|
||||
|
||||
DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
|
||||
NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
|
||||
|
||||
return _routerMgr.applyDhcpEntry(network, nic, uservm, dest, routers);
|
||||
}
|
||||
return false;
|
||||
|
||||
@ -19,43 +19,116 @@ package com.cloud.network.rules;
|
||||
|
||||
import org.apache.cloudstack.network.topology.NetworkTopologyVisitor;
|
||||
|
||||
import com.cloud.agent.api.routing.DhcpEntryCommand;
|
||||
import com.cloud.agent.api.routing.NetworkElementCommand;
|
||||
import com.cloud.agent.manager.Commands;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Network.Provider;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.router.VirtualRouter;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.Nic;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
public class DhcpEntryRules extends RuleApplier {
|
||||
|
||||
private final NicProfile nic;
|
||||
private final VirtualMachineProfile profile;
|
||||
private final DeployDestination destination;
|
||||
private final NicProfile _nic;
|
||||
private final VirtualMachineProfile _profile;
|
||||
private final DeployDestination _destination;
|
||||
|
||||
private NicVO _nicVo;
|
||||
private UserVmVO _userVM;
|
||||
|
||||
public DhcpEntryRules(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination destination) {
|
||||
super(network);
|
||||
|
||||
this.nic = nic;
|
||||
this.profile = profile;
|
||||
this.destination = destination;
|
||||
_nic = nic;
|
||||
_profile = profile;
|
||||
_destination = destination;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
|
||||
this._router = router;
|
||||
_router = router;
|
||||
|
||||
_userVM = _userVmDao.findById(_profile.getId());
|
||||
_userVmDao.loadDetails(_userVM);
|
||||
_nicVo = _nicDao.findById(_nic.getId());
|
||||
|
||||
return visitor.visit(this);
|
||||
}
|
||||
|
||||
public NicProfile getNic() {
|
||||
return nic;
|
||||
return _nic;
|
||||
}
|
||||
|
||||
public VirtualMachineProfile getProfile() {
|
||||
return profile;
|
||||
public NicVO getNicVo() {
|
||||
return _nicVo;
|
||||
}
|
||||
|
||||
public UserVmVO getUserVM() {
|
||||
return _userVM;
|
||||
}
|
||||
|
||||
public DeployDestination getDestination() {
|
||||
return destination;
|
||||
return _destination;
|
||||
}
|
||||
|
||||
public void createDhcpEntryCommand(final VirtualRouter router, final UserVm vm, final NicVO nic, final Commands cmds) {
|
||||
final DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), vm.getHostName(), nic.getIp6Address(),
|
||||
_networkModel.getExecuteInSeqNtwkElmtCmd());
|
||||
final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
|
||||
final Nic defaultNic = findGatewayIp(vm.getId());
|
||||
String gatewayIp = defaultNic.getGateway();
|
||||
if (gatewayIp != null && !gatewayIp.equals(nic.getGateway())) {
|
||||
gatewayIp = "0.0.0.0";
|
||||
}
|
||||
dhcpCommand.setDefaultRouter(gatewayIp);
|
||||
dhcpCommand.setIp6Gateway(nic.getIp6Gateway());
|
||||
String ipaddress = null;
|
||||
final NicVO domrDefaultNic = findDefaultDnsIp(vm.getId());
|
||||
if (domrDefaultNic != null) {
|
||||
ipaddress = domrDefaultNic.getIp4Address();
|
||||
}
|
||||
dhcpCommand.setDefaultDns(ipaddress);
|
||||
dhcpCommand.setDuid(NetUtils.getDuidLL(nic.getMacAddress()));
|
||||
dhcpCommand.setDefault(nic.isDefaultNic());
|
||||
|
||||
dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
|
||||
dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
|
||||
dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(nic.getNetworkId(), router.getId()));
|
||||
dhcpCommand.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
|
||||
|
||||
cmds.addCommand("dhcp", dhcpCommand);
|
||||
}
|
||||
|
||||
private NicVO findGatewayIp(final long userVmId) {
|
||||
final NicVO defaultNic = _nicDao.findDefaultNicForVM(userVmId);
|
||||
return defaultNic;
|
||||
}
|
||||
|
||||
private NicVO findDefaultDnsIp(final long userVmId) {
|
||||
final NicVO defaultNic = _nicDao.findDefaultNicForVM(userVmId);
|
||||
|
||||
// check if DNS provider is the domR
|
||||
if (!_networkModel.isProviderSupportServiceInNetwork(defaultNic.getNetworkId(), Service.Dns, Provider.VirtualRouter)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final NetworkOffering offering = _networkOfferingDao.findById(_networkDao.findById(defaultNic.getNetworkId()).getNetworkOfferingId());
|
||||
if (offering.getRedundantRouter()) {
|
||||
return findGatewayIp(userVmId);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -27,6 +27,7 @@ import org.springframework.stereotype.Component;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.rules.DhcpEntryRules;
|
||||
import com.cloud.network.rules.RuleApplier;
|
||||
import com.cloud.network.rules.RuleApplierWrapper;
|
||||
import com.cloud.network.rules.UserdataPwdRules;
|
||||
@ -58,4 +59,20 @@ public class AdvancedNetworkTopology extends BasicNetworkTopology {
|
||||
|
||||
return applyRules(network, routers, typeString, isPodLevelException, podId, failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(pwdRules));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyDhcpEntry(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination dest,
|
||||
final List<DomainRouterVO> routers) throws ResourceUnavailableException {
|
||||
|
||||
s_logger.debug("APPLYING DHCP ENTRY RULES");
|
||||
|
||||
final String typeString = "dhcp entry";
|
||||
final Long podId = null;
|
||||
final boolean isPodLevelException = false;
|
||||
final boolean failWhenDisconnect = false;
|
||||
|
||||
DhcpEntryRules dhcpRules = _virtualNetworkApplianceFactory.createDhcpEntryRules(network, nic, profile, dest);
|
||||
|
||||
return applyRules(network, routers, typeString, isPodLevelException, podId, failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(dhcpRules));
|
||||
}
|
||||
}
|
||||
@ -109,7 +109,28 @@ public class BasicNetworkTopology implements NetworkTopology {
|
||||
@Override
|
||||
public boolean applyDhcpEntry(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination dest,
|
||||
final List<DomainRouterVO> routers) throws ResourceUnavailableException {
|
||||
<<<<<<< HEAD
|
||||
return false;
|
||||
=======
|
||||
|
||||
s_logger.debug("APPLYING DHCP ENTRY RULES");
|
||||
|
||||
final String typeString = "dhcp entry";
|
||||
final Long podId = dest.getPod().getId();
|
||||
boolean isPodLevelException = false;
|
||||
|
||||
//for user vm in Basic zone we should try to re-deploy vm in a diff pod if it fails to deploy in original pod; so throwing exception with Pod scope
|
||||
if (podId != null && profile.getVirtualMachine().getType() == VirtualMachine.Type.User && network.getTrafficType() == TrafficType.Guest &&
|
||||
network.getGuestType() == Network.GuestType.Shared) {
|
||||
isPodLevelException = true;
|
||||
}
|
||||
|
||||
final boolean failWhenDisconnect = false;
|
||||
|
||||
DhcpEntryRules dhcpRules = _virtualNetworkApplianceFactory.createDhcpEntryRules(network, nic, profile, dest);
|
||||
|
||||
return applyRules(network, routers, typeString, isPodLevelException, podId, failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(dhcpRules));
|
||||
>>>>>>> ee0389b... fixing import in virtual router element and checkstyle in dhcp entry related changes
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -168,7 +168,19 @@ public class BasicNetworkVisitor extends NetworkTopologyVisitor {
|
||||
|
||||
@Override
|
||||
public boolean visit(final DhcpEntryRules dhcp) throws ResourceUnavailableException {
|
||||
return false;
|
||||
final VirtualRouter router = dhcp.getRouter();
|
||||
|
||||
final Commands commands = new Commands(Command.OnError.Stop);
|
||||
final NicVO nicVo = dhcp.getNicVo();
|
||||
final UserVmVO userVM = dhcp.getUserVM();
|
||||
final DeployDestination destination = dhcp.getDestination();
|
||||
|
||||
if (router.getPodIdToDeployIn().longValue() == destination.getPod().getId()) {
|
||||
dhcp.createDhcpEntryCommand(router, userVM, nicVo, commands);
|
||||
|
||||
return _applianceManager.sendCommandsToRouter(router, commands);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -19,8 +19,6 @@ package org.apache.cloudstack.network.topology;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user