Search in sources :

Example 1 with DnsServiceProvider

use of com.cloud.network.element.DnsServiceProvider in project cloudstack by apache.

the class NetworkOrchestrator method prepareElement.

protected boolean prepareElement(final NetworkElement element, final Network network, final NicProfile profile, final VirtualMachineProfile vmProfile, final DeployDestination dest, final ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
    element.prepare(network, profile, vmProfile, dest, context);
    if (vmProfile.getType() == Type.User && element.getProvider() != null) {
        if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp) && _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, element.getProvider()) && element instanceof DhcpServiceProvider) {
            final DhcpServiceProvider sp = (DhcpServiceProvider) element;
            final Map<Capability, String> dhcpCapabilities = element.getCapabilities().get(Service.Dhcp);
            final String supportsMultipleSubnets = dhcpCapabilities.get(Capability.DhcpAccrossMultipleSubnets);
            if (supportsMultipleSubnets != null && Boolean.valueOf(supportsMultipleSubnets) && profile.getIPv6Address() == null) {
                if (!sp.configDhcpSupportForSubnet(network, profile, vmProfile, dest, context)) {
                    return false;
                }
            }
            if (!sp.addDhcpEntry(network, profile, vmProfile, dest, context)) {
                return false;
            }
        }
        if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dns) && _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dns, element.getProvider()) && element instanceof DnsServiceProvider) {
            final DnsServiceProvider sp = (DnsServiceProvider) element;
            if (profile.getIPv6Address() == null) {
                if (!sp.configDnsSupportForSubnet(network, profile, vmProfile, dest, context)) {
                    return false;
                }
            }
            if (!sp.addDnsEntry(network, profile, vmProfile, dest, context)) {
                return false;
            }
        }
        if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.UserData) && _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.UserData, element.getProvider()) && element instanceof UserDataServiceProvider) {
            final UserDataServiceProvider sp = (UserDataServiceProvider) element;
            if (!sp.addPasswordAndUserdata(network, profile, vmProfile, dest, context)) {
                return false;
            }
        }
    }
    return true;
}
Also used : Capability(com.cloud.network.Network.Capability) DnsServiceProvider(com.cloud.network.element.DnsServiceProvider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider)

Example 2 with DnsServiceProvider

use of com.cloud.network.element.DnsServiceProvider 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

DhcpServiceProvider (com.cloud.network.element.DhcpServiceProvider)2 DnsServiceProvider (com.cloud.network.element.DnsServiceProvider)2 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)2 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 ConnectionException (com.cloud.exception.ConnectionException)1 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)1 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 UnsupportedServiceException (com.cloud.exception.UnsupportedServiceException)1 Capability (com.cloud.network.Network.Capability)1 Provider (com.cloud.network.Network.Provider)1 NetworkVO (com.cloud.network.dao.NetworkVO)1 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)1 ConfigDriveNetworkElement (com.cloud.network.element.ConfigDriveNetworkElement)1 LoadBalancingServiceProvider (com.cloud.network.element.LoadBalancingServiceProvider)1