You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by "rg9975 (via GitHub)" <gi...@apache.org> on 2025/02/12 15:11:01 UTC

[PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

rg9975 opened a new pull request, #10376:
URL: https://github.com/apache/cloudstack/pull/10376

   ### Description
   
   Adds use of virsh domifaddr command as first choice for finding the external DHCP address of a newly provisioned VM.  This command returns address information about all the interfaces when the Qemu OS guest agent is installed within the VM.  When this command fails to find the IP, falls back to original behavior of looking at OS disk lease files to find the data.
   
   <!--- ******************************************************************************* -->
   <!--- NOTE: AUTOMATION USES THE DESCRIPTIONS TO SET LABELS AND PRODUCE DOCUMENTATION. -->
   <!--- PLEASE PUT AN 'X' in only **ONE** box -->
   <!--- ******************************************************************************* -->
   
   ### Types of changes
   
   - [ ] Breaking change (fix or feature that would cause existing functionality to change)
   - [ ] New feature (non-breaking change which adds functionality)
   - [ ] Bug fix (non-breaking change which fixes an issue)
   - [X] Enhancement (improves an existing feature and functionality)
   - [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
   - [ ] build/CI
   - [ ] test (unit or integration test code)
   
   ### Feature/Enhancement Scale or Bug Severity
   
   #### Feature/Enhancement Scale
   
   - [ ] Major
   - [X] Minor
   
   #### Bug Severity
   
   - [ ] BLOCKER
   - [ ] Critical
   - [X] Major
   - [ ] Minor
   - [ ] Trivial
   
   ### Screenshots (if appropriate):
   
   ### How Has This Been Tested?
   Tested locally with VM running Qemu guest agent.
   
   #### How did you try to break this feature and the system with this change?
   Tested with VM having guest agent and not having agent for expected behaviors.
   
   <!-- Please read the [CONTRIBUTING](https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md) document -->
   


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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "rohityadavcloud (via GitHub)" <gi...@apache.org>.
rohityadavcloud merged PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376


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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#issuecomment-2655813835

   Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 12436


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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "weizhouapache (via GitHub)" <gi...@apache.org>.
weizhouapache commented on PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#issuecomment-2685382121

   @blueorangutan package


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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#issuecomment-2685694873

   Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 12582


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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "weizhouapache (via GitHub)" <gi...@apache.org>.
weizhouapache commented on PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#issuecomment-2689819122

   > Sorry missed your comment @weizhouapache if there are further changes you could review if this needs to be reverted or you want to raise a new PR?
   
   @rohityadavcloud 
   no worries, I will address it in another PR #10431 
   
   btw, actually I missed a word in my previous comment. :man_facepalming: 
   
   This does **NOT** work in my testing on ubuntu 24.
   


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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "rohityadavcloud (via GitHub)" <gi...@apache.org>.
rohityadavcloud commented on PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#issuecomment-2689705742

   Sorry missed your comment @weizhouapache if there are further changes you could review if this needs to be reverted or you want to raise a new PR? 


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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "weizhouapache (via GitHub)" <gi...@apache.org>.
weizhouapache commented on PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#issuecomment-2690899814

   
   > What exactly is the problem you are seeing? you mean Ubuntu on the hypervisor or on the guest OS?
   
   @rg9975 
   never mind
   I found I was testing the first commit of the PR.
   The issue has been fixed by the 2nd commit in this PR 2 days ago.


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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on code in PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#discussion_r1971827902


##########
plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmIpAddressCommandWrapperTest.java:
##########
@@ -0,0 +1,301 @@
+package com.cloud.hypervisor.kvm.resource.wrapper;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.MockedStatic;
+import org.mockito.MockitoAnnotations;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.GetVmIpAddressCommand;
+import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
+import com.cloud.utils.Pair;
+import com.cloud.utils.script.Script;
+
+public class LibvirtGetVmIpAddressCommandWrapperTest {
+
+    private static String VIRSH_DOMIF_OUTPUT = " Name       MAC address          Protocol     Address\n" + //
+            "-------------------------------------------------------------------------------\n" + //
+            " lo         00:00:00:00:00:70    ipv4         127.0.0.1/8\n" + //
+            " eth0       02:0c:02:f9:00:80    ipv4         192.168.0.10/24\n" + //
+            " net1 b2:41:19:69:a4:90    N/A          N/A\n" + //
+            " net2 52:a2:36:cf:d1:50    ipv4         10.244.6.93/32\n" + //
+            " net3 a6:1d:d3:52:d3:40    N/A          N/A\n" + //
+            " net4 2e:9b:60:dc:49:30    N/A          N/A\n" + //
+            " lxc5b7327203b6f 92:b2:77:0b:a9:20    N/A          N/A\n";
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.openMocks(this);
+    }
+
+    @Test
+    public void testExecuteWithValidVmName() {
+        LibvirtComputingResource libvirtComputingResource = mock(LibvirtComputingResource.class);
+        GetVmIpAddressCommand getVmIpAddressCommand = mock(GetVmIpAddressCommand.class);
+        LibvirtGetVmIpAddressCommandWrapper commandWrapper = new LibvirtGetVmIpAddressCommandWrapper();
+        MockedStatic<Script> scriptMock = mockStatic(Script.class);
+
+        when(getVmIpAddressCommand.getVmName()).thenReturn("validVmName");
+        when(getVmIpAddressCommand.getVmNetworkCidr()).thenReturn("192.168.0.0/24");
+        when(getVmIpAddressCommand.isWindows()).thenReturn(false);
+        when(Script.executePipedCommands(anyList(), anyLong())).thenReturn(new Pair<>(0, VIRSH_DOMIF_OUTPUT));
+
+        Answer answer = commandWrapper.execute(getVmIpAddressCommand, libvirtComputingResource);
+
+        try {
+            assertTrue(answer.getResult());
+            assertEquals("192.168.0.10", answer.getDetails());
+        } finally {
+            scriptMock.close();
+        }
+    }
+
+    @Test
+    public void testExecuteWithInvalidVmName() {
+        LibvirtComputingResource libvirtComputingResource = mock(LibvirtComputingResource.class);
+        GetVmIpAddressCommand getVmIpAddressCommand = mock(GetVmIpAddressCommand.class);
+        LibvirtGetVmIpAddressCommandWrapper commandWrapper = new LibvirtGetVmIpAddressCommandWrapper();
+        MockedStatic<Script> scriptMock = mockStatic(Script.class);
+
+        when(getVmIpAddressCommand.getVmName()).thenReturn("invalidVmName!");
+        when(getVmIpAddressCommand.getVmNetworkCidr()).thenReturn("192.168.0.0/24");
+        when(getVmIpAddressCommand.isWindows()).thenReturn(false);
+        when(Script.executePipedCommands(anyList(), anyLong())).thenReturn(new Pair<>(0, VIRSH_DOMIF_OUTPUT));
+
+        Answer answer = commandWrapper.execute(getVmIpAddressCommand, libvirtComputingResource);
+
+        try {
+            assertFalse(answer.getResult());
+            assertNull(answer.getDetails());
+        } finally {
+            scriptMock.close();
+        }
+
+    }
+
+    @Test
+    public void testExecuteWithWindowsVm() {
+        LibvirtComputingResource libvirtComputingResource = mock(LibvirtComputingResource.class);
+        GetVmIpAddressCommand getVmIpAddressCommand = mock(GetVmIpAddressCommand.class);
+        LibvirtGetVmIpAddressCommandWrapper commandWrapper = new LibvirtGetVmIpAddressCommandWrapper();
+        MockedStatic<Script> scriptMock = null;
+
+        try {
+            scriptMock = mockStatic(Script.class);
+
+            when(getVmIpAddressCommand.getVmName()).thenReturn("validVmName");
+            when(getVmIpAddressCommand.getVmNetworkCidr()).thenReturn("192.168.0.0/24");
+            when(getVmIpAddressCommand.isWindows()).thenReturn(true);
+            when(Script.executePipedCommands(anyList(), anyLong())).thenReturn(new Pair<>(0, "192.168.0.10"));
+
+            Answer answer = commandWrapper.execute(getVmIpAddressCommand, libvirtComputingResource);
+
+            assertTrue(answer.getResult());
+            assertEquals("192.168.0.10", answer.getDetails());
+        } finally {
+            if (scriptMock != null)
+                scriptMock.close();
+        }
+    }
+
+    @Test
+    public void testExecuteWithNoIpFound() {
+        LibvirtComputingResource libvirtComputingResource = mock(LibvirtComputingResource.class);
+        GetVmIpAddressCommand getVmIpAddressCommand = mock(GetVmIpAddressCommand.class);
+        LibvirtGetVmIpAddressCommandWrapper commandWrapper = new LibvirtGetVmIpAddressCommandWrapper();
+        MockedStatic<Script> scriptMock = null;
+        try {
+            scriptMock = mockStatic(Script.class);
+
+            when(getVmIpAddressCommand.getVmName()).thenReturn("validVmName");
+            when(getVmIpAddressCommand.getVmNetworkCidr()).thenReturn("192.168.0.0/24");
+            when(getVmIpAddressCommand.isWindows()).thenReturn(false);
+            when(Script.executePipedCommands(anyList(), anyLong())).thenReturn(new Pair<>(0, ""));
+
+            Answer answer = commandWrapper.execute(getVmIpAddressCommand, libvirtComputingResource);
+
+            assertFalse(answer.getResult());
+            assertNull(answer.getDetails());
+        } finally {
+            if (scriptMock != null)
+                scriptMock.close();
+        }
+    }
+
+    @Test
+    public void testExecuteWithValidVmNameAndNoIpFound() {
+        LibvirtComputingResource libvirtComputingResource = mock(LibvirtComputingResource.class);
+        GetVmIpAddressCommand getVmIpAddressCommand = mock(GetVmIpAddressCommand.class);
+        LibvirtGetVmIpAddressCommandWrapper commandWrapper = new LibvirtGetVmIpAddressCommandWrapper();
+        MockedStatic<Script> scriptMock = null;
+        try {
+            scriptMock = mockStatic(Script.class);
+
+            when(getVmIpAddressCommand.getVmName()).thenReturn("validVmName");
+            when(getVmIpAddressCommand.getVmNetworkCidr()).thenReturn("192.168.0.0/24");
+            when(getVmIpAddressCommand.isWindows()).thenReturn(false);
+            when(Script.executePipedCommands(anyList(), anyLong())).thenReturn(new Pair<>(0, ""));
+
+            Answer answer = commandWrapper.execute(getVmIpAddressCommand, libvirtComputingResource);
+
+            assertFalse(answer.getResult());
+            assertNull(answer.getDetails());
+        } finally {
+            if (scriptMock != null)
+                scriptMock.close();
+        }
+    }
+
+    @Test
+    public void testExecuteWithValidVmNameAndIpFromDhcpLeaseFile() {
+        LibvirtComputingResource libvirtComputingResource = mock(LibvirtComputingResource.class);
+        GetVmIpAddressCommand getVmIpAddressCommand = mock(GetVmIpAddressCommand.class);
+        LibvirtGetVmIpAddressCommandWrapper commandWrapper = new LibvirtGetVmIpAddressCommandWrapper();
+        MockedStatic<Script> scriptMock = null;
+        try {
+            scriptMock = mockStatic(Script.class);
+            when(getVmIpAddressCommand.getVmName()).thenReturn("validVmName");
+            when(getVmIpAddressCommand.getVmNetworkCidr()).thenReturn("192.168.0.0/24");
+            when(getVmIpAddressCommand.isWindows()).thenReturn(false);
+            when(Script.executePipedCommands(anyList(), anyLong())).thenReturn(new Pair<>(0, "192.168.0.10"));
+
+            Answer answer = commandWrapper.execute(getVmIpAddressCommand, libvirtComputingResource);
+
+            assertTrue(answer.getResult());
+            assertEquals("192.168.0.10", answer.getDetails());
+        } finally {
+            if (scriptMock != null)
+                scriptMock.close();
+        }
+    }
+
+    @Test
+    public void testExecuteWithValidVmNameAndIpFromWindowsRegistry() {
+        LibvirtComputingResource libvirtComputingResource = mock(LibvirtComputingResource.class);
+        GetVmIpAddressCommand getVmIpAddressCommand = mock(GetVmIpAddressCommand.class);
+        LibvirtGetVmIpAddressCommandWrapper commandWrapper = new LibvirtGetVmIpAddressCommandWrapper();
+        MockedStatic<Script> scriptMock = null;
+        try {
+            scriptMock = mockStatic(Script.class);
+            when(getVmIpAddressCommand.getVmName()).thenReturn("validVmName");
+            when(getVmIpAddressCommand.getVmNetworkCidr()).thenReturn("192.168.0.0/24");
+            when(getVmIpAddressCommand.isWindows()).thenReturn(true);
+            when(Script.executePipedCommands(anyList(), anyLong())).thenReturn(new Pair<>(0, "\"192.168.0.10\""));
+
+            Answer answer = commandWrapper.execute(getVmIpAddressCommand, libvirtComputingResource);
+
+            assertTrue(answer.getResult());
+            assertEquals("192.168.0.10", answer.getDetails());
+        } finally {
+            if (scriptMock != null)
+                scriptMock.close();
+        }
+    }
+
+    @Test
+    public void testIpFromDomIfCommandExecutionFailure() {
+        LibvirtComputingResource libvirtComputingResource = mock(LibvirtComputingResource.class);
+        GetVmIpAddressCommand getVmIpAddressCommand = mock(GetVmIpAddressCommand.class);
+        LibvirtGetVmIpAddressCommandWrapper commandWrapper = new LibvirtGetVmIpAddressCommandWrapper();
+        MockedStatic<Script> scriptMock = null;
+        try {
+            scriptMock = mockStatic(Script.class);
+            when(getVmIpAddressCommand.getVmName()).thenReturn("testVm");
+            when(getVmIpAddressCommand.getVmNetworkCidr()).thenReturn("192.168.1.0/24");
+            when(Script.executePipedCommands(anyList(), anyLong())).thenReturn(null);
+
+            Answer answer = commandWrapper.execute(getVmIpAddressCommand, libvirtComputingResource);
+
+            assertFalse(answer.getResult());
+            assertNull(answer.getDetails());
+        } finally {
+            if (scriptMock != null)
+                scriptMock.close();
+        }
+    }
+
+    @Test
+    public void testIpFromDhcpLeaseFileCommandExecutionFailure() {
+        LibvirtComputingResource libvirtComputingResource = mock(LibvirtComputingResource.class);
+        GetVmIpAddressCommand getVmIpAddressCommand = mock(GetVmIpAddressCommand.class);
+        LibvirtGetVmIpAddressCommandWrapper commandWrapper = new LibvirtGetVmIpAddressCommandWrapper();
+        MockedStatic<Script> scriptMock = null;
+        try {
+            scriptMock = mockStatic(Script.class);
+            when(getVmIpAddressCommand.getVmName()).thenReturn("testVm");
+            when(getVmIpAddressCommand.getVmNetworkCidr()).thenReturn("192.168.1.0/24");
+            when(Script.executePipedCommands(anyList(), anyLong())).thenReturn(null);
+
+            Answer answer = commandWrapper.execute(getVmIpAddressCommand, libvirtComputingResource);
+
+            assertFalse(answer.getResult());
+            assertNull(answer.getDetails());
+        } finally {
+            if (scriptMock != null)
+                scriptMock.close();
+        }
+    }
+
+    @Test
+    public void testIpFromWindowsRegistryCommandExecutionFailure() {
+        LibvirtComputingResource libvirtComputingResource = mock(LibvirtComputingResource.class);
+        GetVmIpAddressCommand getVmIpAddressCommand = mock(GetVmIpAddressCommand.class);
+        LibvirtGetVmIpAddressCommandWrapper commandWrapper = new LibvirtGetVmIpAddressCommandWrapper();
+        MockedStatic<Script> scriptMock = null;
+        try {
+            scriptMock = mockStatic(Script.class);
+            when(getVmIpAddressCommand.getVmName()).thenReturn("testVm");
+            when(getVmIpAddressCommand.getVmNetworkCidr()).thenReturn("192.168.1.0/24");
+            when(getVmIpAddressCommand.isWindows()).thenReturn(true);
+            when(Script.executePipedCommands(anyList(), anyLong())).thenReturn(null);
+
+            Answer answer = commandWrapper.execute(getVmIpAddressCommand, libvirtComputingResource);
+
+            assertFalse(answer.getResult());
+            assertNull(answer.getDetails());
+        } finally {
+            if (scriptMock != null)
+                scriptMock.close();
+        }
+    }
+
+    @Test
+    public void testInit() {
+        MockedStatic<Script> scriptMock = null;
+        try {
+            scriptMock = mockStatic(Script.class);
+            scriptMock.when(() -> Script.getExecutableAbsolutePath("virt-ls")).thenReturn("/usr/bin/virt-ls");
+            scriptMock.when(() -> Script.getExecutableAbsolutePath("virt-cat")).thenReturn("/usr/bin/virt-cat");
+            scriptMock.when(() -> Script.getExecutableAbsolutePath("virt-win-reg")).thenReturn("/usr/bin/virt-win-reg");
+            scriptMock.when(() -> Script.getExecutableAbsolutePath("tail")).thenReturn("/usr/bin/tail");
+            scriptMock.when(() -> Script.getExecutableAbsolutePath("grep")).thenReturn("/usr/bin/grep");
+            scriptMock.when(() -> Script.getExecutableAbsolutePath("awk")).thenReturn("/usr/bin/awk");
+            scriptMock.when(() -> Script.getExecutableAbsolutePath("sed")).thenReturn("/usr/bin/sed");
+            scriptMock.when(() -> Script.getExecutableAbsolutePath("virsh")).thenReturn("/usr/bin/virsh");
+
+            LibvirtGetVmIpAddressCommandWrapper.init();
+
+            assertEquals("/usr/bin/virt-ls", LibvirtGetVmIpAddressCommandWrapper.virt_ls_path);
+            assertEquals("/usr/bin/virt-cat", LibvirtGetVmIpAddressCommandWrapper.virt_cat_path);
+            assertEquals("/usr/bin/virt-win-reg", LibvirtGetVmIpAddressCommandWrapper.virt_win_reg_path);
+            assertEquals("/usr/bin/tail", LibvirtGetVmIpAddressCommandWrapper.tail_path);
+            assertEquals("/usr/bin/grep", LibvirtGetVmIpAddressCommandWrapper.grep_path);
+            assertEquals("/usr/bin/awk", LibvirtGetVmIpAddressCommandWrapper.awk_path);
+            assertEquals("/usr/bin/sed", LibvirtGetVmIpAddressCommandWrapper.sed_path);
+            assertEquals("/usr/bin/virsh", LibvirtGetVmIpAddressCommandWrapper.virsh_path);
+        } finally {
+            if (scriptMock != null)
+                scriptMock.close();
+        }
+    }
+}

Review Comment:
   ```suggestion
   }
   
   ```



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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on code in PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#discussion_r1963847896


##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmIpAddressCommandWrapper.java:
##########
@@ -47,15 +47,33 @@ public Answer execute(final GetVmIpAddressCommand command, final LibvirtComputin
         }
         String sanitizedVmName = sanitizeBashCommandArgument(vmName);
         String networkCidr = command.getVmNetworkCidr();
-        List<String[]> commands = new ArrayList<>();
         final String virt_ls_path = Script.getExecutableAbsolutePath("virt-ls");
         final String virt_cat_path = Script.getExecutableAbsolutePath("virt-cat");
         final String virt_win_reg_path = Script.getExecutableAbsolutePath("virt-win-reg");
         final String tail_path = Script.getExecutableAbsolutePath("tail");
         final String grep_path = Script.getExecutableAbsolutePath("grep");
         final String awk_path = Script.getExecutableAbsolutePath("awk");
         final String sed_path = Script.getExecutableAbsolutePath("sed");
-        if(!command.isWindows()) {
+        final String virsh_path = Script.getExecutableAbsolutePath("virsh");
+
+        // first run virsh domiflist to get the network interface name from libvirt.  This is set if qemu guest agent is running in the VM
+        // and is the most reliable and least intrusive
+        List<String[]> commands = new ArrayList<>();
+        commands.add(new String[]{virsh_path, "domifaddr", sanitizedVmName, "--source", "agent"});
+        String output = Script.executePipedCommands(commands, 0).second();
+        if (output != null) {
+            String[] lines = output.split("\n");
+            for (String line : lines) {
+                ip = parseDomIfListOutput(line, networkCidr);
+                if (ip != null) {
+                    break;
+                }
+            }
+        }

Review Comment:
   can this be a new method as well?



##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmIpAddressCommandWrapper.java:
##########
@@ -47,15 +47,33 @@ public Answer execute(final GetVmIpAddressCommand command, final LibvirtComputin
         }
         String sanitizedVmName = sanitizeBashCommandArgument(vmName);
         String networkCidr = command.getVmNetworkCidr();
-        List<String[]> commands = new ArrayList<>();
         final String virt_ls_path = Script.getExecutableAbsolutePath("virt-ls");
         final String virt_cat_path = Script.getExecutableAbsolutePath("virt-cat");
         final String virt_win_reg_path = Script.getExecutableAbsolutePath("virt-win-reg");
         final String tail_path = Script.getExecutableAbsolutePath("tail");
         final String grep_path = Script.getExecutableAbsolutePath("grep");
         final String awk_path = Script.getExecutableAbsolutePath("awk");
         final String sed_path = Script.getExecutableAbsolutePath("sed");
-        if(!command.isWindows()) {
+        final String virsh_path = Script.getExecutableAbsolutePath("virsh");
+
+        // first run virsh domiflist to get the network interface name from libvirt.  This is set if qemu guest agent is running in the VM
+        // and is the most reliable and least intrusive
+        List<String[]> commands = new ArrayList<>();
+        commands.add(new String[]{virsh_path, "domifaddr", sanitizedVmName, "--source", "agent"});
+        String output = Script.executePipedCommands(commands, 0).second();
+        if (output != null) {
+            String[] lines = output.split("\n");
+            for (String line : lines) {
+                ip = parseDomIfListOutput(line, networkCidr);
+                if (ip != null) {
+                    break;
+                }
+            }
+        }
+
+        commands.clear();
+        commands.add(new String[]{grep_path, ".*\\*"});
+        if(ip == null && !command.isWindows()) {

Review Comment:
   now what if later `(ip != null && !command.isWindows())`, are we going the part commented `// For windows, read ...` anyway?



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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#issuecomment-2655702264

   @rohityadavcloud a [SL] Jenkins job has been kicked to build packages. It will be bundled with  KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.


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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#issuecomment-2687281140

   @DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests


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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "weizhouapache (via GitHub)" <gi...@apache.org>.
weizhouapache commented on code in PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#discussion_r1975726310


##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmIpAddressCommandWrapper.java:
##########
@@ -37,6 +38,26 @@ public final class LibvirtGetVmIpAddressCommandWrapper extends CommandWrapper<Ge
 
     private static final Logger s_logger = Logger.getLogger(LibvirtGetVmIpAddressCommandWrapper.class);
 
+    static String virsh_path = null;
+    static String virt_win_reg_path = null;
+    static String grep_path = null;
+    static String awk_path = null;
+    static String sed_path = null;
+    static String virt_ls_path = null;
+    static String virt_cat_path = null;
+    static String tail_path = null;
+
+    static void init() {

Review Comment:
   @rg9975 
   the method is never used in LibvirtGetVmIpAddressCommandWrapper.java
   which breaks the functionality
   
   I will fix it in #10431 



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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#issuecomment-2687277201

   @blueorangutan test


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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "weizhouapache (via GitHub)" <gi...@apache.org>.
weizhouapache commented on PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#issuecomment-2689054288

   This does work in my testing on ubuntu 24.
   I will give a suggestion tomorrow


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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#issuecomment-2656183336

   @blueorangutan test


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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#issuecomment-2655713291

   ## [Codecov](https://app.codecov.io/gh/apache/cloudstack/pull/10376?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   All modified and coverable lines are covered by tests :white_check_mark:
   > Project coverage is 4.29%. Comparing base [(`ae1d7cc`)](https://app.codecov.io/gh/apache/cloudstack/commit/ae1d7cc86091ce1612dba9981c01d63544c5c426?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`76b34fb`)](https://app.codecov.io/gh/apache/cloudstack/commit/76b34fb30cd6579301ba3d1dbdee703a291a1b29?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   
   > :exclamation:  There is a different number of reports uploaded between BASE (ae1d7cc) and HEAD (76b34fb). Click for more details.
   > 
   > <details><summary>HEAD has 1 upload less than BASE</summary>
   >
   >| Flag | BASE (ae1d7cc) | HEAD (76b34fb) |
   >|------|------|------|
   >|unittests|1|0|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@              Coverage Diff              @@
   ##               4.19   #10376       +/-   ##
   =============================================
   - Coverage     15.15%    4.29%   -10.87%     
   =============================================
     Files          5413      367     -5046     
     Lines        474670    29627   -445043     
     Branches      57890     5199    -52691     
   =============================================
   - Hits          71943     1272    -70671     
   + Misses       394680    28210   -366470     
   + Partials       8047      145     -7902     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/cloudstack/pull/10376/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [uitests](https://app.codecov.io/gh/apache/cloudstack/pull/10376/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `4.29% <ø> (ø)` | |
   | [unittests](https://app.codecov.io/gh/apache/cloudstack/pull/10376/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/cloudstack/pull/10376?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   


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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "rg9975 (via GitHub)" <gi...@apache.org>.
rg9975 commented on code in PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#discussion_r1971767387


##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmIpAddressCommandWrapper.java:
##########
@@ -47,15 +47,33 @@ public Answer execute(final GetVmIpAddressCommand command, final LibvirtComputin
         }
         String sanitizedVmName = sanitizeBashCommandArgument(vmName);
         String networkCidr = command.getVmNetworkCidr();
-        List<String[]> commands = new ArrayList<>();
         final String virt_ls_path = Script.getExecutableAbsolutePath("virt-ls");
         final String virt_cat_path = Script.getExecutableAbsolutePath("virt-cat");
         final String virt_win_reg_path = Script.getExecutableAbsolutePath("virt-win-reg");
         final String tail_path = Script.getExecutableAbsolutePath("tail");
         final String grep_path = Script.getExecutableAbsolutePath("grep");
         final String awk_path = Script.getExecutableAbsolutePath("awk");
         final String sed_path = Script.getExecutableAbsolutePath("sed");
-        if(!command.isWindows()) {
+        final String virsh_path = Script.getExecutableAbsolutePath("virsh");
+
+        // first run virsh domiflist to get the network interface name from libvirt.  This is set if qemu guest agent is running in the VM
+        // and is the most reliable and least intrusive
+        List<String[]> commands = new ArrayList<>();
+        commands.add(new String[]{virsh_path, "domifaddr", sanitizedVmName, "--source", "agent"});
+        String output = Script.executePipedCommands(commands, 0).second();
+        if (output != null) {
+            String[] lines = output.split("\n");
+            for (String line : lines) {
+                ip = parseDomIfListOutput(line, networkCidr);
+                if (ip != null) {
+                    break;
+                }
+            }
+        }

Review Comment:
   modularized better, fixed a few issues, and added test cases.



##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmIpAddressCommandWrapper.java:
##########
@@ -47,15 +47,33 @@ public Answer execute(final GetVmIpAddressCommand command, final LibvirtComputin
         }
         String sanitizedVmName = sanitizeBashCommandArgument(vmName);
         String networkCidr = command.getVmNetworkCidr();
-        List<String[]> commands = new ArrayList<>();
         final String virt_ls_path = Script.getExecutableAbsolutePath("virt-ls");
         final String virt_cat_path = Script.getExecutableAbsolutePath("virt-cat");
         final String virt_win_reg_path = Script.getExecutableAbsolutePath("virt-win-reg");
         final String tail_path = Script.getExecutableAbsolutePath("tail");
         final String grep_path = Script.getExecutableAbsolutePath("grep");
         final String awk_path = Script.getExecutableAbsolutePath("awk");
         final String sed_path = Script.getExecutableAbsolutePath("sed");
-        if(!command.isWindows()) {
+        final String virsh_path = Script.getExecutableAbsolutePath("virsh");
+
+        // first run virsh domiflist to get the network interface name from libvirt.  This is set if qemu guest agent is running in the VM
+        // and is the most reliable and least intrusive
+        List<String[]> commands = new ArrayList<>();
+        commands.add(new String[]{virsh_path, "domifaddr", sanitizedVmName, "--source", "agent"});
+        String output = Script.executePipedCommands(commands, 0).second();
+        if (output != null) {
+            String[] lines = output.split("\n");
+            for (String line : lines) {
+                ip = parseDomIfListOutput(line, networkCidr);
+                if (ip != null) {
+                    break;
+                }
+            }
+        }
+
+        commands.clear();
+        commands.add(new String[]{grep_path, ".*\\*"});
+        if(ip == null && !command.isWindows()) {

Review Comment:
   modularized better, fixed a few issues, and added test cases.



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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#issuecomment-2685387814

   @weizhouapache a [SL] Jenkins job has been kicked to build packages. It will be bundled with  KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.


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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#issuecomment-2689327941

   <b>[SF] Trillian test result (tid-12503)</b>
   Environment: kvm-ol8 (x2), Advanced Networking with Mgmt server ol8
   Total time taken: 49673 seconds
   Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr10376-t12503-kvm-ol8.zip
   Smoke tests completed. 132 look OK, 1 have errors, 0 did not run
   Only failed and skipped tests results shown below:
   
   
   Test | Result | Time (s) | Test File
   --- | --- | --- | ---
   test_01_redundant_vpc_site2site_vpn | `Failure` | 434.27 | test_vpc_vpn.py
   


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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "NuxRo (via GitHub)" <gi...@apache.org>.
NuxRo commented on PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#issuecomment-2693994159

   Thanks @rg9975 and @weizhouapache - I'm watching this closely and will be testing.
   
   Very interested in the feature for both shared and especially L2 networks.
   
   


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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "rg9975 (via GitHub)" <gi...@apache.org>.
rg9975 commented on PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#issuecomment-2690819571

   > > Sorry missed your comment @weizhouapache if there are further changes you could review if this needs to be reverted or you want to raise a new PR?
   > 
   > @rohityadavcloud no worries, I will address it in another PR #10431
   > 
   > btw, actually I missed a word in my previous comment. 🤦‍♂️
   > 
   > This does **NOT** work in my testing on ubuntu 24.
   
   What exactly is the problem you are seeing? you mean Ubuntu on the hypervisor or on the guest OS?


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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "rohityadavcloud (via GitHub)" <gi...@apache.org>.
rohityadavcloud commented on PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#issuecomment-2655701587

   @blueorangutan package


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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#issuecomment-2656188257

   @DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests


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


Re: [PR] add use of virsh domifaddr to get VM external DHCP IP [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #10376:
URL: https://github.com/apache/cloudstack/pull/10376#issuecomment-2657998992

   <b>[SF] Trillian test result (tid-12390)</b>
   Environment: kvm-ol8 (x2), Advanced Networking with Mgmt server ol8
   Total time taken: 47368 seconds
   Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr10376-t12390-kvm-ol8.zip
   Smoke tests completed. 132 look OK, 1 have errors, 0 did not run
   Only failed and skipped tests results shown below:
   
   
   Test | Result | Time (s) | Test File
   --- | --- | --- | ---
   test_02_list_cpvm_vm | `Failure` | 0.05 | test_ssvm.py
   test_04_cpvm_internals | `Failure` | 0.05 | test_ssvm.py
   


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