//get physical network id
long physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId,
offering.getTags(),
offering.getTrafficType());
NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(),
network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated,
network.getDataCenterId(), physicalNetworkId);
if (network.getGateway() != null) {
implemented.setGateway(network.getGateway());
}
if (network.getCidr() != null) {
implemented.setCidr(network.getCidr());
}
String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId,
network.getAccountId(), context.getReservationId(), canUseSystemGuestVlan(network.getAccountId()));
if (vnet == null) {
throw new InsufficientVirtualNetworkCapcityException("Unable to allocate vnet as a " +
"part of network " + network + " implement ", DataCenter.class, dcId);
}
int vlan = Integer.parseInt(vnet);
// Name is either the given name or the uuid
String name = network.getName();
String networkUuid = implemented.getUuid();
if (name == null || name.isEmpty()) {
name = ((NetworkVO)network).getUuid();
}
if (name.length() > 64 ) {
name = name.substring(0, 63); // max length 64
}
String tenantId = context.getDomain().getName();
List<BigSwitchVnsDeviceVO> devices = _bigswitchVnsDao.listByPhysicalNetwork(physicalNetworkId);
if (devices.isEmpty()) {
s_logger.error("No BigSwitch Controller on physical network " + physicalNetworkId);
return null;
}
BigSwitchVnsDeviceVO bigswitchVnsDevice = devices.get(0);
HostVO bigswitchVnsHost = _hostDao.findById(bigswitchVnsDevice.getHostId());
_hostDao.loadDetails(bigswitchVnsHost);
CreateVnsNetworkCommand cmd = new CreateVnsNetworkCommand(networkUuid, name, tenantId, vlan);
CreateVnsNetworkAnswer answer = (CreateVnsNetworkAnswer) _agentMgr.easySend(bigswitchVnsHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error ("CreateNetworkCommand failed");
return null;
}
try {
implemented.setBroadcastUri(new URI("vns", cmd.getNetworkUuid(), null));
implemented.setBroadcastDomainType(BroadcastDomainType.Lswitch);
s_logger.info("Implemented OK, network " + networkUuid + " in tenant " +
tenantId + " linked to " + implemented.getBroadcastUri().toString());
} catch (URISyntaxException e) {
s_logger.error("Unable to store network id in broadcast uri, uuid = " + implemented.getUuid(), e);
}
return implemented;
}