Search in sources :

Example 1 with NetworkMigrationResponder

use of com.cloud.network.NetworkMigrationResponder in project cloudstack by apache.

the class NetworkOrchestrator method prepareNicForMigration.

@Override
public void prepareNicForMigration(final VirtualMachineProfile vm, final DeployDestination dest) {
    if (vm.getType().equals(VirtualMachine.Type.DomainRouter) && (vm.getHypervisorType().equals(HypervisorType.KVM) || vm.getHypervisorType().equals(HypervisorType.VMware))) {
        //Include nics hot plugged and not stored in DB
        prepareAllNicsForMigration(vm, dest);
        return;
    }
    final List<NicVO> nics = _nicDao.listByVmId(vm.getId());
    final ReservationContext context = new ReservationContextImpl(UUID.randomUUID().toString(), null, null);
    for (final NicVO 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));
        if (guru instanceof NetworkMigrationResponder) {
            if (!((NetworkMigrationResponder) guru).prepareMigration(profile, network, vm, dest, context)) {
                // XXX: Transaction error
                s_logger.error("NetworkGuru " + guru + " prepareForMigration failed.");
            }
        }
        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) {
                    if (!((NetworkMigrationResponder) element).prepareMigration(profile, network, vm, dest, context)) {
                        // XXX: Transaction error
                        s_logger.error("NetworkElement " + element + " prepareForMigration failed.");
                    }
                }
            }
        }
        guru.updateNicProfile(profile, network);
        vm.addNic(profile);
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkMigrationResponder(com.cloud.network.NetworkMigrationResponder) NetworkGuru(com.cloud.network.guru.NetworkGuru) NicProfile(com.cloud.vm.NicProfile) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) 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) NetworkElement(com.cloud.network.element.NetworkElement) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NicVO(com.cloud.vm.NicVO)

Example 2 with NetworkMigrationResponder

use of com.cloud.network.NetworkMigrationResponder in project cloudstack by apache.

the class NetworkOrchestrator method rollbackNicForMigration.

@Override
public void rollbackNicForMigration(final VirtualMachineProfile src, final VirtualMachineProfile dst) {
    for (final NicProfile nicDst : dst.getNics()) {
        final NetworkVO network = _networksDao.findById(nicDst.getNetworkId());
        final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
        final NicProfile nicSrc = findNicProfileById(src, nicDst.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).rollbackMigration(nicDst, network, dst, 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).rollbackMigration(nicDst, network, dst, src_context, dst_context);
                }
            }
        }
    }
}
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) 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 3 with NetworkMigrationResponder

use of com.cloud.network.NetworkMigrationResponder 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);
        }
        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) 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 4 with NetworkMigrationResponder

use of com.cloud.network.NetworkMigrationResponder in project cloudstack by apache.

the class NetworkOrchestrator method prepareAllNicsForMigration.

/*
    Prepare All Nics for migration including the nics dynamically created and not stored in DB
    This is a temporary workaround work KVM migration
    Once clean fix is added by stored dynamically nics is DB, this workaround won't be needed
     */
