use of org.ovirt.engine.core.common.businessentities.network.VmNic 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.common.businessentities.network.VmNic in project ovirt-engine by oVirt.
the class RemoveStoragePoolCommand method removeNetworks.
private void removeNetworks() {
final List<Network> networks = networkDao.getAllForDataCenter(getStoragePoolId());
for (Network network : networks) {
if (network.isExternal()) {
for (VmNic nic : vmNicDao.getAllForNetwork(network.getId())) {
externalNetworkManagerFactory.create(nic, network).deallocateIfExternal();
}
}
}
TransactionSupport.executeInNewTransaction(() -> {
for (final Network net : networks) {
List<VnicProfile> profiles = vnicProfileDao.getAllForNetwork(net.getId());
for (VnicProfile vnicProfile : profiles) {
getCompensationContext().snapshotEntity(vnicProfile);
vnicProfileDao.remove(vnicProfile.getId());
}
getCompensationContext().snapshotEntity(net);
networkDao.remove(net.getId());
}
getCompensationContext().stateChanged();
return null;
});
}
use of org.ovirt.engine.core.common.businessentities.network.VmNic in project ovirt-engine by oVirt.
the class HotPlugOrUnplugNicVDSCommand method generateDomainXml.
private String generateDomainXml() {
VmNic nic = getParameters().getNic();
VmDevice vmDevice = getParameters().getVmDevice();
LibvirtVmXmlBuilder builder = new LibvirtVmXmlBuilder(getParameters().getVm(), getVds().getId(), nic, vmDevice, vmInfoBuildUtils, nic.isPassthrough() ? Collections.singletonMap(nic.getId(), vmDevice.getHostDevice()) : Collections.emptyMap());
String libvirtXml = builder.buildHotplugNic();
String prettyLibvirtXml = XmlUtils.prettify(libvirtXml);
if (prettyLibvirtXml != null) {
log.info("NIC hot-set: {}", prettyLibvirtXml);
}
return libvirtXml;
}
use of org.ovirt.engine.core.common.businessentities.network.VmNic in project ovirt-engine by oVirt.
the class UpdateVmCommand method updateVmNetworks.
private void updateVmNetworks() {
// check if the cluster has changed
if (!Objects.equals(getVm().getClusterId(), getParameters().getVmStaticData().getClusterId())) {
List<Network> networks = networkDao.getAllForCluster(getParameters().getVmStaticData().getClusterId());
List<VmNic> interfaces = vmNicDao.getAllForVm(getParameters().getVmStaticData().getId());
for (final VmNic iface : interfaces) {
final Network network = networkHelper.getNetworkByVnicProfileId(iface.getVnicProfileId());
boolean networkFound = networks.stream().anyMatch(n -> Objects.equals(n.getId(), network.getId()));
// if network not exists in cluster we remove the network from the interface
if (!networkFound) {
iface.setVnicProfileId(null);
vmNicDao.update(iface);
}
}
}
}
use of org.ovirt.engine.core.common.businessentities.network.VmNic 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()));
}
Aggregations