You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ro...@apache.org on 2022/12/08 16:59:41 UTC

[cloudstack] branch 4.17 updated: server: fix nic device id fro imported vm (#6953)

This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch 4.17
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.17 by this push:
     new b7f845ab134 server: fix nic device id fro imported vm (#6953)
b7f845ab134 is described below

commit b7f845ab1346bf79e7cbfcb3561232cccf49b3ef
Author: Abhishek Kumar <ab...@gmail.com>
AuthorDate: Fri Dec 9 00:59:32 2022 +0800

    server: fix nic device id fro imported vm (#6953)
    
    Fixes #6951
    
    Adds deviceid for NICs of an imported VM. Device Id will be set 0..n in the order which they are returned by hypervisor.
    
    Signed-off-by: Abhishek Kumar <ab...@gmail.com>
---
 .../java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java b/server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java
index 38f57d1f0bb..72ccf621e3a 100644
--- a/server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java
+++ b/server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java
@@ -698,8 +698,8 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
         return new Pair<DiskProfile, StoragePool>(profile, storagePool);
     }
 
-    private NicProfile importNic(UnmanagedInstanceTO.Nic nic, VirtualMachine vm, Network network, Network.IpAddresses ipAddresses, boolean isDefaultNic, boolean forced) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
-        Pair<NicProfile, Integer> result = networkOrchestrationService.importNic(nic.getMacAddress(), 0, network, isDefaultNic, vm, ipAddresses, forced);
+    private NicProfile importNic(UnmanagedInstanceTO.Nic nic, VirtualMachine vm, Network network, Network.IpAddresses ipAddresses, int deviceId, boolean isDefaultNic, boolean forced) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
+        Pair<NicProfile, Integer> result = networkOrchestrationService.importNic(nic.getMacAddress(), deviceId, network, isDefaultNic, vm, ipAddresses, forced);
         if (result == null) {
             throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("NIC ID: %s import failed", nic.getNicId()));
         }
@@ -1016,12 +1016,12 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
             throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to import volumes while importing vm: %s. %s", instanceName, StringUtils.defaultString(e.getMessage())));
         }
         try {
-            boolean firstNic = true;
+            int nicIndex = 0;
             for (UnmanagedInstanceTO.Nic nic : unmanagedInstance.getNics()) {
                 Network network = networkDao.findById(allNicNetworkMap.get(nic.getNicId()));
                 Network.IpAddresses ipAddresses = nicIpAddressMap.get(nic.getNicId());
-                importNic(nic, userVm, network, ipAddresses, firstNic, forced);
-                firstNic = false;
+                importNic(nic, userVm, network, ipAddresses, nicIndex, nicIndex==0, forced);
+                nicIndex++;
             }
         } catch (Exception e) {
             LOGGER.error(String.format("Failed to import NICs while importing vm: %s", instanceName), e);