use of org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO in project cloudstack by apache.
the class OpendaylightGuestNetworkGuru method release.
@Override
public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) {
boolean success = super.release(nic, vm, reservationId);
if (success) {
//get physical network id
NetworkVO network = _networkDao.findById(nic.getNetworkId());
Long physicalNetworkId = network.getPhysicalNetworkId();
List<OpenDaylightControllerVO> devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physicalNetworkId);
if (devices.isEmpty()) {
s_logger.error("No Controller on physical network " + physicalNetworkId);
throw new CloudRuntimeException("No OpenDaylight controller on this physical network");
}
OpenDaylightControllerVO controller = devices.get(0);
DestroyPortCommand cmd = new DestroyPortCommand(UUID.fromString(nic.getUuid()));
DestroyPortAnswer answer = (DestroyPortAnswer) agentManager.easySend(controller.getHostId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("DestroyPortCommand failed");
success = false;
}
}
return success;
}
use of org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO 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.dao.OpenDaylightControllerVO 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.dao.OpenDaylightControllerVO in project cloudstack by apache.
the class OpenDaylightControllerResourceManagerImpl method deleteController.
@Override
public void deleteController(DeleteOpenDaylightControllerCmd cmd) throws InvalidParameterValueException {
OpenDaylightControllerVO controller = openDaylightControllerMappingDao.findById(cmd.getId());
if (controller == null) {
throw new InvalidParameterValueException("No ODL Controller with id " + cmd.getId());
}
// Find the physical network we work for
Long physicalNetworkId = controller.getPhysicalNetworkId();
PhysicalNetworkVO physicalNetwork = physicalNetworkDao.findById(physicalNetworkId);
if (physicalNetwork != null) {
// Lets see if there are networks that use us
List<NetworkVO> networkList = networkDao.listByPhysicalNetwork(physicalNetworkId);
if (networkList != null) {
// Networks with broadcast type lswitch are ours
for (NetworkVO network : networkList) {
if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.OpenDaylight) {
if ((network.getState() != Network.State.Shutdown) && (network.getState() != Network.State.Destroy)) {
throw new CloudRuntimeException("This Controller can not be deleted as there are one or more logical networks provisioned by cloudstack.");
}
}
}
}
}
HostVO host = hostDao.findById(controller.getHostId());
Long hostId = host.getId();
host.setResourceState(ResourceState.Maintenance);
hostDao.update(hostId, host);
resourceManager.deleteHost(hostId, false, false);
openDaylightControllerMappingDao.remove(cmd.getId());
}
use of org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO in project cloudstack by apache.
the class OpenDaylightControllerResourceManagerImpl method listControllers.
@Override
public List<OpenDaylightControllerVO> listControllers(ListOpenDaylightControllersCmd cmd) {
if (cmd.getId() != null) {
List<OpenDaylightControllerVO> foundControllers = new ArrayList<OpenDaylightControllerVO>();
OpenDaylightControllerVO controller = openDaylightControllerMappingDao.findById(cmd.getId());
if (controller != null) {
foundControllers.add(controller);
}
return foundControllers;
} else if (cmd.getPhysicalNetworkId() != null) {
return openDaylightControllerMappingDao.listByPhysicalNetwork(cmd.getPhysicalNetworkId());
}
return openDaylightControllerMappingDao.listAll();
}
Aggregations