use of com.cloud.network.element.DhcpServiceProvider in project cloudstack by apache.
the class NetworkOrchestratorTest method setUp.
@Override
@Before
public void setUp() {
// make class-scope mocks
testOrchastrator._nicDao = mock(NicDao.class);
testOrchastrator._networksDao = mock(NetworkDao.class);
testOrchastrator._networkModel = mock(NetworkModel.class);
testOrchastrator._nicSecondaryIpDao = mock(NicSecondaryIpDao.class);
testOrchastrator._ntwkSrvcDao = mock(NetworkServiceMapDao.class);
testOrchastrator._nicIpAliasDao = mock(NicIpAliasDao.class);
DhcpServiceProvider provider = mock(DhcpServiceProvider.class);
Map<Network.Capability, String> capabilities = new HashMap<Network.Capability, String>();
Map<Network.Service, Map<Network.Capability, String>> services = new HashMap<Network.Service, Map<Network.Capability, String>>();
services.put(Network.Service.Dhcp, capabilities);
when(provider.getCapabilities()).thenReturn(services);
capabilities.put(Network.Capability.DhcpAccrossMultipleSubnets, "true");
when(testOrchastrator._ntwkSrvcDao.getProviderForServiceInNetwork(Matchers.anyLong(), Matchers.eq(Service.Dhcp))).thenReturn(dhcpProvider);
when(testOrchastrator._networkModel.getElementImplementingProvider(dhcpProvider)).thenReturn(provider);
when(guru.getName()).thenReturn(guruName);
List<NetworkGuru> networkGurus = new ArrayList<NetworkGuru>();
networkGurus.add(guru);
testOrchastrator.networkGurus = networkGurus;
}
use of com.cloud.network.element.DhcpServiceProvider in project cloudstack by apache.
the class NetworkOrchestrator method removeDhcpServiceInSubnet.
@DB
@Override
public void removeDhcpServiceInSubnet(final Nic nic) {
final Network network = _networksDao.findById(nic.getNetworkId());
final DhcpServiceProvider dhcpServiceProvider = getDhcpServiceProvider(network);
try {
final NicIpAliasVO ipAlias = _nicIpAliasDao.findByGatewayAndNetworkIdAndState(nic.getIPv4Gateway(), network.getId(), NicIpAlias.State.active);
if (ipAlias != null) {
ipAlias.setState(NicIpAlias.State.revoked);
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
_nicIpAliasDao.update(ipAlias.getId(), ipAlias);
final IPAddressVO aliasIpaddressVo = _publicIpAddressDao.findByIpAndSourceNetworkId(ipAlias.getNetworkId(), ipAlias.getIp4Address());
_publicIpAddressDao.unassignIpAddress(aliasIpaddressVo.getId());
}
});
if (!dhcpServiceProvider.removeDhcpSupportForSubnet(network)) {
s_logger.warn("Failed to remove the ip alias on the router, marking it as removed in db and freed the allocated ip " + ipAlias.getIp4Address());
}
}
} catch (final ResourceUnavailableException e) {
//failed to remove the dhcpconfig on the router.
s_logger.info("Unable to delete the ip alias due to unable to contact the virtualrouter.");
}
}
use of com.cloud.network.element.DhcpServiceProvider 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;
}
use of com.cloud.network.element.DhcpServiceProvider 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");
}
}
use of com.cloud.network.element.DhcpServiceProvider in project cloudstack by apache.
the class NetworkOrchestrator method getDhcpServiceProvider.
@Override
public DhcpServiceProvider getDhcpServiceProvider(final Network network) {
final String DhcpProvider = _ntwkSrvcDao.getProviderForServiceInNetwork(network.getId(), Service.Dhcp);
if (DhcpProvider == null) {
s_logger.debug("Network " + network + " doesn't support service " + Service.Dhcp.getName());
return null;
}
final NetworkElement element = _networkModel.getElementImplementingProvider(DhcpProvider);
if (element instanceof DhcpServiceProvider) {
return (DhcpServiceProvider) element;
} else {
return null;
}
}
Aggregations