Skip to content

Commit 0b78731

Browse files
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
1 parent 869f0ad commit 0b78731

6 files changed

Lines changed: 139 additions & 14 deletions

File tree

‎server/src/com/cloud/network/element/VirtualRouterElement.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
157157

158158
@Inject
159159
NetworkTopologyContext networkTopologyContext;
160+
160161
@Inject
161162
private RouterDeploymentDefinitionBuilder routerDeploymentDefinitionBuilder;
162163

@@ -959,6 +960,9 @@ public boolean addDhcpEntry(final Network network, final NicProfile nic, final V
959960
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
960961
}
961962

963+
DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
964+
NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
965+
962966
return _routerMgr.applyDhcpEntry(network, nic, uservm, dest, routers);
963967
}
964968
return false;

‎server/src/com/cloud/network/rules/DhcpEntryRules.java‎

Lines changed: 84 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,116 @@
1919

2020
import org.apache.cloudstack.network.topology.NetworkTopologyVisitor;
2121

22+
import com.cloud.agent.api.routing.DhcpEntryCommand;
23+
import com.cloud.agent.api.routing.NetworkElementCommand;
24+
import com.cloud.agent.manager.Commands;
25+
import com.cloud.dc.DataCenterVO;
2226
import com.cloud.deploy.DeployDestination;
2327
import com.cloud.exception.ResourceUnavailableException;
2428
import com.cloud.network.Network;
29+
import com.cloud.network.Network.Provider;
30+
import com.cloud.network.Network.Service;
2531
import com.cloud.network.router.VirtualRouter;
32+
import com.cloud.offering.NetworkOffering;
33+
import com.cloud.uservm.UserVm;
34+
import com.cloud.utils.net.NetUtils;
35+
import com.cloud.vm.Nic;
2636
import com.cloud.vm.NicProfile;
37+
import com.cloud.vm.NicVO;
38+
import com.cloud.vm.UserVmVO;
2739
import com.cloud.vm.VirtualMachineProfile;
2840

2941
public class DhcpEntryRules extends RuleApplier {
3042

31-
private final NicProfile nic;
32-
private final VirtualMachineProfile profile;
33-
private final DeployDestination destination;
43+
private final NicProfile _nic;
44+
private final VirtualMachineProfile _profile;
45+
private final DeployDestination _destination;
46+
47+
private NicVO _nicVo;
48+
private UserVmVO _userVM;
3449

3550
public DhcpEntryRules(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination destination) {
3651
super(network);
3752

38-
this.nic = nic;
39-
this.profile = profile;
40-
this.destination = destination;
53+
_nic = nic;
54+
_profile = profile;
55+
_destination = destination;
4156
}
4257

4358
@Override
4459
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
45-
this._router = router;
60+
_router = router;
61+
62+
_userVM = _userVmDao.findById(_profile.getId());
63+
_userVmDao.loadDetails(_userVM);
64+
_nicVo = _nicDao.findById(_nic.getId());
4665

4766
return visitor.visit(this);
4867
}
4968

5069
public NicProfile getNic() {
51-
return nic;
70+
return _nic;
71+
}
72+
73+
public NicVO getNicVo() {
74+
return _nicVo;
5275
}
5376

54-
public VirtualMachineProfile getProfile() {
55-
return profile;
77+
public UserVmVO getUserVM() {
78+
return _userVM;
5679
}
5780

5881
public DeployDestination getDestination() {
59-
return destination;
82+
return _destination;
83+
}
84+
85+
public void createDhcpEntryCommand(final VirtualRouter router, final UserVm vm, final NicVO nic, final Commands cmds) {
86+
final DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), vm.getHostName(), nic.getIp6Address(),
87+
_networkModel.getExecuteInSeqNtwkElmtCmd());
88+
final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
89+
final Nic defaultNic = findGatewayIp(vm.getId());
90+
String gatewayIp = defaultNic.getGateway();
91+
if (gatewayIp != null && !gatewayIp.equals(nic.getGateway())) {
92+
gatewayIp = "0.0.0.0";
93+
}
94+
dhcpCommand.setDefaultRouter(gatewayIp);
95+
dhcpCommand.setIp6Gateway(nic.getIp6Gateway());
96+
String ipaddress = null;
97+
final NicVO domrDefaultNic = findDefaultDnsIp(vm.getId());
98+
if (domrDefaultNic != null) {
99+
ipaddress = domrDefaultNic.getIp4Address();
100+
}
101+
dhcpCommand.setDefaultDns(ipaddress);
102+
dhcpCommand.setDuid(NetUtils.getDuidLL(nic.getMacAddress()));
103+
dhcpCommand.setDefault(nic.isDefaultNic());
104+
105+
dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
106+
dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
107+
dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(nic.getNetworkId(), router.getId()));
108+
dhcpCommand.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
109+
110+
cmds.addCommand("dhcp", dhcpCommand);
60111
}
112+
113+
private NicVO findGatewayIp(final long userVmId) {
114+
final NicVO defaultNic = _nicDao.findDefaultNicForVM(userVmId);
115+
return defaultNic;
116+
}
117+
118+
private NicVO findDefaultDnsIp(final long userVmId) {
119+
final NicVO defaultNic = _nicDao.findDefaultNicForVM(userVmId);
120+
121+
// check if DNS provider is the domR
122+
if (!_networkModel.isProviderSupportServiceInNetwork(defaultNic.getNetworkId(), Service.Dns, Provider.VirtualRouter)) {
123+
return null;
124+
}
125+
126+
final NetworkOffering offering = _networkOfferingDao.findById(_networkDao.findById(defaultNic.getNetworkId()).getNetworkOfferingId());
127+
if (offering.getRedundantRouter()) {
128+
return findGatewayIp(userVmId);
129+
}
130+
131+
return null;
132+
}
133+
61134
}

