use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.
the class NetworkOrchestrator method getElementForServiceInNetwork.
protected List<NetworkElement> getElementForServiceInNetwork(final Network network, final Service service) {
final List<NetworkElement> elements = new ArrayList<>();
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.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.
the class NetworkOrchestrator method releaseNic.
@DB
protected void releaseNic(final VirtualMachineProfile vmProfile, final long nicId) throws ConcurrentOperationException, ResourceUnavailableException {
final Pair<Network, NicProfile> networkToRelease = Transaction.execute(new TransactionCallback<Pair<Network, NicProfile>>() {
@Override
public Pair<Network, NicProfile> doInTransaction(final TransactionStatus status) {
final NicVO nic = _nicDao.lockRow(nicId, true);
if (nic == null) {
throw new ConcurrentOperationException("Unable to acquire lock on nic " + nic);
}
final Nic.State originalState = nic.getState();
final NetworkVO network = _networksDao.findById(nic.getNetworkId());
if (originalState == Nic.State.Reserved || originalState == Nic.State.Reserving) {
if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
nic.setState(Nic.State.Releasing);
_nicDao.update(nic.getId(), nic);
final NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network));
if (guru.release(profile, vmProfile, nic.getReservationId())) {
applyProfileToNicForRelease(nic, profile);
nic.setState(Nic.State.Allocated);
if (originalState == Nic.State.Reserved) {
updateNic(nic, network.getId(), -1);
} else {
_nicDao.update(nic.getId(), nic);
}
}
// Perform release on network elements
return new Pair<>(network, profile);
} else {
nic.setState(Nic.State.Allocated);
updateNic(nic, network.getId(), -1);
}
}
return null;
}
});
// cleanup the entry in vm_network_map
if (vmProfile.getType().equals(VirtualMachineType.User)) {
final NicVO nic = _nicDao.findById(nicId);
if (nic != null) {
final NetworkVO vmNetwork = _networksDao.findById(nic.getNetworkId());
final VMNetworkMapVO vno = _vmNetworkMapDao.findByVmAndNetworkId(vmProfile.getVirtualMachine().getId(), vmNetwork.getId());
if (vno != null) {
_vmNetworkMapDao.remove(vno.getId());
}
}
}
if (networkToRelease != null) {
final Network network = networkToRelease.first();
final NicProfile profile = networkToRelease.second();
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 " + profile);
}
// NOTE: Context appear to never be used in release method
// implementations. Consider removing it from interface Element
element.release(network, profile, vmProfile, null);
}
}
}
}
use of com.cloud.legacymodel.network.Network.Provider 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.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.
the class NetworkOrchestrator method prepareNicForMigration.
@Override
public void prepareNicForMigration(final VirtualMachineProfile vm, final DeployDestination dest) {
if (vm.getType().equals(VirtualMachineType.DomainRouter) && vm.getHypervisorType().equals(HypervisorType.KVM)) {
// 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());
// Get Broadcast URI from the NIC
URI broadcastUri = nic.getBroadcastUri();
// Except for Guest networks
if (TrafficType.Guest.equals(network.getTrafficType())) {
broadcastUri = network.getBroadcastUri();
}
final NicProfile profile = new NicProfile(nic, network, broadcastUri, nic.getIsolationUri(), networkRate, _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);
}
}
use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.
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.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 | ResourceUnavailableException ex) {
s_logger.warn("release failed during the nic " + nic.toString() + " removeNic due to ", ex);
}
}
}
}
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");
}
}
Aggregations