}
if (nic.getTrafficType() == Networks.TrafficType.Guest ||
nic.getTrafficType() == Networks.TrafficType.Public &&
nic.getBroadcastType() == Networks.BroadcastDomainType.Mido){
Bridge netBridge = getOrCreateNetworkBridge(network);
if(nic.getTrafficType() == Networks.TrafficType.Public &&
vm.getVirtualMachine().getType() != VirtualMachine.Type.DomainRouter){
// Get provider router
Router providerRouter = api.getRouter(_providerRouterId);
Port[] ports = getOrCreatePublicBridgePorts(nic, netBridge, providerRouter);
RouterPort providerDownlink = (RouterPort) ports[1];
// Set route from router to bridge for this particular IP. Prepare
// is called in both starting a new VM and restarting a VM, so the
// NIC may
boolean routeExists = false;
for (Route route : providerRouter.getRoutes(new MultivaluedMapImpl())) {
String ip4 = route.getDstNetworkAddr();
if (ip4 != null && ip4.equals(nic.getIp4Address())) {
routeExists = true;
break;
}
}
if (!routeExists) {
providerRouter.addRoute()
.type("Normal")
.weight(100)
.srcNetworkAddr("0.0.0.0")
.srcNetworkLength(0)
.dstNetworkAddr(nic.getIp4Address())
.dstNetworkLength(32)
.nextHopPort(providerDownlink.getId())
.nextHopGateway(null)
.create();
}
}
// Add port on bridge
BridgePort newPort = netBridge.addExteriorPort().create(); // returns wrapper resource of port
// Set MidoNet port VIF ID to UUID of nic
UUID nicUUID = getNicUUID(nic);
newPort.vifId(nicUUID).update();
}