Search in sources :

Example 26 with NetworkGuru

use of com.cloud.network.guru.NetworkGuru in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method allocateNic.

@DB
@Override
public NicProfile allocateNic(final NicProfile requested, final Network network, final Boolean isDefaultNic, final VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {
    final NetworkVO ntwkVO = _networksDao.findById(network.getId());
    s_logger.debug("Allocating nic for vm " + vm.getVirtualMachine() + " in network " + network + " with requested profile " + requested);
    final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, ntwkVO.getGuruName());
    if (requested != null && requested.getMode() == null) {
        requested.setMode(network.getMode());
    }
    final NicProfile profile = guru.allocate(network, requested, vm);
    if (profile == null) {
        return null;
    }
    if (isDefaultNic != null) {
        profile.setDefaultNic(isDefaultNic);
    }
    if (requested != null && requested.getMode() == null) {
        profile.setMode(requested.getMode());
    } else {
        profile.setMode(network.getMode());
    }
    NicVO vo = new NicVO(guru.getName(), vm.getId(), network.getId(), vm.getType());
    applyProfileToNic(vo, profile);
    vo = _nicDao.persist(vo);
    final Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
    return new NicProfile(vo, network, vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, _networkModel.getNetworkTag(vm.getHypervisorType(), network));
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkGuru(com.cloud.network.guru.NetworkGuru) NicProfile(com.cloud.vm.NicProfile) NicVO(com.cloud.vm.NicVO) DB(com.cloud.utils.db.DB)

Example 27 with NetworkGuru

use of com.cloud.network.guru.NetworkGuru in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method commitNicForMigration.

@Override
public void commitNicForMigration(final VirtualMachineProfile src, final VirtualMachineProfile dst) {
    for (final NicProfile nicSrc : src.getNics()) {
        final NetworkVO network = _networksDao.findById(nicSrc.getNetworkId());
        final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
        final NicProfile nicDst = findNicProfileById(dst, nicSrc.getId());
        final ReservationContext src_context = new ReservationContextImpl(nicSrc.getReservationId(), null, null);
        final ReservationContext dst_context = new ReservationContextImpl(nicDst.getReservationId(), null, null);
        if (guru instanceof NetworkMigrationResponder) {
            ((NetworkMigrationResponder) guru).commitMigration(nicSrc, network, src, src_context, dst_context);
        }
        final List<Provider> providersToImplement = getNetworkProviders(network.getId());
        for (final NetworkElement element : networkElements) {
            if (providersToImplement.contains(element.getProvider())) {
                if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) {
                    throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId());
                }
                if (element instanceof NetworkMigrationResponder) {
                    ((NetworkMigrationResponder) element).commitMigration(nicSrc, network, src, src_context, dst_context);
                }
            }
        }
        // update the reservation id
        final NicVO nicVo = _nicDao.findById(nicDst.getId());
        nicVo.setReservationId(nicDst.getReservationId());
        _nicDao.persist(nicVo);
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkMigrationResponder(com.cloud.network.NetworkMigrationResponder) NetworkElement(com.cloud.network.element.NetworkElement) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetworkGuru(com.cloud.network.guru.NetworkGuru) NicProfile(com.cloud.vm.NicProfile) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) NicVO(com.cloud.vm.NicVO) ReservationContext(com.cloud.vm.ReservationContext) 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)

Example 28 with NetworkGuru

use of com.cloud.network.guru.NetworkGuru in project cloudstack by apache.

the class NetworkOrchestrator method getNicProfiles.

@Override
public List<NicProfile> getNicProfiles(final VirtualMachine vm) {
    final List<NicVO> nics = _nicDao.listByVmId(vm.getId());
    final List<NicProfile> profiles = new ArrayList<NicProfile>();
    if (nics != null) {
        for (final Nic nic : nics) {
            final NetworkVO network = _networksDao.findById(nic.getNetworkId());
            final Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
            final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
            final NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network));
            guru.updateNicProfile(profile, network);
            profiles.add(profile);
        }
    }
    return profiles;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkGuru(com.cloud.network.guru.NetworkGuru) ArrayList(java.util.ArrayList) Nic(com.cloud.vm.Nic) NicProfile(com.cloud.vm.NicProfile) NicVO(com.cloud.vm.NicVO)

