use of org.ovirt.engine.core.bll.network.VmInterfaceManager in project ovirt-engine by oVirt.
the class AddVmCommand method addVmNetwork.
protected void addVmNetwork() {
List<? extends VmNic> nics = getVmInterfaces();
VmInterfaceManager vmInterfaceManager = new VmInterfaceManager(getMacPool());
vmInterfaceManager.sortVmNics(nics, getVmInterfaceDevices());
List<String> macAddresses = getMacPool().allocateMacAddresses(nics.size());
// Add interfaces from template
for (int i = 0; i < nics.size(); ++i) {
VmNic iface = nics.get(i);
Guid id = Guid.newGuid();
srcVmNicIdToTargetVmNicIdMapping.put(iface.getId(), id);
iface.setId(id);
iface.setMacAddress(macAddresses.get(i));
iface.setSpeed(VmInterfaceType.forValue(iface.getType()).getSpeed());
iface.setVmTemplateId(null);
iface.setVmId(getParameters().getVmStaticData().getId());
updateProfileOnNic(iface);
vmNicDao.save(iface);
getCompensationContext().snapshotNewEntity(iface);
vmNetworkStatisticsDao.save(iface.getStatistics());
getCompensationContext().snapshotNewEntity(iface.getStatistics());
}
}
use of org.ovirt.engine.core.bll.network.VmInterfaceManager in project ovirt-engine by oVirt.
the class ImportVmCommandBase method addVmInterfaces.
protected void addVmInterfaces() {
VmInterfaceManager vmInterfaceManager = new VmInterfaceManager(macPool);
VnicProfileHelper vnicProfileHelper = new VnicProfileHelper(getClusterId(), getStoragePoolId(), AuditLogType.IMPORTEXPORT_IMPORT_VM_INVALID_INTERFACES);
List<VmNetworkInterface> nics = getVm().getInterfaces();
vmInterfaceManager.sortVmNics(nics, getVm().getStaticData().getManagedDeviceMap());
if (!getParameters().isImportAsNewEntity() && isExternalMacsToBeReported()) {
reportExternalMacs();
}
for (VmNetworkInterface iface : getVm().getInterfaces()) {
initInterface(iface);
vnicProfileHelper.updateNicWithVnicProfileForUser(iface, getCurrentUser());
vmInterfaceManager.add(iface, getCompensationContext(), shouldReassignMac(iface));
macsAdded.add(iface.getMacAddress());
}
vnicProfileHelper.auditInvalidInterfaces(getVmName());
}
use of org.ovirt.engine.core.bll.network.VmInterfaceManager in project ovirt-engine by oVirt.
the class ActivateDeactivateVmNicCommand method macAvailable.
protected ValidationResult macAvailable() {
VmNic nic = getParameters().getNic();
EngineMessage failMessage = EngineMessage.NETWORK_MAC_ADDRESS_IN_USE;
return ValidationResult.failWith(failMessage, ReplacementUtils.getVariableAssignmentString(failMessage, nic.getMacAddress())).when(new VmInterfaceManager().tooManyPluggedInterfaceWithSameMac(nic, getMacPool()));
}
use of org.ovirt.engine.core.bll.network.VmInterfaceManager in project ovirt-engine by oVirt.
the class TryBackToAllSnapshotsOfVmCommand method restoreVmConfigFromSnapshot.
private void restoreVmConfigFromSnapshot() {
snapshotDao.updateStatus(getParameters().getDstSnapshotId(), SnapshotStatus.IN_PREVIEW);
snapshotDao.updateStatus(snapshotDao.getId(getVm().getId(), SnapshotType.PREVIEW, SnapshotStatus.LOCKED), SnapshotStatus.OK);
Guid activeSnapshotLeaseDomainId = null;
if (isLeaseDomainIdUpdateNeeded()) {
activeSnapshotLeaseDomainId = getVm().getStaticData().getLeaseStorageDomainId();
}
getSnapshotsManager().attempToRestoreVmConfigurationFromSnapshot(getVm(), getDstSnapshot(), snapshotDao.getId(getVm().getId(), SnapshotType.ACTIVE), getImagesToPreview(), getCompensationContext(), getCurrentUser(), new VmInterfaceManager(getMacPool()), isRestoreMemory());
// custom preview - without leases
if (!isRestoreLease()) {
vmStaticDao.updateVmLeaseStorageDomainId(getVm().getId(), null);
return;
}
Guid dstLeaseStorageDomainId = OvfUtils.fetchLeaseDomainId(getDstSnapshot().getVmConfiguration());
if (isLeaseDomainIdUpdateNeeded()) {
// previewed snapshot and active have leases on different domains, use the active snapshot lease
vmStaticDao.updateVmLeaseStorageDomainId(getVm().getId(), activeSnapshotLeaseDomainId);
} else if (getParameters().getDstLeaseDomainId() != null && !getParameters().getDstLeaseDomainId().equals(dstLeaseStorageDomainId)) {
// custom preview - use the other snapshot lease.
// if the given destination lease domain ID is not equals to the previewed snapshot lease domain ID
// it means that the preview uses other lease domain ID that should set instead of the previewed snapshot
// lease domain ID
vmStaticDao.updateVmLeaseStorageDomainId(getVm().getId(), getParameters().getDstLeaseDomainId());
}
}
use of org.ovirt.engine.core.bll.network.VmInterfaceManager in project ovirt-engine by oVirt.
the class RestoreAllSnapshotsCommand method restoreConfiguration.
/**
* Prepare to remove the active snapshot & restore the given snapshot to be the active one, including the
* configuration.
*
* @param targetSnapshot
* The snapshot to restore to.
*/
private void restoreConfiguration(Snapshot targetSnapshot) {
removedSnapshot = snapshotDao.get(getVmId(), SnapshotType.ACTIVE);
snapshotsToRemove.add(removedSnapshot.getId());
getSnapshotsManager().removeAllIllegalDisks(removedSnapshot.getId(), getVmId());
getSnapshotsManager().attempToRestoreVmConfigurationFromSnapshot(getVm(), targetSnapshot, targetSnapshot.getId(), null, getCompensationContext(), getCurrentUser(), new VmInterfaceManager(getMacPool()), targetSnapshot.containsMemory());
snapshotDao.remove(targetSnapshot.getId());
// add active snapshot with status locked, so that other commands that depend on the VM's snapshots won't run in parallel
getSnapshotsManager().addActiveSnapshot(targetSnapshot.getId(), getVm(), SnapshotStatus.LOCKED, targetSnapshot.getMemoryDiskId(), targetSnapshot.getMetadataDiskId(), getCompensationContext());
}
Aggregations