vishesh92 commented on code in PR #10641:
URL: https://github.com/apache/cloudstack/pull/10641#discussion_r2401049631


##########
plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java:
##########
@@ -5837,11 +5837,19 @@ protected Answer execute(GetVmIpAddressCommand cmd) {
                 if (toolsStatus == 
VirtualMachineToolsStatus.TOOLS_NOT_INSTALLED) {
                     details += "Vmware tools not installed.";
                 } else {
-                    ip = guestInfo.getIpAddress();
-                    if (ip != null) {
-                        result = true;
+                    var normalizedMac = cmd.getMacAddress().replaceAll("-", 
":");
+                    for(var guestInfoNic : guestInfo.getNet()) {
+                        var normalizedNicMac = 
guestInfoNic.getMacAddress().replaceAll("-", ":");
+                        if (!result && 
normalizedNicMac.equalsIgnoreCase(normalizedMac)) {
+                            result = true;
+                            details = null;
+                            for (var ipAddr : guestInfoNic.getIpAddress()) {
+                                if (NetUtils.isValidIp4(ipAddr) && 
(cmd.getVmNetworkCidr() == null || NetUtils.isIpWithInCidrRange(ipAddr, 
cmd.getVmNetworkCidr()))) {
+                                    details = ipAddr;
+                                }
+                            }

Review Comment:
   once the result is set to true, we can break out of the for loop.



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