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



##########
File path: server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
##########
@@ -2911,9 +2924,42 @@ public UserVm updateVirtualMachine(long id, String 
displayName, String group, Bo
             }
         }
 
+        if (!StringUtils.isEmpty(hostName)) {
+            vm.setHostName(hostName);

Review comment:
       @Pearl1594 
   line 2928 to line 2933 can be moved into updateDns

##########
File path: server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
##########
@@ -2911,9 +2924,42 @@ 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 {
+                    if (!nwHelper.sendCommandsToRouter(router, commands)) {

Review comment:
       @Pearl1594 
   what if router is not Running ?

##########
File path: server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
##########
@@ -2911,9 +2924,42 @@ 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 {
+                    if (!nwHelper.sendCommandsToRouter(router, commands)) {
+                        throw new AgentUnavailableException("Unable to send 
commands to virtual router ", router.getHostId());

Review comment:
       CloudRuntimeException or AgentUnavailableException ?




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to