Skip to content

Commit b7f845a

Browse files
authored
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 <abhishek.mrt22@gmail.com>
1 parent a4d3780 commit b7f845a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,8 @@ private Pair<DiskProfile, StoragePool> importDisk(UnmanagedInstanceTO.Disk disk,
698698
return new Pair<DiskProfile, StoragePool>(profile, storagePool);
699699
}
700700

701-
private NicProfile importNic(UnmanagedInstanceTO.Nic nic, VirtualMachine vm, Network network, Network.IpAddresses ipAddresses, boolean isDefaultNic, boolean forced) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
702-
Pair<NicProfile, Integer> result = networkOrchestrationService.importNic(nic.getMacAddress(), 0, network, isDefaultNic, vm, ipAddresses, forced);
701+
private NicProfile importNic(UnmanagedInstanceTO.Nic nic, VirtualMachine vm, Network network, Network.IpAddresses ipAddresses, int deviceId, boolean isDefaultNic, boolean forced) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
702+
Pair<NicProfile, Integer> result = networkOrchestrationService.importNic(nic.getMacAddress(), deviceId, network, isDefaultNic, vm, ipAddresses, forced);
703703
if (result == null) {
704704
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("NIC ID: %s import failed", nic.getNicId()));
705705
}
@@ -1016,12 +1016,12 @@ private UserVm importVirtualMachineInternal(final UnmanagedInstanceTO unmanagedI
10161016
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to import volumes while importing vm: %s. %s", instanceName, StringUtils.defaultString(e.getMessage())));
10171017
}
10181018
try {
1019-
boolean firstNic = true;
1019+
int nicIndex = 0;
10201020
for (UnmanagedInstanceTO.Nic nic : unmanagedInstance.getNics()) {
10211021
Network network = networkDao.findById(allNicNetworkMap.get(nic.getNicId()));
10221022
Network.IpAddresses ipAddresses = nicIpAddressMap.get(nic.getNicId());
1023-
importNic(nic, userVm, network, ipAddresses, firstNic, forced);
1024-
firstNic = false;
1023+
importNic(nic, userVm, network, ipAddresses, nicIndex, nicIndex==0, forced);
1024+
nicIndex++;
10251025
}
10261026
} catch (Exception e) {
10271027
LOGGER.error(String.format("Failed to import NICs while importing vm: %s", instanceName), e);

0 commit comments

Comments
 (0)