use of com.cloud.engine.cloud.entity.api.db.VMNetworkMapVO in project cosmic by MissionCriticalCloud.
the class VMNetworkMapDaoImpl method getNetworks.
@Override
public List<Long> getNetworks(final long vmId) {
final SearchCriteria<VMNetworkMapVO> sc = VmIdSearch.create();
sc.setParameters("vmId", vmId);
final List<VMNetworkMapVO> results = search(sc, null);
final List<Long> networks = new ArrayList<>(results.size());
for (final VMNetworkMapVO result : results) {
networks.add(result.getNetworkId());
}
return networks;
}
use of com.cloud.engine.cloud.entity.api.db.VMNetworkMapVO in project cosmic by MissionCriticalCloud.
the class VMNetworkMapDaoImpl method findByVmAndNetworkId.
@Override
public VMNetworkMapVO findByVmAndNetworkId(final long vmId, final long networkId) {
final SearchCriteria<VMNetworkMapVO> sc = VmNetworkSearch.create();
sc.setParameters("vmId", vmId);
sc.setParameters("networkId", networkId);
final VMNetworkMapVO network = findOneBy(sc);
return network;
}
use of com.cloud.engine.cloud.entity.api.db.VMNetworkMapVO in project cosmic by MissionCriticalCloud.
the class VMNetworkMapDaoImpl method persist.
@Override
public void persist(final long vmId, final List<Long> networks) {
final TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
final SearchCriteria<VMNetworkMapVO> sc = VmIdSearch.create();
sc.setParameters("vmId", vmId);
expunge(sc);
for (final Long networkId : networks) {
final VMNetworkMapVO vo = new VMNetworkMapVO(vmId, networkId);
persist(vo);
}
txn.commit();
}
use of com.cloud.engine.cloud.entity.api.db.VMNetworkMapVO in project cosmic by MissionCriticalCloud.
the class NetworkOrchestrator method createNicForVm.
@Override
public NicProfile createNicForVm(final Network network, final NicProfile requested, final ReservationContext context, final VirtualMachineProfile vmProfile, final boolean prepare) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
final VirtualMachine vm = vmProfile.getVirtualMachine();
final Zone zone = _zoneRepository.findOne(network.getDataCenterId());
final Host host = _hostDao.findById(vm.getHostId());
final DeployDestination dest = new DeployDestination(zone, null, null, host);
NicProfile nic = getNicProfileForVm(network, requested, vm);
// 1) allocate nic (if needed) Always allocate if it is a user vm
if (nic == null || vmProfile.getType() == VirtualMachine.Type.User) {
nic = allocateNic(requested, network, false, vmProfile);
if (nic == null) {
throw new CloudRuntimeException("Failed to allocate nic for vm " + vm + " in network " + network);
}
// Update vm_network_map table
if (vmProfile.getType() == VirtualMachine.Type.User) {
final VMNetworkMapVO vno = new VMNetworkMapVO(vm.getId(), network.getId());
_vmNetworkMapDao.persist(vno);
}
s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network);
}
// 2) prepare nic
if (prepare) {
final Pair<NetworkGuru, NetworkVO> implemented = implementNetwork(nic.getNetworkId(), dest, context, vmProfile.getVirtualMachine().getType() == Type.DomainRouter);
if (implemented == null || implemented.first() == null) {
s_logger.warn("Failed to implement network id=" + nic.getNetworkId() + " as a part of preparing nic id=" + nic.getId());
throw new CloudRuntimeException("Failed to implement network id=" + nic.getNetworkId() + " as a part preparing nic id=" + nic.getId());
}
nic = prepareNic(vmProfile, dest, context, nic.getId(), implemented.second());
s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network);
}
return nic;
}
use of com.cloud.engine.cloud.entity.api.db.VMNetworkMapVO 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(VirtualMachine.Type.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);
}
}
}
}
Aggregations