use of org.apache.cloudstack.network.opendaylight.agent.responses.AddHypervisorAnswer in project cloudstack by apache.
the class OpendaylightGuestNetworkGuru method reserve.
@Override
public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
super.reserve(nic, network, vm, dest, context);
//get physical network id
Long physicalNetworkId = network.getPhysicalNetworkId();
List<OpenDaylightControllerVO> devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physicalNetworkId);
if (devices.isEmpty()) {
s_logger.error("No Controller on physical network " + physicalNetworkId);
throw new InsufficientVirtualNetworkCapacityException("No OpenDaylight Controller configured for this network", dest.getPod().getId());
}
OpenDaylightControllerVO controller = devices.get(0);
AddHypervisorCommand addCmd = new AddHypervisorCommand(dest.getHost().getUuid(), dest.getHost().getPrivateIpAddress());
AddHypervisorAnswer addAnswer = (AddHypervisorAnswer) agentManager.easySend(controller.getHostId(), addCmd);
if (addAnswer == null || !addAnswer.getResult()) {
s_logger.error("Failed to add " + dest.getHost().getName() + " as a node to the controller");
throw new InsufficientVirtualNetworkCapacityException("Failed to add destination hypervisor to the OpenDaylight Controller", dest.getPod().getId());
}
ConfigurePortCommand cmd = new ConfigurePortCommand(UUID.fromString(nic.getUuid()), UUID.fromString(BroadcastDomainType.getValue(network.getBroadcastUri())), context.getAccount().getAccountName(), nic.getMacAddress());
ConfigurePortAnswer answer = (ConfigurePortAnswer) agentManager.easySend(controller.getHostId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("ConfigureNetworkCommand failed");
throw new InsufficientVirtualNetworkCapacityException("Failed to configure the port on the OpenDaylight Controller", dest.getPod().getId());
}
}
use of org.apache.cloudstack.network.opendaylight.agent.responses.AddHypervisorAnswer in project cloudstack by apache.
the class OpenDaylightControllerResource method executeRequest.
private Answer executeRequest(AddHypervisorCommand cmd) {
NeutronNodesNorthboundAction nodeActions = new NeutronNodesNorthboundAction(controllerUrl, controllerUsername, controllerPassword);
try {
NeutronNodesList<NeutronNodeWrapper> nodes = nodeActions.listAllNodes();
if (nodes.getNodes() != null) {
for (NeutronNodeWrapper nodeWrapper : nodes.getNodes()) {
NeutronNode node = nodeWrapper.getNode();
if (node.getId().equals(cmd.getHostId())) {
return new AddHypervisorAnswer(cmd, true, "Hypervisor already connected");
}
}
}
// Not found in the existing node list, add it
nodeActions.updateNeutronNodeV2("OVS", cmd.getHostId(), cmd.getIpAddress(), 6640);
} catch (NeutronRestApiException e) {
s_logger.error("Call to OpenDaylight failed", e);
return new AddHypervisorAnswer(cmd, e);
}
return new AddHypervisorAnswer(cmd, true, "Hypervisor " + cmd.getHostId() + " added");
}
Aggregations