Search in sources :

Example 51 with NetworkVO

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;
    }
}
Also used : VirtualNetwork(net.juniper.contrail.api.types.VirtualNetwork) NetworkVO(com.cloud.network.dao.NetworkVO) ApiConnector(net.juniper.contrail.api.ApiConnector) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException) TrafficType(com.cloud.network.Networks.TrafficType)

Example 52 with NetworkVO

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;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DestroyPortCommand(org.apache.cloudstack.network.opendaylight.agent.commands.DestroyPortCommand) DestroyPortAnswer(org.apache.cloudstack.network.opendaylight.agent.responses.DestroyPortAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) OpenDaylightControllerVO(org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO)

Example 53 with NetworkVO

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;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ConfigureNetworkAnswer(org.apache.cloudstack.network.opendaylight.agent.responses.ConfigureNetworkAnswer) ConfigureNetworkCommand(org.apache.cloudstack.network.opendaylight.agent.commands.ConfigureNetworkCommand) OpenDaylightControllerVO(org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO)

Example 54 with NetworkVO

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());
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) OpenDaylightControllerVO(org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO) HostVO(com.cloud.host.HostVO)

Example 55 with NetworkVO

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);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NicProfile(com.cloud.vm.NicProfile) URI(java.net.URI) AccountVO(com.cloud.user.AccountVO) ReservationContext(com.cloud.vm.ReservationContext) DomainVO(com.cloud.domain.DomainVO) Answer(com.cloud.agent.api.Answer) DeployDestination(com.cloud.deploy.DeployDestination) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) NicVO(com.cloud.vm.NicVO) VirtualMachine(com.cloud.vm.VirtualMachine) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Aggregations

NetworkVO (com.cloud.network.dao.NetworkVO)230 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)108 ArrayList (java.util.ArrayList)79 Test (org.junit.Test)56 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)55 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)49 Account (com.cloud.user.Account)44 Network (com.cloud.network.Network)39 DataCenterVO (com.cloud.dc.DataCenterVO)35 DataCenter (com.cloud.dc.DataCenter)34 NicVO (com.cloud.vm.NicVO)33 NicProfile (com.cloud.vm.NicProfile)27 HostVO (com.cloud.host.HostVO)24 NetworkOffering (com.cloud.offering.NetworkOffering)24 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)22 ReservationContext (com.cloud.vm.ReservationContext)22 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)20 DeployDestination (com.cloud.deploy.DeployDestination)19 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)19 NetworkGuru (com.cloud.network.guru.NetworkGuru)19