Example 29 with NetworkGuru

use of com.cloud.network.guru.NetworkGuru in project cloudstack by apache.

the class NetworkOrchestrator method commitNicForMigration.

@Override
public void commitNicForMigration(final VirtualMachineProfile src, final VirtualMachineProfile dst) {
    for (final NicProfile nicSrc : src.getNics()) {
        final NetworkVO network = _networksDao.findById(nicSrc.getNetworkId());
        final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
        final NicProfile nicDst = findNicProfileById(dst, nicSrc.getId());
        final ReservationContext src_context = new ReservationContextImpl(nicSrc.getReservationId(), null, null);
        final ReservationContext dst_context = new ReservationContextImpl(nicDst.getReservationId(), null, null);
        if (guru instanceof NetworkMigrationResponder) {
            ((NetworkMigrationResponder) guru).commitMigration(nicSrc, network, src, src_context, dst_context);
        }
        if (network.getGuestType() == Network.GuestType.L2 && src.getType() == VirtualMachine.Type.User) {
            _userVmMgr.setupVmForPvlan(true, src.getVirtualMachine().getHostId(), nicSrc);
        }
        final List<Provider> providersToImplement = getNetworkProviders(network.getId());
        for (final NetworkElement element : networkElements) {
            if (providersToImplement.contains(element.getProvider())) {
                if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) {
                    throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId());
                }
                if (element instanceof NetworkMigrationResponder) {
                    ((NetworkMigrationResponder) element).commitMigration(nicSrc, network, src, src_context, dst_context);
                }
            }
        }
        // update the reservation id
        final NicVO nicVo = _nicDao.findById(nicDst.getId());
        nicVo.setReservationId(nicDst.getReservationId());
        _nicDao.persist(nicVo);
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkMigrationResponder(com.cloud.network.NetworkMigrationResponder) NetworkElement(com.cloud.network.element.NetworkElement) ConfigDriveNetworkElement(com.cloud.network.element.ConfigDriveNetworkElement) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetworkGuru(com.cloud.network.guru.NetworkGuru) NicProfile(com.cloud.vm.NicProfile) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) NicVO(com.cloud.vm.NicVO) ReservationContext(com.cloud.vm.ReservationContext) DnsServiceProvider(com.cloud.network.element.DnsServiceProvider) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.network.Network.Provider)

Example 30 with NetworkGuru

use of com.cloud.network.guru.NetworkGuru in project cloudstack by apache.

the class NetworkOrchestrator method removeNic.

