@@ -753,7 +753,7 @@ private class VmIpAddrFetchThread extends ManagedContextRunnable {
753
753
String networkCidr ;
754
754
String macAddress ;
755
755
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 ) {
757
757
this .vmId = vmId ;
758
758
this .vmUuid = vmUuid ;
759
759
this .nicId = nicId ;
@@ -775,8 +775,13 @@ protected void runInContext() {
775
775
Answer answer = _agentMgr .send (hostId , cmd );
776
776
if (answer .getResult ()) {
777
777
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 )) {
780
785
// set this vm ip addr in vm nic.
781
786
if (nic != null ) {
782
787
nic .setIPv4Address (vmIp );
@@ -791,12 +796,8 @@ protected void runInContext() {
791
796
}
792
797
}
793
798
} 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 ;
800
801
if (answer .getDetails () != null ) {
801
802
logger .debug ("Failed to get vm ip for Vm [id: {}, uuid: {}, name: {}], details: {}" ,
802
803
vmId , vmUuid , vmName , answer .getDetails ());
@@ -2693,7 +2694,8 @@ protected void runInContext() {
2693
2694
VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl (userVm );
2694
2695
VirtualMachine vm = vmProfile .getVirtualMachine ();
2695
2696
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 (),
2697
2699
isWindows , vm .getHostId (), network .getCidr (), nicVo .getMacAddress ()));
2698
2700
2699
2701
}
0 commit comments