use of org.apache.cloudstack.network.opendaylight.agent.responses.ConfigureNetworkAnswer in project cloudstack by apache.
the class OpendaylightGuestNetworkGuru method implement.
@Override
public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
long dcId = dest.getDataCenter().getId();
//get physical network id
Long physicalNetworkId = network.getPhysicalNetworkId();
// physical network id can be null in Guest Network in Basic zone, so locate the physical network
if (physicalNetworkId == null) {
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, offering.getRedundantRouter());
if (network.getGateway() != null) {
implemented.setGateway(network.getGateway());
}
if (network.getCidr() != null) {
implemented.setCidr(network.getCidr());
}
// Name is either the given name or the uuid
String name = network.getName();
if (name == null || name.isEmpty()) {
name = ((NetworkVO) network).getUuid();
}
List<OpenDaylightControllerVO> devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physicalNetworkId);
if (devices.isEmpty()) {
s_logger.error("No Controller on physical network " + physicalNetworkId);
return null;
}
OpenDaylightControllerVO controller = devices.get(0);
ConfigureNetworkCommand cmd = new ConfigureNetworkCommand(name, context.getAccount().getAccountName());
ConfigureNetworkAnswer answer = (ConfigureNetworkAnswer) agentManager.easySend(controller.getHostId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("ConfigureNetworkCommand failed");
return null;
}
implemented.setBroadcastUri(BroadcastDomainType.OpenDaylight.toUri(answer.getNetworkUuid()));
implemented.setBroadcastDomainType(BroadcastDomainType.OpenDaylight);
s_logger.info("Implemented OK, network linked to = " + implemented.getBroadcastUri().toString());
return implemented;
}
use of org.apache.cloudstack.network.opendaylight.agent.responses.ConfigureNetworkAnswer in project cloudstack by apache.
the class OpenDaylightControllerResource method executeRequest.
private Answer executeRequest(ConfigureNetworkCommand cmd) {
NeutronNetworksNorthboundAction configureNetwork = new NeutronNetworksNorthboundAction(controllerUrl, controllerUsername, controllerPassword);
// Find free gre key
int gre_key = -1;
Random keyGenerator = new Random(System.currentTimeMillis());
try {
NeutronNetworksList<NeutronNetwork> networks = configureNetwork.listAllNetworks();
while (true) {
int i = keyGenerator.nextInt();
for (NeutronNetwork network : networks.getNetworks()) {
if (network.getSegmentationId() == i) {
continue;
}
}
gre_key = i;
break;
}
} catch (NeutronRestApiException e) {
s_logger.error("Failed to list existing networks on the ODL Controller", e);
return new ConfigureNetworkAnswer(cmd, e);
}
NeutronNetwork newNetwork = new NeutronNetwork();
// Configuration from the command
newNetwork.setName(cmd.getName());
newNetwork.setTenantId(cmd.getTenantId());
// Static configuation
newNetwork.setNetworkType("gre");
newNetwork.setShared(false);
newNetwork.setSegmentationId(gre_key);
newNetwork.setId(UUID.randomUUID());
NeutronNetworkWrapper wrapper = new NeutronNetworkWrapper();
wrapper.setNetwork(newNetwork);
try {
wrapper = configureNetwork.createNeutronNetwork(wrapper);
} catch (NeutronRestApiException e) {
s_logger.error("createNeutronNetwork failed", e);
return new ConfigureNetworkAnswer(cmd, e);
}
return new ConfigureNetworkAnswer(cmd, true, null, wrapper.getNetwork().getId().toString());
}
Aggregations