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/09/09 13:16:40 UTC

[GitHub] [cloudstack] weizhouapache commented on a change in pull request #5425: api: Update DNS on changing VM name

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



##########
File path: server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
##########
@@ -2911,9 +2918,40 @@ public UserVm updateVirtualMachine(long id, String displayName, String group, Bo
             }
         }
 
+        if (!StringUtils.isEmpty(hostName)) {
+            vm.setHostName(hostName);
+            try {
+                updateDns(vm);
+            } catch (CloudRuntimeException e) {
+                throw new CloudRuntimeException(String.format("Failed to update hostname of VM %s to %s", vm.getInstanceName(), vm.getHostName()));
+            }
+        }
+
         return _vmDao.findById(id);
     }
 
+    private void updateDns(UserVmVO vm) {
+        List<NicVO> nicVOs = _nicDao.listByVmId(vm.getId());
+        for (NicVO nic : nicVOs) {
+            List<DomainRouterVO> routers = _routerDao.findByNetwork(nic.getNetworkId());
+            for (DomainRouterVO router : routers) {
+                Commands commands = new Commands(Command.OnError.Stop);
+                commandSetupHelper.createDhcpEntryCommand(router, vm, nic, false, commands);
+                try {
+                    _agentMgr.send(router.getHostId(), commands);

Review comment:
       @Pearl1594 can we use networkHelper.sendCommandsToRouter instead ?
   
   https://github.com/apache/cloudstack/blob/f6073052aa3d592d6d737990a95c44e702908d59/server/src/main/java/com/cloud/network/router/NetworkHelperImpl.java#L180-L208




-- 
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