You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2021/12/09 10:30:39 UTC

[GitHub] [cloudstack] weizhouapache commented on a change in pull request #5757: network: update ip in lb/pf/dnat tables when update vm nic ip

weizhouapache commented on a change in pull request #5757:
URL: https://github.com/apache/cloudstack/pull/5757#discussion_r765655432



##########
File path: server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
##########
@@ -1748,35 +1749,33 @@ public UserVm updateNicIpForVirtualMachine(UpdateVmNicIpCmd cmd) {
             }
 
             if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.StaticNat)) {
-                IPAddressVO oldIP = _ipAddressDao.findByAssociatedVmId(vm.getId());
-                if (oldIP != null) {
-                    oldIP.setVmIp(ipaddr);
-                    _ipAddressDao.persist(oldIP);
+                List<IPAddressVO> publicIps = _ipAddressDao.listByAssociatedVmId(vm.getId());
+                for (IPAddressVO publicIp : publicIps) {
+                    if (nicVO.getIPv4Address().equals(publicIp.getVmIp() ) && publicIp.getAssociatedWithNetworkId() == network.getId()) {
+                        publicIp.setVmIp(ipaddr);
+                        _ipAddressDao.persist(publicIp);
+                    }
                 }
             }
-            // implementing the network elements and resources as a part of vm nic ip update if network has services and it is in Implemented state
-            if (!_networkModel.listNetworkOfferingServices(offering.getId()).isEmpty() && network.getState() == Network.State.Implemented) {
-                User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
-                ReservationContext context = new ReservationContextImpl(null, null, callerUser, caller);
-                DeployDestination dest = new DeployDestination(_dcDao.findById(network.getDataCenterId()), null, null, null);
-
-                s_logger.debug("Implementing the network " + network + " elements and resources as a part of vm nic ip update");
-                try {
-                    // implement the network elements and rules again
-                    _networkMgr.implementNetworkElementsAndResources(dest, context, network, offering);
-                } catch (Exception ex) {
-                    s_logger.warn("Failed to implement network " + network + " elements and resources as a part of vm nic ip update due to ", ex);
-                    CloudRuntimeException e = new CloudRuntimeException("Failed to implement network (with specified id) elements and resources as a part of vm nic ip update");
-                    e.addProxyObject(network.getUuid(), "networkId");
-                    // restore to old ip address
-                    if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.StaticNat)) {
-                        IPAddressVO oldIP = _ipAddressDao.findByAssociatedVmId(vm.getId());
-                        if (oldIP != null) {
-                            oldIP.setVmIp(nicVO.getIPv4Address());
-                            _ipAddressDao.persist(oldIP);
-                        }
+            if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Lb)) {
+                List<LoadBalancerVMMapVO> loadBalancerVMMaps = _loadBalancerVMMapDao.listByInstanceId(vm.getId());
+                for (LoadBalancerVMMapVO map : loadBalancerVMMaps) {
+                    long lbId = map.getLoadBalancerId();
+                    FirewallRuleVO rule = _rulesDao.findById(lbId);
+                    if (nicVO.getIPv4Address().equals(map.getInstanceIp()) && network.getId() == rule.getNetworkId()) {
+                        map.setInstanceIp(ipaddr);
+                        _loadBalancerVMMapDao.persist(map);
+                    }
+                }
+            }
+            if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.PortForwarding)) {
+                List<PortForwardingRuleVO> firewallRules = _portForwardingDao.listByVm(vm.getId());
+                for (PortForwardingRuleVO firewallRule : firewallRules) {
+                    FirewallRuleVO rule = _rulesDao.findById(firewallRule.getId());
+                    if (nicVO.getIPv4Address().equals(firewallRule.getDestinationIpAddress().toString()) && network.getId() == rule.getNetworkId()) {
+                        firewallRule.setDestinationIpAddress(new Ip(ipaddr));
+                        _portForwardingDao.persist(firewallRule);

Review comment:
       Updated. thanks @DaanHoogland . 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org