Search in sources :

Example 1 with VMNetworkMapVO

use of com.cloud.engine.cloud.entity.api.db.VMNetworkMapVO in project cosmic by MissionCriticalCloud.

the class VMNetworkMapDaoImpl method getNetworks.

@Override
public List<Long> getNetworks(final long vmId) {
    final SearchCriteria<VMNetworkMapVO> sc = VmIdSearch.create();
    sc.setParameters("vmId", vmId);
    final List<VMNetworkMapVO> results = search(sc, null);
    final List<Long> networks = new ArrayList<>(results.size());
    for (final VMNetworkMapVO result : results) {
        networks.add(result.getNetworkId());
    }
    return networks;
}
Also used : VMNetworkMapVO(com.cloud.engine.cloud.entity.api.db.VMNetworkMapVO) ArrayList(java.util.ArrayList)

Example 2 with VMNetworkMapVO

use of com.cloud.engine.cloud.entity.api.db.VMNetworkMapVO in project cosmic by MissionCriticalCloud.

the class VMNetworkMapDaoImpl method findByVmAndNetworkId.

@Override
public VMNetworkMapVO findByVmAndNetworkId(final long vmId, final long networkId) {
    final SearchCriteria<VMNetworkMapVO> sc = VmNetworkSearch.create();
    sc.setParameters("vmId", vmId);
    sc.setParameters("networkId", networkId);
    final VMNetworkMapVO network = findOneBy(sc);
    return network;
}
Also used : VMNetworkMapVO(com.cloud.engine.cloud.entity.api.db.VMNetworkMapVO)

Example 3 with VMNetworkMapVO

use of com.cloud.engine.cloud.entity.api.db.VMNetworkMapVO in project cosmic by MissionCriticalCloud.

the class VMNetworkMapDaoImpl method persist.

@Override
public void persist(final long vmId, final List<Long> networks) {
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    final SearchCriteria<VMNetworkMapVO> sc = VmIdSearch.create();
    sc.setParameters("vmId", vmId);
    expunge(sc);
    for (final Long networkId : networks) {
        final VMNetworkMapVO vo = new VMNetworkMapVO(vmId, networkId);
        persist(vo);
    }
    txn.commit();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) VMNetworkMapVO(com.cloud.engine.cloud.entity.api.db.VMNetworkMapVO)

Example 4 with VMNetworkMapVO

use of com.cloud.engine.cloud.entity.api.db.VMNetworkMapVO in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method createNicForVm.

@Override
public NicProfile createNicForVm(final Network network, final NicProfile requested, final ReservationContext context, final VirtualMachineProfile vmProfile, final boolean prepare) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
    final VirtualMachine vm = vmProfile.getVirtualMachine();
    final Zone zone = _zoneRepository.findOne(network.getDataCenterId());
    final Host host = _hostDao.findById(vm.getHostId());
    final DeployDestination dest = new DeployDestination(zone, null, null, host);
    NicProfile nic = getNicProfileForVm(network, requested, vm);
    // 1) allocate nic (if needed) Always allocate if it is a user vm
    if (nic == null || vmProfile.getType() == VirtualMachine.Type.User) {
        nic = allocateNic(requested, network, false, vmProfile);
        if (nic == null) {
            throw new CloudRuntimeException("Failed to allocate nic for vm " + vm + " in network " + network);
        }
        // Update vm_network_map table
        if (vmProfile.getType() == VirtualMachine.Type.User) {
            final VMNetworkMapVO vno = new VMNetworkMapVO(vm.getId(), network.getId());
            _vmNetworkMapDao.persist(vno);
        }
        s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network);
    }
    // 2) prepare nic
    if (prepare) {
        final Pair<NetworkGuru, NetworkVO> implemented = implementNetwork(nic.getNetworkId(), dest, context, vmProfile.getVirtualMachine().getType() == Type.DomainRouter);
        if (implemented == null || implemented.first() == null) {
            s_logger.warn("Failed to implement network id=" + nic.getNetworkId() + " as a part of preparing nic id=" + nic.getId());
            throw new CloudRuntimeException("Failed to implement network id=" + nic.getNetworkId() + " as a part preparing nic id=" + nic.getId());
        }
        nic = prepareNic(vmProfile, dest, context, nic.getId(), implemented.second());
        s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network);
    }
    return nic;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) Zone(com.cloud.db.model.Zone) DeployDestination(com.cloud.deploy.DeployDestination) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetworkGuru(com.cloud.network.guru.NetworkGuru) VMNetworkMapVO(com.cloud.engine.cloud.entity.api.db.VMNetworkMapVO) Host(com.cloud.host.Host) NicProfile(com.cloud.vm.NicProfile) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 5 with VMNetworkMapVO

