Search in sources :

Example 16 with NetworkGuru

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

the class NetworkOrchestrator method prepareNic.

@Override
public NicProfile prepareNic(final VirtualMachineProfile vmProfile, final DeployDestination dest, final ReservationContext context, final long nicId, final Network network) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
    final Integer networkRate = _networkModel.getNetworkRate(network.getId(), vmProfile.getId());
    final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
    final NicVO nic = _nicDao.findById(nicId);
    NicProfile profile = null;
    if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
        nic.setState(Nic.State.Reserving);
        nic.setReservationId(context.getReservationId());
        _nicDao.update(nic.getId(), nic);
        URI broadcastUri = nic.getBroadcastUri();
        if (broadcastUri == null) {
            broadcastUri = network.getBroadcastUri();
        }
        final URI isolationUri = nic.getIsolationUri();
        profile = new NicProfile(nic, network, broadcastUri, isolationUri, networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network));
        guru.reserve(profile, network, vmProfile, dest, context);
        nic.setIPv4Address(profile.getIPv4Address());
        nic.setAddressFormat(profile.getFormat());
        nic.setIPv6Address(profile.getIPv6Address());
        nic.setIPv6Cidr(profile.getIPv6Cidr());
        nic.setIPv6Gateway(profile.getIPv6Gateway());
        nic.setMacAddress(profile.getMacAddress());
        nic.setIsolationUri(profile.getIsolationUri());
        nic.setBroadcastUri(profile.getBroadCastUri());
        nic.setReserver(guru.getName());
        nic.setState(Nic.State.Reserved);
        nic.setIPv4Netmask(profile.getIPv4Netmask());
        nic.setIPv4Gateway(profile.getIPv4Gateway());
        if (profile.getReservationStrategy() != null) {
            nic.setReservationStrategy(profile.getReservationStrategy());
        }
        updateNic(nic, network.getId(), 1);
    } else {
        profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network));
        guru.updateNicProfile(profile, network);
        nic.setState(Nic.State.Reserved);
        updateNic(nic, network.getId(), 1);
    }
    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 (s_logger.isDebugEnabled()) {
                s_logger.debug("Asking " + element.getName() + " to prepare for " + nic);
            }
            if (!prepareElement(element, network, profile, vmProfile, dest, context)) {
                throw new InsufficientAddressCapacityException("unable to configure the dhcp service, due to insufficiant address capacity", Network.class, network.getId());
            }
        }
    }
    profile.setSecurityGroupEnabled(_networkModel.isSecurityGroupSupportedInNetwork(network));
    guru.updateNicProfile(profile, network);
    return profile;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetworkGuru(com.cloud.network.guru.NetworkGuru) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) NicProfile(com.cloud.vm.NicProfile) NicVO(com.cloud.vm.NicVO) URI(java.net.URI) 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 17 with NetworkGuru

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

the class NetworkOrchestrator method startNetwork.

@Override
public boolean startNetwork(final long networkId, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    // Check if network exists
    final NetworkVO network = _networksDao.findById(networkId);
    if (network == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Network with specified id doesn't exist");
        ex.addProxyObject(String.valueOf(networkId), "networkId");
        throw ex;
    }
    // implement the network
    s_logger.debug("Starting network " + network + "...");
    final Pair<NetworkGuru, NetworkVO> implementedNetwork = implementNetwork(networkId, dest, context);
    if (implementedNetwork == null || implementedNetwork.first() == null) {
        s_logger.warn("Failed to start the network " + network);
        return false;
    } else {
        return true;
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NetworkGuru(com.cloud.network.guru.NetworkGuru)

Example 18 with NetworkGuru

use of com.cloud.network.guru.NetworkGuru 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 19 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);
        }
    }
    nic.setState(Nic.State.Deallocating);
    _nicDao.update(nic.getId(), nic);
    final NetworkVO network = _networksDao.findById(nic.getNetworkId());
    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);
    _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) NetworkElement(com.cloud.network.element.NetworkElement) NetworkGuru(com.cloud.network.guru.NetworkGuru) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) 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) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) 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)

Example 20 with NetworkGuru

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

the class NetworkOrchestrator method implementNetwork.

Pair<NetworkGuru, NetworkVO> implementNetwork(final long networkId, final DeployDestination dest, final ReservationContext context, final boolean isRouter) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    Pair<NetworkGuru, NetworkVO> implemented = null;
    if (!isRouter) {
        implemented = implementNetwork(networkId, dest, context);
    } else {
        // At the time of implementing network (using implementNetwork() method), if the VR needs to be deployed then
        // it follows the same path of regular VM deployment. This leads to a nested call to implementNetwork() while
        // preparing VR nics. This flow creates issues in dealing with network state transitions. The original call
        // puts network in "Implementing" state and then the nested call again tries to put it into same state resulting
        // in issues. In order to avoid it, implementNetwork() call for VR is replaced with below code.
        final NetworkVO network = _networksDao.findById(networkId);
        final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
        implemented = new Pair<NetworkGuru, NetworkVO>(guru, network);
    }
    return implemented;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkGuru(com.cloud.network.guru.NetworkGuru)

Aggregations

NetworkGuru (com.cloud.network.guru.NetworkGuru)22 NetworkVO (com.cloud.network.dao.NetworkVO)19 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)18 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)12 NicProfile (com.cloud.vm.NicProfile)11 DhcpServiceProvider (com.cloud.network.element.DhcpServiceProvider)9 NicVO (com.cloud.vm.NicVO)9 Provider (com.cloud.network.Network.Provider)8 DnsServiceProvider (com.cloud.network.element.DnsServiceProvider)8 LoadBalancingServiceProvider (com.cloud.network.element.LoadBalancingServiceProvider)8 NetworkElement (com.cloud.network.element.NetworkElement)8 StaticNatServiceProvider (com.cloud.network.element.StaticNatServiceProvider)8 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)8 DB (com.cloud.utils.db.DB)7 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)6 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)6 Pair (com.cloud.utils.Pair)6 ArrayList (java.util.ArrayList)6 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)5 Network (com.cloud.network.Network)5