@@ -753,7 +753,7 @@ private class VmIpAddrFetchThread extends ManagedContextRunnable {
753753 String networkCidr ;
754754 String macAddress ;
755755
756- public VmIpAddrFetchThread (long vmId , long nicId , String instanceName , boolean windows , Long hostId , String networkCidr , String macAddress ) {
756+ public VmIpAddrFetchThread (long vmId , String vmUuid , long nicId , String instanceName , boolean windows , Long hostId , String networkCidr , String macAddress ) {
757757 this .vmId = vmId ;
758758 this .vmUuid = vmUuid ;
759759 this .nicId = nicId ;
@@ -775,8 +775,13 @@ protected void runInContext() {
775775 Answer answer = _agentMgr .send (hostId , cmd );
776776 if (answer .getResult ()) {
777777 String vmIp = answer .getDetails ();
778-
779- if (NetUtils .isValidIp4 (vmIp )) {
778+ if (vmIp == null ) {
779+ // we got a valid response and the NIC does not have an IP assigned, as such we will update the database with null
780+ if (nic .getIPv4Address () != null ) {
781+ nic .setIPv4Address (null );
782+ _nicDao .update (nicId , nic );
783+ }
784+ } else if (NetUtils .isValidIp4 (vmIp )) {
780785 // set this vm ip addr in vm nic.
781786 if (nic != null ) {
782787 nic .setIPv4Address (vmIp );
@@ -791,12 +796,8 @@ protected void runInContext() {
791796 }
792797 }
793798 } else {
794- //previously vm has ip and nic table has ip address. After vm restart or stop/start
795- //if vm doesnot get the ip then set the ip in nic table to null
796- if (nic .getIPv4Address () != null ) {
797- nic .setIPv4Address (null );
798- _nicDao .update (nicId , nic );
799- }
799+ // since no changes are being done, we should not decrement IP usage
800+ decrementCount = false ;
800801 if (answer .getDetails () != null ) {
801802 logger .debug ("Failed to get vm ip for Vm [id: {}, uuid: {}, name: {}], details: {}" ,
802803 vmId , vmUuid , vmName , answer .getDetails ());
@@ -2693,7 +2694,8 @@ protected void runInContext() {
26932694 VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl (userVm );
26942695 VirtualMachine vm = vmProfile .getVirtualMachine ();
26952696 boolean isWindows = _guestOSCategoryDao .findById (_guestOSDao .findById (vm .getGuestOSId ()).getCategoryId ()).getName ().equalsIgnoreCase ("Windows" );
2696- _vmIpFetchThreadExecutor .execute (new VmIpAddrFetchThread (vmId , nicId , vmInstance .getInstanceName (),
2697+
2698+ _vmIpFetchThreadExecutor .execute (new VmIpAddrFetchThread (vmId , vmInstance .getUuid (), nicId , vmInstance .getInstanceName (),
26972699 isWindows , vm .getHostId (), network .getCidr (), nicVo .getMacAddress ()));
26982700
26992701 }
0 commit comments