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
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4ae9e67a
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4ae9e67a
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4ae9e67a
Branch: refs/heads/vpc-refactor
Commit: 4ae9e67a5b13b90bae35c1e1c77d35cf2aac9592
Parents: e6b1a3c
Author: Wilder Rodrigues <[email protected]>
Authored: Thu Jul 17 07:57:29 2014 +0200
Committer: Wilder Rodrigues <[email protected]>
Committed: Fri Oct 3 06:21:26 2014 +0200
----------------------------------------------------------------------
.../network/element/VirtualRouterElement.java | 4 +
.../com/cloud/network/rules/DhcpEntryRules.java | 95 +++++++++++++++++---
.../topology/AdvancedNetworkTopology.java | 17 ++++
.../network/topology/BasicNetworkTopology.java | 21 +++++
.../network/topology/BasicNetworkVisitor.java | 14 ++-
.../topology/NetworkTopologyContext.java | 2 -
6 files changed, 139 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4ae9e67a/server/src/com/cloud/network/element/VirtualRouterElement.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java
b/server/src/com/cloud/network/element/VirtualRouterElement.java
index 90e9a63..0ea6c18 100755
--- a/server/src/com/cloud/network/element/VirtualRouterElement.java
+++ b/server/src/com/cloud/network/element/VirtualRouterElement.java
@@ -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;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4ae9e67a/server/src/com/cloud/network/rules/DhcpEntryRules.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/rules/DhcpEntryRules.java
b/server/src/com/cloud/network/rules/DhcpEntryRules.java
index 7e0eae0..2bfa4e6 100644
--- a/server/src/com/cloud/network/rules/DhcpEntryRules.java
+++ b/server/src/com/cloud/network/rules/DhcpEntryRules.java
@@ -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 NicVO getNicVo() {
+ return _nicVo;
}
- public VirtualMachineProfile getProfile() {
- return profile;
+ 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;
+ }
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4ae9e67a/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java
----------------------------------------------------------------------
diff --git
a/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java
b/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java
index 81b6565..794ed4c 100644
---
a/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java
+++
b/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java
@@ -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));
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4ae9e67a/server/src/org/apache/cloudstack/network/topology/BasicNetworkTopology.java
----------------------------------------------------------------------
diff --git
a/server/src/org/apache/cloudstack/network/topology/BasicNetworkTopology.java
b/server/src/org/apache/cloudstack/network/topology/BasicNetworkTopology.java
index d19db06..63b9376 100644
---
a/server/src/org/apache/cloudstack/network/topology/BasicNetworkTopology.java
+++
b/server/src/org/apache/cloudstack/network/topology/BasicNetworkTopology.java
@@ -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
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4ae9e67a/server/src/org/apache/cloudstack/network/topology/BasicNetworkVisitor.java
----------------------------------------------------------------------
diff --git
a/server/src/org/apache/cloudstack/network/topology/BasicNetworkVisitor.java
b/server/src/org/apache/cloudstack/network/topology/BasicNetworkVisitor.java
index 3b1f071..430ce86 100644
--- a/server/src/org/apache/cloudstack/network/topology/BasicNetworkVisitor.java
+++ b/server/src/org/apache/cloudstack/network/topology/BasicNetworkVisitor.java
@@ -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
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4ae9e67a/server/src/org/apache/cloudstack/network/topology/NetworkTopologyContext.java
----------------------------------------------------------------------
diff --git
a/server/src/org/apache/cloudstack/network/topology/NetworkTopologyContext.java
b/server/src/org/apache/cloudstack/network/topology/NetworkTopologyContext.java
index 00acec8..8ddc836 100644
---
a/server/src/org/apache/cloudstack/network/topology/NetworkTopologyContext.java
+++
b/server/src/org/apache/cloudstack/network/topology/NetworkTopologyContext.java
@@ -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;