fix dhcp subnet rules. we can create VMs again.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/5f51a06e Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/5f51a06e Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/5f51a06e Branch: refs/heads/master Commit: 5f51a06e3cbb15c26defad559ca96a360378d72f Parents: 02c7525 Author: wrodrigues <wrodrig...@schubergphilis.com> Authored: Sat Aug 23 14:10:46 2014 +0200 Committer: wilderrodrigues <wrodrig...@schubergphilis.com> Committed: Tue Oct 14 15:08:10 2014 +0200 ---------------------------------------------------------------------- .../cloud/network/rules/DhcpSubNetRules.java | 39 +++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5f51a06e/server/src/com/cloud/network/rules/DhcpSubNetRules.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/rules/DhcpSubNetRules.java b/server/src/com/cloud/network/rules/DhcpSubNetRules.java index 37b3857..ec99f44 100644 --- a/server/src/com/cloud/network/rules/DhcpSubNetRules.java +++ b/server/src/com/cloud/network/rules/DhcpSubNetRules.java @@ -73,17 +73,20 @@ public class DhcpSubNetRules extends RuleApplier { final UserVmVO vm = _userVmDao.findById(_profile.getId()); _userVmDao.loadDetails(vm); - //check if this is not the primary subnet. - final NicVO domr_guest_nic = - _nicDao.findByInstanceIdAndIpAddressAndVmtype(router.getId(), _nicDao.getIpAddress(_nic.getNetworkId(), router.getId()), VirtualMachine.Type.DomainRouter); - //check if the router ip address and the vm ip address belong to same subnet. - //if they do not belong to same netwoek check for the alias ips. if not create one. - // This should happen only in case of Basic and Advanced SG enabled networks. + // check if this is not the primary subnet. + final NicVO domr_guest_nic = _nicDao.findByInstanceIdAndIpAddressAndVmtype(router.getId(), _nicDao.getIpAddress(_nic.getNetworkId(), router.getId()), + VirtualMachine.Type.DomainRouter); + // check if the router ip address and the vm ip address belong to same + // subnet. + // if they do not belong to same netwoek check for the alias ips. if not + // create one. + // This should happen only in case of Basic and Advanced SG enabled + // networks. if (!NetUtils.sameSubnet(domr_guest_nic.getIp4Address(), _nic.getIp4Address(), _nic.getNetmask())) { final List<NicIpAliasVO> aliasIps = _nicIpAliasDao.listByNetworkIdAndState(domr_guest_nic.getNetworkId(), NicIpAlias.state.active); boolean ipInVmsubnet = false; for (final NicIpAliasVO alias : aliasIps) { - //check if any of the alias ips belongs to the Vm's subnet. + // check if any of the alias ips belongs to the Vm's subnet. if (NetUtils.sameSubnet(alias.getIp4Address(), _nic.getIp4Address(), _nic.getNetmask())) { ipInVmsubnet = true; break; @@ -94,7 +97,7 @@ public class DhcpSubNetRules extends RuleApplier { final DataCenter dc = _dcDao.findById(router.getDataCenterId()); if (ipInVmsubnet == false) { try { - if (_network.getTrafficType() == TrafficType.Guest && _network.getGuestType() == GuestType.Shared) { + if ((_network.getTrafficType() == TrafficType.Guest) && (_network.getGuestType() == GuestType.Shared)) { _podDao.findById(vm.getPodIdToDeployIn()); final Account caller = CallContext.current().getCallingAccount(); final List<VlanVO> vlanList = _vlanDao.listVlansByNetworkIdAndGateway(_network.getId(), _nic.getGateway()); @@ -103,13 +106,11 @@ public class DhcpSubNetRules extends RuleApplier { vlanDbIdList.add(vlan.getId()); } if (dc.getNetworkType() == NetworkType.Basic) { - routerPublicIP = - _ipAddrMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(), vm.getPodIdToDeployIn(), caller, Vlan.VlanType.DirectAttached, - vlanDbIdList, _nic.getNetworkId(), null, false); + routerPublicIP = _ipAddrMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(), vm.getPodIdToDeployIn(), caller, Vlan.VlanType.DirectAttached, + vlanDbIdList, _nic.getNetworkId(), null, false); } else { - routerPublicIP = - _ipAddrMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(), null, caller, Vlan.VlanType.DirectAttached, vlanDbIdList, - _nic.getNetworkId(), null, false); + routerPublicIP = _ipAddrMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(), null, caller, Vlan.VlanType.DirectAttached, vlanDbIdList, + _nic.getNetworkId(), null, false); } _routerAliasIp = routerPublicIP.getAddress().addr(); @@ -119,7 +120,7 @@ public class DhcpSubNetRules extends RuleApplier { s_logger.info("unable to configure dhcp for this VM."); return false; } - //this means we did not create an IP alias on the router. + // this means we did not create an IP alias on the router. _nicAlias = new NicIpAliasVO(domr_guest_nic.getId(), _routerAliasIp, router.getId(), CallContext.current().getCallingAccountId(), _network.getDomainId(), _nic.getNetworkId(), _nic.getGateway(), _nic.getNetmask()); _nicAlias.setAliasCount((routerPublicIP.getIpMacAddress())); @@ -127,11 +128,6 @@ public class DhcpSubNetRules extends RuleApplier { final boolean result = visitor.visit(this); - // Clean the routerAliasIp just to make sure it will keep an older value. - // The rules classes area created every time a command is issued, but I want to make 100% sure - // that the routerAliasIp won't float around. - _routerAliasIp = null; - if (result == false) { final NicIpAliasVO ipAliasVO = _nicIpAliasDao.findByInstanceIdAndNetworkId(_network.getId(), router.getId()); final PublicIp routerPublicIPFinal = routerPublicIP; @@ -147,8 +143,7 @@ public class DhcpSubNetRules extends RuleApplier { } return true; } - - return visitor.visit(this); + return true; } public NicIpAliasVO getNicAlias() {