protected void removeNic(final VirtualMachineProfile vm, final NicVO nic) {
    if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start && nic.getState() != Nic.State.Allocated) {
        // Ensure that release is performed before Nic is to be removed to avoid resource leaks.
        try {
            releaseNic(vm, nic.getId());
        } catch (final Exception ex) {
            s_logger.warn("Failed to release nic: " + nic.toString() + " as part of remove operation due to", ex);
        }
    }
    final NetworkVO network = _networksDao.findById(nic.getNetworkId());
    if (network != null && network.getTrafficType() == TrafficType.Guest) {
        final String nicIp = StringUtils.isEmpty(nic.getIPv4Address()) ? nic.getIPv6Address() : nic.getIPv4Address();
        if (StringUtils.isNotEmpty(nicIp)) {
            NicProfile nicProfile = new NicProfile(nic.getIPv4Address(), nic.getIPv6Address(), nic.getMacAddress());
            nicProfile.setId(nic.getId());
            cleanupNicDhcpDnsEntry(network, vm, nicProfile);
        }
    }
    Boolean preserveNics = (Boolean) vm.getParameter(VirtualMachineProfile.Param.PreserveNics);
    if (BooleanUtils.isNotTrue(preserveNics)) {
        nic.setState(Nic.State.Deallocating);
        _nicDao.update(nic.getId(), nic);
    }
    final NicProfile profile = new NicProfile(nic, network, null, null, null, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network));
    /*
         * We need to release the nics with a Create ReservationStrategy here
         * because the nic is now being removed.
         */
    if (nic.getReservationStrategy() == Nic.ReservationStrategy.Create) {
        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 " + nic);
                }
                try {
                    element.release(network, profile, vm, null);
                } catch (final ConcurrentOperationException ex) {
                    s_logger.warn("release failed during the nic " + nic.toString() + " removeNic due to ", ex);
                } catch (final ResourceUnavailableException ex) {
                    s_logger.warn("release failed during the nic " + nic.toString() + " removeNic due to ", ex);
                }
            }
        }
    }
    if (vm.getType() == Type.User && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == GuestType.Shared && isLastNicInSubnet(nic)) {
        if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp)) {
            // remove the dhcpservice ip if this is the last nic in subnet.
            final DhcpServiceProvider dhcpServiceProvider = getDhcpServiceProvider(network);
            if (dhcpServiceProvider != null && isDhcpAccrossMultipleSubnetsSupported(dhcpServiceProvider)) {
                removeDhcpServiceInSubnet(nic);
            }
        }
        if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dns)) {
            final DnsServiceProvider dnsServiceProvider = getDnsServiceProvider(network);
            if (dnsServiceProvider != null) {
                try {
                    if (!dnsServiceProvider.removeDnsSupportForSubnet(network)) {
                        s_logger.warn("Failed to remove the ip alias on the dns server");
                    }
                } catch (final ResourceUnavailableException e) {
                    // failed to remove the dnsconfig.
                    s_logger.info("Unable to delete the ip alias due to unable to contact the dns server.");
                }
            }
        }
    }
    final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
    guru.deallocate(network, profile, vm);
    if (BooleanUtils.isNotTrue(preserveNics)) {
        _nicDao.remove(nic.getId());
    }
    s_logger.debug("Removed nic id=" + nic.getId());
    // remove the secondary ip addresses corresponding to to this nic
    if (!removeVmSecondaryIpsOfNic(nic.getId())) {
        s_logger.debug("Removing nic " + nic.getId() + " secondary ip addreses failed");
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkGuru(com.cloud.network.guru.NetworkGuru) DnsServiceProvider(com.cloud.network.element.DnsServiceProvider) NicProfile(com.cloud.vm.NicProfile) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConnectionException(com.cloud.exception.ConnectionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) ConfigurationException(javax.naming.ConfigurationException) DnsServiceProvider(com.cloud.network.element.DnsServiceProvider) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.network.Network.Provider) NetworkElement(com.cloud.network.element.NetworkElement) ConfigDriveNetworkElement(com.cloud.network.element.ConfigDriveNetworkElement) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Aggregations

NetworkGuru (com.cloud.network.guru.NetworkGuru)44 NetworkVO (com.cloud.network.dao.NetworkVO)39 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)37 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)24 NicProfile (com.cloud.vm.NicProfile)23 NicVO (com.cloud.vm.NicVO)19 DhcpServiceProvider (com.cloud.network.element.DhcpServiceProvider)18 Provider (com.cloud.network.Network.Provider)16 LoadBalancingServiceProvider (com.cloud.network.element.LoadBalancingServiceProvider)16 NetworkElement (com.cloud.network.element.NetworkElement)16 StaticNatServiceProvider (com.cloud.network.element.StaticNatServiceProvider)16 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)16 DB (com.cloud.utils.db.DB)14 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)11 ArrayList (java.util.ArrayList)11 Network (com.cloud.network.Network)10 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)10 NetworkMigrationResponder (com.cloud.network.NetworkMigrationResponder)9 Pair (com.cloud.utils.Pair)9 TransactionStatus (com.cloud.utils.db.TransactionStatus)9