EduFrazao commented on issue #13519:
URL: https://github.com/apache/cloudstack/issues/13519#issuecomment-4849911938

   In order to investigate a little deeper, I've made some changes on 
ServerResourceBase and LibvirtComputingResource
   
   Insted of try to guess the private management ip address from listing all 
interfaces and getting the first with a IP (in case of the 
private.network.device does not have an IP directly associated), I've added a 
little snippet where I try to use the hypervisor OS routing table to resolve 
what is the best source ip address (the source address used to reach the 
management server).
   
   ```
   protected void 
tryToAutoDiscoverResourcePrivateNetworkInterfaceByRouteLookup(Map<String, 
Object> params) throws ConfigurationException {
           logger.info("Trying to autodiscover this resource's private network 
interface by route lookup");
           final String mgmtIp = collectMgmtHostIp(params);
           if (mgmtIp == null) {
               logger.info("Unable to resolve any management server ip address. 
Aborting private network search by route lookup.");
               return;
           }
           logger.info(String.format("Using management server IP [%s] to 
lookup", mgmtIp));
           try {
               InetAddress address = InetAddress.getByName(mgmtIp);
               try (DatagramSocket socket = new DatagramSocket()) {
                   socket.connect(address, 8250); // Port is not really 
important, can be hardcoded
                   // Asking for source address to mgmgt destination to O.S 
routing tables.
                   InetAddress localAddress = socket.getLocalAddress();
   
                   // Collecting interface with this source address
                   NetworkInterface nic = 
NetworkInterface.getByInetAddress(localAddress);
                   if (nic != null) {
                       logger.info(String.format("Using NIC [%s] as private 
NIC.", nic));
                       privateNic = nic;
                   }
               }
           } catch (Exception e) {
               // Logging only, if this method was unnable to find a valid 
interface, iteration will be tested
               logger.debug(String.format("Unable to use routing table to 
determine private management interface: [%s]", e.getMessage()));
           }
       }
   ````
   
   ```
   2026-07-01 00:08:19,302 INFO  [kvm.resource.LibvirtComputingResource] 
(main:[]) (logid:) Trying to autodiscover this resource's private network 
interface by route lookup
   2026-07-01 00:08:19,303 INFO  [kvm.resource.LibvirtComputingResource] 
(main:[]) (logid:) Params: [{host=10.254.0.101,10.254.0.100@roundrobin}]
   2026-07-01 00:08:19,303 INFO  [kvm.resource.LibvirtComputingResource] 
(main:[]) (logid:) Parsing host setting: [10.254.0.101,10.254.0.100@roundrobin]
   2026-07-01 00:08:19,303 INFO  [kvm.resource.LibvirtComputingResource] 
(main:[]) (logid:) Using management server IP [10.254.0.101] to lookup
   2026-07-01 00:08:19,307 INFO  [kvm.resource.LibvirtComputingResource] 
(main:[]) (logid:) Using NIC [name:v-clmgmt (v-clmgmt)] as private NIC.
   ```
   
   And now its working.
   If this method does not find any interfaces, the previous method continues 
to work.
   Do you guys thinks that this is acceptable?


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