Skip to content

Commit

Permalink
Error syncing up VM in plugin bootup, throws delete message
Browse files Browse the repository at this point in the history
Closes-Bug: #1560712

Change-Id: Ia9d4156bdf0abd6fe51a48b359fcae126899cfe6
  • Loading branch information
Andra Cismaru committed Mar 23, 2016
1 parent 062591a commit b27ceec
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/net/juniper/contrail/vcenter/VRouterNotifier.java
Expand Up @@ -43,7 +43,7 @@ public static void created(VirtualMachineInterfaceInfo vmiInfo) {
}

if (vmiInfo.getUuid() == null) {
s_logger.error("Null uuid, cannot perform DeletePort for " + vmiInfo);
s_logger.error("Null uuid, cannot perform AddPort for " + vmiInfo);
return;
}

Expand Down
89 changes: 82 additions & 7 deletions src/net/juniper/contrail/vcenter/VirtualNetworkInfo.java
Expand Up @@ -3,6 +3,7 @@
import java.rmi.RemoteException;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.UUID;
Expand All @@ -20,6 +21,9 @@
import com.vmware.vim25.mo.DistributedVirtualPortgroup;
import com.vmware.vim25.mo.ManagedObject;
import com.vmware.vim25.mo.util.PropertyCollectorUtil;
import net.juniper.contrail.api.ObjectReference;
import net.juniper.contrail.api.types.VnSubnetsType;
import net.juniper.contrail.api.types.VnSubnetsType.IpamSubnetType;

public class VirtualNetworkInfo extends VCenterObject {
private String uuid; // required attribute, key for this object
Expand Down Expand Up @@ -87,11 +91,40 @@ public VirtualNetworkInfo(VirtualNetworkInfo vnInfo)
}

public VirtualNetworkInfo(net.juniper.contrail.api.types.VirtualNetwork vn) {
this.apiVn = vn;
this.uuid = vn.getUuid();

if (vn == null) {
throw new IllegalArgumentException();
}

apiVn = vn;
uuid = vn.getUuid();
name = vn.getName();
this.vmiInfoMap = new ConcurrentSkipListMap<String, VirtualMachineInterfaceInfo>();
this.externalIpam = vn.getExternalIpam();
vmiInfoMap = new ConcurrentSkipListMap<String, VirtualMachineInterfaceInfo>();
externalIpam = vn.getExternalIpam();

List<ObjectReference<VnSubnetsType>> objList = vn.getNetworkIpam();
if (objList != null) {
for (ObjectReference<VnSubnetsType> objRef: Utils.safe(objList)) {
if (objRef == null) {
continue;
}
VnSubnetsType subnetsType = objRef.getAttr();
List<IpamSubnetType> ipamsubList = subnetsType.getIpamSubnets();
if (ipamsubList == null) {
continue;
}
for (IpamSubnetType sub: ipamsubList) {
if (sub == null) {
continue;
}
subnetAddress = sub.getSubnet().getIpPrefix();
int len = sub.getSubnet().getIpPrefixLen();
int mask = 0xFFFFFFFF << (32 - len);
subnetMask = InetAddresses.fromInteger(mask).getHostAddress();
gatewayAddress = sub.getDefaultGateway();
}
}
}
}

public VirtualNetworkInfo(Event event, VCenterDB vcenterDB) throws Exception {
Expand Down Expand Up @@ -548,8 +581,46 @@ void sync(VCenterObject obj, VncDB vncDB)
throws Exception {

VirtualNetworkInfo oldVnInfo = (VirtualNetworkInfo)obj;

if (oldVnInfo.apiVn != null) {

if (uuid == null && oldVnInfo.uuid != null) {
uuid = oldVnInfo.uuid;
}

if (name == null && oldVnInfo.name != null) {
name = oldVnInfo.name;
}

if (isolatedVlanId == 0 && oldVnInfo.isolatedVlanId != 0) {
isolatedVlanId = oldVnInfo.isolatedVlanId;
}

if (primaryVlanId == 0 && oldVnInfo.primaryVlanId != 0) {
primaryVlanId = oldVnInfo.primaryVlanId;
}

if (ipPoolId == null && oldVnInfo.ipPoolId != null) {
ipPoolId = oldVnInfo.ipPoolId;
}

if (subnetAddress == null && oldVnInfo.subnetAddress != null) {
subnetAddress = oldVnInfo.subnetAddress;
externalIpam = oldVnInfo.externalIpam;
}

if (subnetMask == null && oldVnInfo.subnetMask != null) {
subnetMask = oldVnInfo.subnetMask;
}

if (gatewayAddress == null && oldVnInfo.gatewayAddress != null) {
gatewayAddress = oldVnInfo.gatewayAddress;
}

if (range == null && oldVnInfo.range != null) {
range = oldVnInfo.range;
ipPoolEnabled = oldVnInfo.ipPoolEnabled;
}

if (apiVn == null && oldVnInfo.apiVn != null) {
apiVn = oldVnInfo.apiVn;
}
}
Expand All @@ -574,14 +645,18 @@ public boolean isIpAddressInSubnetAndRange(String ipAddress) {
return true;
}

if (subnetAddress == null || subnetMask == null) {
return false;
}

int addr = InetAddresses.coerceToInteger(InetAddresses.forString(ipAddress));
int subnet = InetAddresses.coerceToInteger(InetAddresses.forString(subnetAddress));
int mask = InetAddresses.coerceToInteger(InetAddresses.forString(subnetMask));

if (((addr & mask) != subnet)) {
return false;
}
if (!ipPoolEnabled || range.isEmpty()) {
if (!ipPoolEnabled || range == null || range.isEmpty()) {
return true;
}

Expand Down

0 comments on commit b27ceec

Please sign in to comment.