use of com.cloud.network.element.NetworkElement 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);
}
}
use of com.cloud.network.element.NetworkElement in project cloudstack by apache.
the class NetworkOrchestrator method getLoadBalancingProviderForNetwork.
@Override
public LoadBalancingServiceProvider getLoadBalancingProviderForNetwork(final Network network, final Scheme lbScheme) {
final List<NetworkElement> lbElements = getElementForServiceInNetwork(network, Service.Lb);
NetworkElement lbElement = null;
if (lbElements.size() > 1) {
String providerName = null;
// get network offering details
final NetworkOffering off = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
if (lbScheme == Scheme.Public) {
providerName = _ntwkOffDetailsDao.getDetail(off.getId(), NetworkOffering.Detail.PublicLbProvider);
} else {
providerName = _ntwkOffDetailsDao.getDetail(off.getId(), NetworkOffering.Detail.InternalLbProvider);
}
if (providerName == null) {
throw new InvalidParameterValueException("Can't find Lb provider supporting scheme " + lbScheme.toString() + " in network " + network);
}
lbElement = _networkModel.getElementImplementingProvider(providerName);
} else if (lbElements.size() == 1) {
lbElement = lbElements.get(0);
}
assert lbElement != null;
assert lbElement instanceof LoadBalancingServiceProvider;
return (LoadBalancingServiceProvider) lbElement;
}
use of com.cloud.network.element.NetworkElement 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);
}
}
use of com.cloud.network.element.NetworkElement in project cloudstack by apache.
the class NetworkOrchestrator method getElementForServiceInNetwork.
protected List<NetworkElement> getElementForServiceInNetwork(final Network network, final Service service) {
final List<NetworkElement> elements = new ArrayList<NetworkElement>();
final List<Provider> providers = getProvidersForServiceInNetwork(network, service);
// Only support one provider now
if (providers == null) {
s_logger.error("Cannot find " + service.getName() + " provider for network " + network.getId());
return null;
}
if (providers.size() != 1 && service != Service.Lb) {
// support more than one LB providers only
s_logger.error("Found " + providers.size() + " " + service.getName() + " providers for network!" + network.getId());
return null;
}
for (final Provider provider : providers) {
final NetworkElement element = _networkModel.getElementImplementingProvider(provider.getName());
s_logger.info("Let " + element.getName() + " handle " + service.getName() + " in network " + network.getId());
elements.add(element);
}
return elements;
}
use of com.cloud.network.element.NetworkElement 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");
}
}
Aggregations