use of org.ovirt.engine.api.resource.SystemResource in project ovirt-engine by oVirt.
the class V3VmDisksServer method list.
@GET
public V3Disks list() {
SystemResource systemResource = BackendApiResource.getInstance();
// In version 4 of the API the collection of disks of a virtual machine has been replaced by the collection of
// disk attachments, so we need to fetch the disk attachments:
VmsResource vmsResource = systemResource.getVmsResource();
VmResource vmResource = vmsResource.getVmResource(vmId);
DiskAttachmentsResource attachmentsResource = vmResource.getDiskAttachmentsResource();
DiskAttachments attachments = attachmentsResource.list();
// For each disk, we need now to fetch it from the top level disks collection, and add the information from
// the corresponding attachment:
DisksResource disksResource = systemResource.getDisksResource();
V3Disks disks = new V3Disks();
for (DiskAttachment attachment : attachments.getDiskAttachments()) {
DiskResource diskResource = disksResource.getDiskResource(attachment.getDisk().getId());
Disk v4Disk = diskResource.get();
V3Disk v3Disk = adaptOut(v4Disk);
V3VmHelper.addDiskAttachmentDetails(attachment, v3Disk);
V3VmHelper.fixDiskLinks(vmId, v3Disk);
disks.getDisks().add(v3Disk);
}
return disks;
}
use of org.ovirt.engine.api.resource.SystemResource in project ovirt-engine by oVirt.
the class V3NICHelper method setVnicProfile.
/**
* Finds the VNIC profile that correspond to the given V3 NIC and assigns it to the given V4 NIC.
*
* @param vmId the identifier of the virtual machine that the NIC is going to be added to
* @param v3Nic the V3 NIC where the information will be extracted from
* @param v4Nic the V4 NIC that will be populated
*/
public static void setVnicProfile(String vmId, V3NIC v3Nic, Nic v4Nic) {
// Do nothing if the profile is already set:
if (v4Nic.isSetVnicProfile()) {
return;
}
// In version 4 of the API the "network" and "port_mirroring" properties of the NIC have been completely
// removed, and instead of using them it is required to specify a VNIC profile. This means that if the user
// isn't explicitly indicating the VNIC profile we need to find one that is compatible with the given network
// and port mirroring configuration. The only VNIC profiles to consider are the ones corresponding to the
// networks of the cluster where the VM resides, so we need to retrieve the VM, then the cluster, and then the
// identifiers of the networks:
SystemResource systemService = BackendApiResource.getInstance();
VmsResource vmsService = systemService.getVmsResource();
VmResource vmService = vmsService.getVmResource(vmId);
Vm vm = vmService.get();
ClustersResource clustersService = systemService.getClustersResource();
ClusterResource clusterService = clustersService.getClusterResource(vm.getCluster().getId());
ClusterNetworksResource networksService = clusterService.getNetworksResource();
Set<String> validNetworkIds = networksService.list().getNetworks().stream().map(Network::getId).collect(toSet());
// Find a VNIC profile that is in the set of valid networks and that is compatible with the NIC:
VnicProfilesResource profilesService = systemService.getVnicProfilesResource();
profilesService.list().getVnicProfiles().stream().filter(profile -> validNetworkIds.contains(profile.getNetwork().getId())).filter(profile -> isProfileCompatible(profile, v3Nic)).sorted(comparing(VnicProfile::getName)).map(VnicProfile::getId).findFirst().ifPresent(id -> {
VnicProfile v4Profile = new VnicProfile();
v4Profile.setId(id);
v4Nic.setVnicProfile(v4Profile);
});
}
use of org.ovirt.engine.api.resource.SystemResource in project ovirt-engine by oVirt.
the class V3VmHelper method addDiskAttachmentDetails.
/**
* In version 4 of the API the interface, some attributes have been moved from the disk to the disk attachment, as
* they are specific of the relationship between a particular VM and the disk. But in version 3 of the API we need
* to continue supporting them. To do so we need to find the disk attachment and copy these attributes to the disk.
*/
public static void addDiskAttachmentDetails(String vmId, V3Disk disk) {
if (vmId != null) {
SystemResource systemResource = BackendApiResource.getInstance();
VmsResource vmsResource = systemResource.getVmsResource();
VmResource vmResource = vmsResource.getVmResource(vmId);
DiskAttachmentsResource attachmentsResource = vmResource.getDiskAttachmentsResource();
String diskId = disk.getId();
if (diskId != null) {
DiskAttachmentResource attachmentResource = attachmentsResource.getAttachmentResource(diskId);
try {
DiskAttachment attachment = attachmentResource.get();
addDiskAttachmentDetails(attachment, disk);
} catch (WebApplicationException exception) {
// If an application exception is generated while retrieving the details of the disk attachment
// it is safe to ignore it, as it may be that the user just doesn't have permission to see
// attachment, but she may still have permissions to see the other details of the disk.
}
}
}
}
use of org.ovirt.engine.api.resource.SystemResource in project ovirt-engine by oVirt.
the class V3ClusterOutAdapter method adapt.
@Override
public V3Cluster adapt(Cluster from) {
V3Cluster to = new V3Cluster();
if (from.isSetLinks()) {
to.getLinks().addAll(adaptOut(from.getLinks()));
}
if (from.isSetActions()) {
to.setActions(adaptOut(from.getActions()));
}
if (from.isSetBallooningEnabled()) {
to.setBallooningEnabled(from.isBallooningEnabled());
}
if (from.isSetComment()) {
to.setComment(from.getComment());
}
if (from.isSetCpu()) {
to.setCpu(adaptOut(from.getCpu()));
}
if (from.isSetDataCenter()) {
to.setDataCenter(adaptOut(from.getDataCenter()));
}
if (from.isSetDescription()) {
to.setDescription(from.getDescription());
}
if (from.isSetDisplay()) {
to.setDisplay(adaptOut(from.getDisplay()));
}
if (from.isSetErrorHandling()) {
to.setErrorHandling(adaptOut(from.getErrorHandling()));
}
if (from.isSetFencingPolicy()) {
to.setFencingPolicy(adaptOut(from.getFencingPolicy()));
}
if (from.isSetGlusterService()) {
to.setGlusterService(from.isGlusterService());
}
if (from.isSetHaReservation()) {
to.setHaReservation(from.isHaReservation());
}
if (from.isSetId()) {
to.setId(from.getId());
}
if (from.isSetHref()) {
to.setHref(from.getHref());
}
if (from.isSetKsm()) {
to.setKsm(adaptOut(from.getKsm()));
}
if (from.isSetMaintenanceReasonRequired()) {
to.setMaintenanceReasonRequired(from.isMaintenanceReasonRequired());
}
if (from.isSetManagementNetwork()) {
to.setManagementNetwork(adaptOut(from.getManagementNetwork()));
}
if (from.isSetMemoryPolicy()) {
to.setMemoryPolicy(adaptOut(from.getMemoryPolicy()));
}
if (from.isSetMigration()) {
to.setMigration(adaptOut(from.getMigration()));
}
if (from.isSetName()) {
to.setName(from.getName());
}
if (from.isSetOptionalReason()) {
to.setOptionalReason(from.isOptionalReason());
}
if (from.isSetRequiredRngSources()) {
to.setRequiredRngSources(new V3RngSources());
to.getRequiredRngSources().getRngSources().addAll(adaptRngSources(from));
}
if (from.isSetSerialNumber()) {
to.setSerialNumber(adaptOut(from.getSerialNumber()));
}
if (from.isSetSupportedVersions()) {
to.setSupportedVersions(new V3SupportedVersions());
to.getSupportedVersions().getVersions().addAll(adaptOut(from.getSupportedVersions().getVersions()));
}
if (from.isSetThreadsAsCores()) {
to.setThreadsAsCores(from.isThreadsAsCores());
}
if (from.isSetTrustedService()) {
to.setTrustedService(from.isTrustedService());
}
if (from.isSetTunnelMigration()) {
to.setTunnelMigration(from.isTunnelMigration());
}
if (from.isSetVersion()) {
to.setVersion(adaptOut(from.getVersion()));
}
if (from.isSetVirtService()) {
to.setVirtService(from.isVirtService());
}
// In V3 the scheduling policy was part of the cluster, so we need to retrieve the details and populate the
// "policy" and "thresholds" elements:
SchedulingPolicy fromPolicy = from.getSchedulingPolicy();
if (fromPolicy != null && fromPolicy.isSetId()) {
SystemResource systemResource = BackendApiResource.getInstance();
SchedulingPoliciesResource policiesResource = systemResource.getSchedulingPoliciesResource();
SchedulingPolicyResource policyResource = policiesResource.getPolicyResource(fromPolicy.getId());
try {
fromPolicy = policyResource.get();
} catch (WebApplicationException exception) {
// If an application exception is generated while retrieving the details of the scheduling policy it
// is safe to ignore it, as it may be that the user just doesn't have permission to see the policy, but
// she may still have permissions to see the other details of the cluster.
}
V3SchedulingPolicy toPolicy = to.getSchedulingPolicy();
if (toPolicy == null) {
toPolicy = new V3SchedulingPolicy();
to.setSchedulingPolicy(toPolicy);
}
if (fromPolicy.isSetId()) {
toPolicy.setId(fromPolicy.getId());
}
if (fromPolicy.isSetHref()) {
toPolicy.setHref(fromPolicy.getHref());
}
if (fromPolicy.isSetName() && !toPolicy.isSetPolicy()) {
toPolicy.setPolicy(fromPolicy.getName());
}
Properties fromProperties = fromPolicy.getProperties();
if (fromProperties != null) {
Integer fromDuration = getIntegerProperty(fromProperties, "CpuOverCommitDurationMinutes");
if (fromDuration != null) {
V3SchedulingPolicyThresholds toThresholds = toPolicy.getThresholds();
if (toThresholds == null) {
toThresholds = new V3SchedulingPolicyThresholds();
toPolicy.setThresholds(toThresholds);
}
toThresholds.setDuration(fromDuration);
}
Integer fromHigh = getIntegerProperty(fromProperties, "HighUtilization");
if (fromHigh != null) {
V3SchedulingPolicyThresholds toThresholds = toPolicy.getThresholds();
if (toThresholds == null) {
toThresholds = new V3SchedulingPolicyThresholds();
toPolicy.setThresholds(toThresholds);
}
toThresholds.setHigh(fromHigh);
}
Integer fromLow = getIntegerProperty(fromProperties, "LowUtilization");
if (fromLow != null) {
V3SchedulingPolicyThresholds toThresholds = toPolicy.getThresholds();
if (toThresholds == null) {
toThresholds = new V3SchedulingPolicyThresholds();
toPolicy.setThresholds(toThresholds);
}
toThresholds.setLow(fromLow);
}
}
}
return to;
}
use of org.ovirt.engine.api.resource.SystemResource in project ovirt-engine by oVirt.
the class V3ClusterHelper method findCompatiblePolicy.
/**
* Tries to find a V4 scheduling policy that is compatible with the given V3 scheduling policy.
*
* @return the compatible scheduling policy, or {@code null} if no such policy can be found
*/
public static SchedulingPolicy findCompatiblePolicy(V3SchedulingPolicy v3Policy) {
SystemResource systemResource = BackendApiResource.getInstance();
SchedulingPoliciesResource policiesResource = systemResource.getSchedulingPoliciesResource();
SchedulingPolicies v4Policies = policiesResource.list();
return v4Policies.getSchedulingPolicies().stream().filter(v4Policy -> arePoliciesCompatible(v3Policy, v4Policy)).findFirst().orElse(null);
}
Aggregations