use of org.ovirt.engine.api.resource.SystemResource in project ovirt-engine by oVirt.
the class V3NICHelper method isProfileCompatible.
/**
* Checks if the given VNIC profile is compatible with the given NIC.
*
* @param profile the VNIC profile to check
* @param nic the NIC to check
* @return {@code true} iff the profile is compatible with the network and port mirroring configuration of the NIC
*/
private static boolean isProfileCompatible(VnicProfile profile, V3NIC nic) {
// Retrieve the representation of the network corresponding to the profile, as we are going to need it in
// order to check the name:
SystemResource systemService = BackendApiResource.getInstance();
NetworksResource networksService = systemService.getNetworksResource();
NetworkResource networkService = networksService.getNetworkResource(profile.getNetwork().getId());
Network profileNetwork = networkService.get();
// If the NIC configuration explicitly specifies a network then the profile has to correspond to that same
// network:
V3Network nicNetwork = nic.getNetwork();
if (nicNetwork != null) {
if (nicNetwork.isSetId()) {
if (!Objects.equals(profileNetwork.getId(), nicNetwork.getId())) {
return false;
}
}
if (nicNetwork.isSetName()) {
if (!Objects.equals(profileNetwork.getName(), nicNetwork.getName())) {
return false;
}
}
}
// If the NIC configuration explicitly specifies a port mirroring configuration then the profile must have
// port mirroring enabled, and all the networks included in the port mirroring configuration must be the same
// network used by the profile:
V3PortMirroring nicPortMirroring = nic.getPortMirroring();
if (nicPortMirroring != null) {
if (!profile.isSetPortMirroring() || !profile.isPortMirroring()) {
return false;
}
V3Networks nicPortMirroringNetworks = nicPortMirroring.getNetworks();
if (nicPortMirroringNetworks != null) {
for (V3Network nicPortMirroringNetwork : nicPortMirroringNetworks.getNetworks()) {
if (nicPortMirroringNetwork.isSetId()) {
if (!Objects.equals(profileNetwork.getId(), nicPortMirroringNetwork.getId())) {
return false;
}
}
if (nicPortMirroringNetwork.isSetName()) {
if (!Objects.equals(profileNetwork.getName(), nicPortMirroringNetwork.getName())) {
return false;
}
}
}
}
}
// All checks passed, so the profile is compatible:
return true;
}
use of org.ovirt.engine.api.resource.SystemResource in project ovirt-engine by oVirt.
the class V3VmHelper method addGuestIp.
/**
* If the V4 virtual machine has IP addresses reported, then add them to the V3 {@code guest_info} element.
*/
public static void addGuestIp(V3VM vm) {
String vmId = vm.getId();
if (vmId != null) {
SystemResource systemResource = BackendApiResource.getInstance();
VmsResource vmsResource = systemResource.getVmsResource();
VmResource vmResource = vmsResource.getVmResource(vmId);
VmNicsResource nicsResource = vmResource.getNicsResource();
try {
Nics fromNics = nicsResource.list();
List<Ip> fromIps = new ArrayList<>();
for (Nic fromNic : fromNics.getNics()) {
ReportedDevices fromDevices = fromNic.getReportedDevices();
if (fromDevices != null) {
for (ReportedDevice fromDevice : fromDevices.getReportedDevices()) {
Ips deviceIps = fromDevice.getIps();
if (deviceIps != null) {
fromIps.addAll(deviceIps.getIps());
}
}
}
}
if (!fromIps.isEmpty()) {
V3GuestInfo guestInfo = vm.getGuestInfo();
if (guestInfo == null) {
guestInfo = new V3GuestInfo();
vm.setGuestInfo(guestInfo);
}
V3IPs ips = guestInfo.getIps();
if (ips == null) {
ips = new V3IPs();
guestInfo.setIps(ips);
}
ips.getIPs().addAll(adaptOut(fromIps));
}
} catch (WebApplicationException exception) {
// If an application exception is generated while retrieving the details of the NICs is safe to ignore
// it, as it may be that the user just doesn't have permission to see the NICs, but she may still have
// permissions to see the other details of the virtual machine.
}
}
}
Aggregations