‎server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.cloud.deploy.DeployDestination;
2828
import com.cloud.exception.ResourceUnavailableException;
2929
import com.cloud.network.Network;
30+
import com.cloud.network.rules.DhcpEntryRules;
3031
import com.cloud.network.rules.RuleApplier;
3132
import com.cloud.network.rules.RuleApplierWrapper;
3233
import com.cloud.network.rules.UserdataPwdRules;
@@ -58,4 +59,20 @@ public boolean applyUserData(final Network network, final NicProfile nic, final
5859

5960
return applyRules(network, routers, typeString, isPodLevelException, podId, failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(pwdRules));
6061
}
62+
63+
@Override
64+
public boolean applyDhcpEntry(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination dest,
65+
final List<DomainRouterVO> routers) throws ResourceUnavailableException {
66+
67+
s_logger.debug("APPLYING DHCP ENTRY RULES");
68+
69+
final String typeString = "dhcp entry";
70+
final Long podId = null;
71+
final boolean isPodLevelException = false;
72+
final boolean failWhenDisconnect = false;
73+
74+
DhcpEntryRules dhcpRules = _virtualNetworkApplianceFactory.createDhcpEntryRules(network, nic, profile, dest);
75+
76+
return applyRules(network, routers, typeString, isPodLevelException, podId, failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(dhcpRules));
77+
}
6178
}

‎server/src/org/apache/cloudstack/network/topology/BasicNetworkTopology.java‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,28 @@ public boolean configDhcpForSubnet(final Network network, final NicProfile nic,
109109
@Override
110110
public boolean applyDhcpEntry(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination dest,
111111
final List<DomainRouterVO> routers) throws ResourceUnavailableException {
112+
<<<<<<< HEAD
112113
return false;
114+
=======
115+
116+
s_logger.debug("APPLYING DHCP ENTRY RULES");
117+
118+
final String typeString = "dhcp entry";
119+
final Long podId = dest.getPod().getId();
120+
boolean isPodLevelException = false;
121+
122+
//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
123+
if (podId != null && profile.getVirtualMachine().getType() == VirtualMachine.Type.User && network.getTrafficType() == TrafficType.Guest &&
124+
network.getGuestType() == Network.GuestType.Shared) {
125+
isPodLevelException = true;
126+
}
127+
128+
final boolean failWhenDisconnect = false;
129+
130+
DhcpEntryRules dhcpRules = _virtualNetworkApplianceFactory.createDhcpEntryRules(network, nic, profile, dest);
131+
132+
return applyRules(network, routers, typeString, isPodLevelException, podId, failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(dhcpRules));
133+
>>>>>>> ee0389b... fixing import in virtual router element and checkstyle in dhcp entry related changes
113134
}
114135

115136
@Override

‎server/src/org/apache/cloudstack/network/topology/BasicNetworkVisitor.java‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,19 @@ public boolean visit(final UserdataPwdRules userdata) throws ResourceUnavailable
168168

169169
@Override
170170
public boolean visit(final DhcpEntryRules dhcp) throws ResourceUnavailableException {
171-
return false;
171+
final VirtualRouter router = dhcp.getRouter();
172+
173+
final Commands commands = new Commands(Command.OnError.Stop);
174+
final NicVO nicVo = dhcp.getNicVo();
175+
final UserVmVO userVM = dhcp.getUserVM();
176+
final DeployDestination destination = dhcp.getDestination();
177+
178+
if (router.getPodIdToDeployIn().longValue() == destination.getPod().getId()) {
179+
dhcp.createDhcpEntryCommand(router, userVM, nicVo, commands);
180+
181+
return _applianceManager.sendCommandsToRouter(router, commands);
182+
}
183+
return true;
172184
}
173185

174186
@Override

‎server/src/org/apache/cloudstack/network/topology/NetworkTopologyContext.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
import java.util.Hashtable;
2121

22-
import javax.inject.Inject;
23-
2422
import org.springframework.beans.factory.annotation.Autowired;
2523
import org.springframework.beans.factory.annotation.Qualifier;
2624

0 commit comments

Comments
 (0)