use of com.cloud.engine.cloud.entity.api.db.VMNetworkMapVO in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method releaseNic.

@DB
protected void releaseNic(final VirtualMachineProfile vmProfile, final long nicId) throws ConcurrentOperationException, ResourceUnavailableException {
    final Pair<Network, NicProfile> networkToRelease = Transaction.execute(new TransactionCallback<Pair<Network, NicProfile>>() {

        @Override
        public Pair<Network, NicProfile> doInTransaction(final TransactionStatus status) {
            final NicVO nic = _nicDao.lockRow(nicId, true);
            if (nic == null) {
                throw new ConcurrentOperationException("Unable to acquire lock on nic " + nic);
            }
            final Nic.State originalState = nic.getState();
            final NetworkVO network = _networksDao.findById(nic.getNetworkId());
            if (originalState == Nic.State.Reserved || originalState == Nic.State.Reserving) {
                if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
                    final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
                    nic.setState(Nic.State.Releasing);
                    _nicDao.update(nic.getId(), nic);
                    final NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network));
                    if (guru.release(profile, vmProfile, nic.getReservationId())) {
                        applyProfileToNicForRelease(nic, profile);
                        nic.setState(Nic.State.Allocated);
                        if (originalState == Nic.State.Reserved) {
                            updateNic(nic, network.getId(), -1);
                        } else {
                            _nicDao.update(nic.getId(), nic);
                        }
                    }
                    // Perform release on network elements
                    return new Pair<>(network, profile);
                } else {
                    nic.setState(Nic.State.Allocated);
                    updateNic(nic, network.getId(), -1);
                }
            }
            return null;
        }
    });
    // cleanup the entry in vm_network_map
    if (vmProfile.getType().equals(VirtualMachine.Type.User)) {
        final NicVO nic = _nicDao.findById(nicId);
        if (nic != null) {
            final NetworkVO vmNetwork = _networksDao.findById(nic.getNetworkId());
            final VMNetworkMapVO vno = _vmNetworkMapDao.findByVmAndNetworkId(vmProfile.getVirtualMachine().getId(), vmNetwork.getId());
            if (vno != null) {
                _vmNetworkMapDao.remove(vno.getId());
            }
        }
    }
    if (networkToRelease != null) {
        final Network network = networkToRelease.first();
        final NicProfile profile = networkToRelease.second();
        final List<Provider> providersToImplement = getNetworkProviders(network.getId());
        for (final NetworkElement element : networkElements) {
            if (providersToImplement.contains(element.getProvider())) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Asking " + element.getName() + " to release " + profile);
                }
                // NOTE: Context appear to never be used in release method
                // implementations. Consider removing it from interface Element
                element.release(network, profile, vmProfile, null);
            }
        }
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkGuru(com.cloud.network.guru.NetworkGuru) TransactionStatus(com.cloud.utils.db.TransactionStatus) NicProfile(com.cloud.vm.NicProfile) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) Provider(com.cloud.network.Network.Provider) NetworkElement(com.cloud.network.element.NetworkElement) RedundantState(com.cloud.network.router.VirtualRouter.RedundantState) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) VMNetworkMapVO(com.cloud.engine.cloud.entity.api.db.VMNetworkMapVO) NicVO(com.cloud.vm.NicVO) Pair(com.cloud.utils.Pair) DB(com.cloud.utils.db.DB)

Aggregations

VMNetworkMapVO (com.cloud.engine.cloud.entity.api.db.VMNetworkMapVO)5 NetworkVO (com.cloud.network.dao.NetworkVO)2 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)2 NetworkGuru (com.cloud.network.guru.NetworkGuru)2 NicProfile (com.cloud.vm.NicProfile)2 Zone (com.cloud.db.model.Zone)1 DeployDestination (com.cloud.deploy.DeployDestination)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 Host (com.cloud.host.Host)1 Network (com.cloud.network.Network)1 Provider (com.cloud.network.Network.Provider)1 PhysicalNetwork (com.cloud.network.PhysicalNetwork)1 DhcpServiceProvider (com.cloud.network.element.DhcpServiceProvider)1 LoadBalancingServiceProvider (com.cloud.network.element.LoadBalancingServiceProvider)1 NetworkElement (com.cloud.network.element.NetworkElement)1 StaticNatServiceProvider (com.cloud.network.element.StaticNatServiceProvider)1 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)1 RedundantState (com.cloud.network.router.VirtualRouter.RedundantState)1 Pair (com.cloud.utils.Pair)1 DB (com.cloud.utils.db.DB)1