@Override
public void prepareAllNicsForMigration(final VirtualMachineProfile vm, final DeployDestination dest) {
    final List<NicVO> nics = _nicDao.listByVmId(vm.getId());
    final ReservationContext context = new ReservationContextImpl(UUID.randomUUID().toString(), null, null);
    Long guestNetworkId = null;
    for (final NicVO nic : nics) {
        final NetworkVO network = _networksDao.findById(nic.getNetworkId());
        if (network.getTrafficType().equals(TrafficType.Guest) && network.getGuestType().equals(GuestType.Isolated)) {
            guestNetworkId = network.getId();
        }
        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));
        if (guru instanceof NetworkMigrationResponder) {
            if (!((NetworkMigrationResponder) guru).prepareMigration(profile, network, vm, dest, context)) {
                // XXX: Transaction error
                s_logger.error("NetworkGuru " + guru + " prepareForMigration failed.");
            }
        }
        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) {
                    if (!((NetworkMigrationResponder) element).prepareMigration(profile, network, vm, dest, context)) {
                        // XXX: Transaction error
                        s_logger.error("NetworkElement " + element + " prepareForMigration failed.");
                    }
                }
            }
        }
        guru.updateNicProfile(profile, network);
        vm.addNic(profile);
    }
    final List<String> addedURIs = new ArrayList<String>();
    if (guestNetworkId != null) {
        final List<IPAddressVO> publicIps = _ipAddressDao.listByAssociatedNetwork(guestNetworkId, null);
        for (final IPAddressVO userIp : publicIps) {
            final PublicIp publicIp = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
            final URI broadcastUri = BroadcastDomainType.Vlan.toUri(publicIp.getVlanTag());
            final long ntwkId = publicIp.getNetworkId();
            final Nic nic = _nicDao.findByNetworkIdInstanceIdAndBroadcastUri(ntwkId, vm.getId(), broadcastUri.toString());
            if (nic == null && !addedURIs.contains(broadcastUri.toString())) {
                //Nic details are not available in DB
                //Create nic profile for migration
                s_logger.debug("Creating nic profile for migration. BroadcastUri: " + broadcastUri.toString() + " NetworkId: " + ntwkId + " Vm: " + vm.getId());
                final NetworkVO network = _networksDao.findById(ntwkId);
                _networkModel.getNetworkRate(network.getId(), vm.getId());
                final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
                final NicProfile profile = new NicProfile();
                //dummyId
                profile.setDeviceId(255);
                profile.setIPv4Address(userIp.getAddress().toString());
                profile.setIPv4Netmask(publicIp.getNetmask());
                profile.setIPv4Gateway(publicIp.getGateway());
                profile.setMacAddress(publicIp.getMacAddress());
                profile.setBroadcastType(network.getBroadcastDomainType());
                profile.setTrafficType(network.getTrafficType());
                profile.setBroadcastUri(broadcastUri);
                profile.setIsolationUri(Networks.IsolationType.Vlan.toUri(publicIp.getVlanTag()));
                profile.setSecurityGroupEnabled(_networkModel.isSecurityGroupSupportedInNetwork(network));
                profile.setName(_networkModel.getNetworkTag(vm.getHypervisorType(), network));
                profile.setNetworId(network.getId());
                guru.updateNicProfile(profile, network);
                vm.addNic(profile);
                addedURIs.add(broadcastUri.toString());
            }
        }
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkMigrationResponder(com.cloud.network.NetworkMigrationResponder) PublicIp(com.cloud.network.addr.PublicIp) NetworkGuru(com.cloud.network.guru.NetworkGuru) ArrayList(java.util.ArrayList) Nic(com.cloud.vm.Nic) NicProfile(com.cloud.vm.NicProfile) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) URI(java.net.URI) 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) NetworkElement(com.cloud.network.element.NetworkElement) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IPAddressVO(com.cloud.network.dao.IPAddressVO) NicVO(com.cloud.vm.NicVO)

Aggregations

Provider (com.cloud.network.Network.Provider)4 NetworkMigrationResponder (com.cloud.network.NetworkMigrationResponder)4 NetworkVO (com.cloud.network.dao.NetworkVO)4 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)4 DhcpServiceProvider (com.cloud.network.element.DhcpServiceProvider)4 DnsServiceProvider (com.cloud.network.element.DnsServiceProvider)4 LoadBalancingServiceProvider (com.cloud.network.element.LoadBalancingServiceProvider)4 NetworkElement (com.cloud.network.element.NetworkElement)4 StaticNatServiceProvider (com.cloud.network.element.StaticNatServiceProvider)4 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)4 NetworkGuru (com.cloud.network.guru.NetworkGuru)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 NicProfile (com.cloud.vm.NicProfile)4 ReservationContext (com.cloud.vm.ReservationContext)4 ReservationContextImpl (com.cloud.vm.ReservationContextImpl)4 NicVO (com.cloud.vm.NicVO)3 PublicIp (com.cloud.network.addr.PublicIp)1 IPAddressVO (com.cloud.network.dao.IPAddressVO)1 Nic (com.cloud.vm.Nic)1 URI (java.net.URI)1