use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class ServerDBSyncImpl method syncVirtualNetwork.
/*
* Virtual Network Synchronization methods
*/
@SuppressWarnings({ "unchecked" })
public boolean syncVirtualNetwork() throws Exception {
final ApiConnector api = _manager.getApiConnector();
try {
List<TrafficType> types = new ArrayList<TrafficType>();
types.add(TrafficType.Public);
types.add(TrafficType.Guest);
List<NetworkVO> dbNets = _manager.findManagedNetworks(types);
List<VirtualNetwork> vList = (List<VirtualNetwork>) api.list(VirtualNetwork.class, null);
List<VirtualNetwork> vncList = new ArrayList<VirtualNetwork>();
for (VirtualNetwork vn : vList) {
if (!_manager.isSystemDefaultNetwork(vn)) {
vncList.add(vn);
}
}
s_logger.debug("sync VN - DB size: " + dbNets.size() + " VNC Size: " + vncList.size());
return _dbSync.syncGeneric(VirtualNetwork.class, dbNets, vncList);
} catch (Exception ex) {
s_logger.warn("sync virtual-networks", ex);
throw ex;
}
}
use of com.cloud.network.dao.NetworkVO 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 com.cloud.network.dao.NetworkVO 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 com.cloud.network.dao.NetworkVO 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 com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class NuageVspGuestNetworkGuruTest method testReserve.
@Test
public void testReserve() throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, URISyntaxException {
final NetworkVO network = mock(NetworkVO.class);
when(network.getId()).thenReturn(NETWORK_ID);
when(network.getUuid()).thenReturn("aaaaaa");
when(network.getDataCenterId()).thenReturn(NETWORK_ID);
when(network.getNetworkOfferingId()).thenReturn(NETWORK_ID);
when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
when(network.getDomainId()).thenReturn(NETWORK_ID);
when(network.getAccountId()).thenReturn(NETWORK_ID);
when(network.getVpcId()).thenReturn(null);
when(network.getBroadcastUri()).thenReturn(new URI("vsp://aaaaaa-aavvv/10.1.1.1"));
final DataCenterVO dataCenter = mock(DataCenterVO.class);
when(_dataCenterDao.findById(NETWORK_ID)).thenReturn(dataCenter);
final AccountVO networksAccount = mock(AccountVO.class);
when(networksAccount.getId()).thenReturn(NETWORK_ID);
when(networksAccount.getUuid()).thenReturn("aaaa-abbbb");
when(networksAccount.getType()).thenReturn(Account.ACCOUNT_TYPE_NORMAL);
when(_accountDao.findById(NETWORK_ID)).thenReturn(networksAccount);
final DomainVO networksDomain = mock(DomainVO.class);
when(networksDomain.getId()).thenReturn(NETWORK_ID);
when(networksDomain.getUuid()).thenReturn("aaaaa-bbbbb");
when(_domainDao.findById(NETWORK_ID)).thenReturn(networksDomain);
final NicVO nicvo = mock(NicVO.class);
when(nicvo.getId()).thenReturn(NETWORK_ID);
when(nicvo.getMacAddress()).thenReturn("aa-aa-aa-aa-aa-aa");
when(nicvo.getUuid()).thenReturn("aaaa-fffff");
when(nicvo.getNetworkId()).thenReturn(NETWORK_ID);
when(nicvo.getInstanceId()).thenReturn(NETWORK_ID);
when(_nicDao.findById(NETWORK_ID)).thenReturn(nicvo);
when(_nicDao.findDefaultNicForVM(NETWORK_ID)).thenReturn(nicvo);
final VirtualMachine vm = mock(VirtualMachine.class);
when(vm.getId()).thenReturn(NETWORK_ID);
when(vm.getType()).thenReturn(VirtualMachine.Type.User);
final VirtualMachineProfile vmProfile = mock(VirtualMachineProfile.class);
when(vmProfile.getType()).thenReturn(VirtualMachine.Type.User);
when(vmProfile.getInstanceName()).thenReturn("");
when(vmProfile.getUuid()).thenReturn("aaaa-bbbbb");
when(vmProfile.getVirtualMachine()).thenReturn(vm);
NicProfile nicProfile = mock(NicProfile.class);
when(nicProfile.getUuid()).thenReturn("aaa-bbbb");
when(nicProfile.getId()).thenReturn(NETWORK_ID);
when(nicProfile.getMacAddress()).thenReturn("aa-aa-aa-aa-aa-aa");
final NetworkOfferingVO ntwkoffering = mock(NetworkOfferingVO.class);
when(ntwkoffering.getId()).thenReturn(NETWORK_ID);
when(_networkOfferingDao.findById(NETWORK_ID)).thenReturn(ntwkoffering);
when(_networkDao.acquireInLockTable(NETWORK_ID, 1200)).thenReturn(network);
when(_ipAddressDao.findByVmIdAndNetworkId(NETWORK_ID, NETWORK_ID)).thenReturn(null);
when(_domainDao.findById(NETWORK_ID)).thenReturn(mock(DomainVO.class));
final Answer answer = mock(Answer.class);
when(answer.getResult()).thenReturn(true);
when(_agentManager.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
final ReservationContext reservationContext = mock(ReservationContext.class);
when(reservationContext.getAccount()).thenReturn(networksAccount);
when(reservationContext.getDomain()).thenReturn(networksDomain);
_nuageVspGuestNetworkGuru.reserve(nicProfile, network, vmProfile, mock(DeployDestination.class), reservationContext);
}
Aggregations