Skip to content

Commit

Permalink
Merge "Network change, VMI needs new IP Address Closes-Bug: #1550030"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Mar 2, 2016
2 parents 490b8c2 + 6db4a05 commit fbc8726
Show file tree
Hide file tree
Showing 5 changed files with 318 additions and 111 deletions.
68 changes: 35 additions & 33 deletions src/net/juniper/contrail/vcenter/VirtualMachineInterfaceInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package net.juniper.contrail.vcenter;

import java.io.IOException;
import com.google.common.net.InetAddresses;
import com.vmware.vim25.GuestNicInfo;
import com.vmware.vim25.NetIpConfigInfo;
import com.vmware.vim25.NetIpConfigInfoIpAddress;
Expand Down Expand Up @@ -79,7 +80,11 @@ public String getIpAddress() {
}

public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
if (vnInfo.isIpAddressInSubnetAndRange(ipAddress)) {
this.ipAddress = ipAddress;
} else {
this.ipAddress = null;
}
}

public boolean getPortAdded() {
Expand Down Expand Up @@ -115,7 +120,7 @@ public void updatedGuestNic(GuestNicInfo nic, VncDB vncDB)

deletePort();

ipAddress = newIpAddress;
setIpAddress(newIpAddress);

if (ipAddress != null || vnInfo.getExternalIpam() == false) {
vncDB.createInstanceIp(this);
Expand Down Expand Up @@ -162,7 +167,7 @@ void create(VncDB vncDB) throws Exception {
if (vmInfo.getToolsRunningStatus().equals(VirtualMachineToolsRunningStatus.guestToolsRunning.toString())) {
// static IP Address & vmWare tools installed
// see if we can read it from Guest Nic Info
ipAddress = VCenterDB.getVirtualMachineIpAddress(vmInfo.vm, vnInfo.getName());
setIpAddress(VCenterDB.getVirtualMachineIpAddress(vmInfo.vm, vnInfo.getName()));
}
VCenterNotify.watchVm(vmInfo);
}
Expand All @@ -187,41 +192,38 @@ void update(VCenterObject obj,

VirtualMachineInterfaceInfo newVmiInfo = (VirtualMachineInterfaceInfo)obj;

// change of Ip Address, MAC address or network triggers a delete / recreate
if ((newVmiInfo.ipAddress != null && !newVmiInfo.ipAddress.equals(ipAddress))
|| (newVmiInfo.macAddress != null && !newVmiInfo.macAddress.equals(macAddress))
|| vnInfo != newVmiInfo.vnInfo) {

// change of network
if (vnInfo != newVmiInfo.vnInfo) {
// Delete old VMI and create VMI over new network
delete(vncDB);
vnInfo = newVmiInfo.vnInfo;
ipAddress = newVmiInfo.ipAddress;
macAddress = newVmiInfo.macAddress;
create(vncDB);
return;
} else {
deletePort();

vncDB.deleteInstanceIp(this);
if (newVmiInfo.ipAddress != null) {
ipAddress = newVmiInfo.ipAddress;
}

if (newVmiInfo.macAddress != null) {
macAddress = newVmiInfo.macAddress;
}
}

if (ipAddress != null || vnInfo.getExternalIpam() == false) {
vncDB.createInstanceIp(this);
if (vnInfo != newVmiInfo.vnInfo
|| (newVmiInfo.macAddress != null && !newVmiInfo.macAddress.equals(macAddress))) {
// change of network or MAC address
delete(vncDB);
vnInfo = newVmiInfo.vnInfo;
setIpAddress(newVmiInfo.ipAddress);
macAddress = newVmiInfo.macAddress;
if (newVmiInfo.uuid != null && !newVmiInfo.uuid.equals(uuid)) {
uuid = newVmiInfo.uuid;
}
create(vncDB);
return;
}

if (newVmiInfo.uuid != null && !newVmiInfo.uuid.equals(uuid)) {
uuid = newVmiInfo.uuid;
}
if (newVmiInfo.ipAddress != null && !newVmiInfo.ipAddress.equals(ipAddress)) {
// change of IP Address
deletePort();
vncDB.deleteInstanceIp(this);

// vmware bug: after vmware tools restart, ip address is incorrectly reset to null
// this check for null is a workaround
if (newVmiInfo.ipAddress != null) {
setIpAddress(newVmiInfo.ipAddress);
}

if (ipAddress != null || vnInfo.getExternalIpam() == false) {
vncDB.createInstanceIp(this);
}
}

if (vmInfo.isPoweredOnState()) {
if (!portAdded) {
Expand Down Expand Up @@ -250,7 +252,7 @@ void sync(VCenterObject obj,
}

if (ipAddress == null && oldVmiInfo.ipAddress != null) {
ipAddress = oldVmiInfo.ipAddress;
setIpAddress(oldVmiInfo.ipAddress);
}

if (macAddress == null && oldVmiInfo.macAddress != null) {
Expand Down

0 comments on commit fbc8726

Please sign in to comment.