use of org.ovirt.engine.api.model.Vm in project ovirt-engine by oVirt.
the class CompletenessAssertorTest method testMissingParameters.
@Test
public void testMissingParameters() throws Exception {
Vm vm = new Vm();
vm.setDescription("incomplete");
try {
CompletenessAssertor.validateParameters(vm, "name", "host", "status");
fail("expected WebApplicationException on incomplete model");
} catch (WebApplicationException wae) {
verifyIncompleteException(wae, "Vm", "name", "host", "status");
}
}
use of org.ovirt.engine.api.model.Vm in project ovirt-engine by oVirt.
the class CompletenessAssertorTest method testMissingBothAlternatives.
@Test
public void testMissingBothAlternatives() throws Exception {
Permission permission = new Permission();
permission.setVm(new Vm());
try {
CompletenessAssertor.validateParameters(permission, "user|vm.name|id");
fail("expected WebApplicationException on incomplete model");
} catch (WebApplicationException wae) {
verifyIncompleteException(wae, "Permission", "user|vm.name|id");
}
}
use of org.ovirt.engine.api.model.Vm in project ovirt-engine by oVirt.
the class BackendDiskResource method doPopulate.
@Override
protected Disk doPopulate(Disk model, org.ovirt.engine.core.common.businessentities.storage.Disk entity) {
// Populate the references to the VMs that are using this disk:
List<org.ovirt.engine.core.common.businessentities.VM> vms = new ArrayList<>(1);
QueryReturnValue result = runQuery(QueryType.GetVmsByDiskGuid, new IdQueryParameters(entity.getId()));
if (result.getSucceeded()) {
Map<Boolean, List<org.ovirt.engine.core.common.businessentities.VM>> map = result.getReturnValue();
if (MapUtils.isNotEmpty(map)) {
for (List<org.ovirt.engine.core.common.businessentities.VM> list : map.values()) {
vms.addAll(list);
}
}
}
if (CollectionUtils.isNotEmpty(vms)) {
Vms modelVms = new Vms();
for (org.ovirt.engine.core.common.businessentities.VM vm : vms) {
Vm modelVm = new Vm();
modelVm.setId(vm.getId().toString());
modelVms.getVms().add(modelVm);
}
model.setVms(modelVms);
}
return model;
}
use of org.ovirt.engine.api.model.Vm in project ovirt-engine by oVirt.
the class V3VMInAdapter method adapt.
@Override
public Vm adapt(V3VM from) {
Vm to = new Vm();
if (from.isSetLinks()) {
to.getLinks().addAll(adaptIn(from.getLinks()));
}
if (from.isSetActions()) {
to.setActions(adaptIn(from.getActions()));
}
if (from.isSetBios()) {
to.setBios(adaptIn(from.getBios()));
}
if (from.isSetCdroms()) {
to.setCdroms(adaptIn(from.getCdroms()));
}
if (from.isSetCluster()) {
to.setCluster(adaptIn(from.getCluster()));
}
if (from.isSetComment()) {
to.setComment(from.getComment());
}
if (from.isSetConsole()) {
to.setConsole(adaptIn(from.getConsole()));
}
if (from.isSetCpu()) {
to.setCpu(adaptIn(from.getCpu()));
}
if (from.isSetCpuProfile()) {
to.setCpuProfile(adaptIn(from.getCpuProfile()));
}
if (from.isSetCpuShares()) {
to.setCpuShares(from.getCpuShares());
}
if (from.isSetCreationTime()) {
to.setCreationTime(from.getCreationTime());
}
if (from.isSetCustomCpuModel()) {
to.setCustomCpuModel(from.getCustomCpuModel());
}
if (from.isSetCustomEmulatedMachine()) {
to.setCustomEmulatedMachine(from.getCustomEmulatedMachine());
}
if (from.isSetCustomProperties()) {
to.setCustomProperties(adaptIn(from.getCustomProperties()));
}
if (from.isSetDeleteProtected()) {
to.setDeleteProtected(from.isDeleteProtected());
}
if (from.isSetDescription()) {
to.setDescription(from.getDescription());
}
if (from.isSetDisks()) {
DiskAttachments toAttachments = new DiskAttachments();
for (V3Disk fromDisk : from.getDisks().getDisks()) {
DiskAttachment toAttachment = new DiskAttachment();
toAttachment.setDisk(adaptIn(fromDisk));
toAttachments.getDiskAttachments().add(toAttachment);
}
to.setDiskAttachments(toAttachments);
}
if (from.isSetDisplay()) {
to.setDisplay(adaptIn(from.getDisplay()));
}
if (from.isSetDomain()) {
to.setDomain(adaptIn(from.getDomain()));
}
if (from.isSetExternalHostProvider()) {
to.setExternalHostProvider(adaptIn(from.getExternalHostProvider()));
}
if (from.isSetFloppies()) {
to.setFloppies(adaptIn(from.getFloppies()));
}
if (from.isSetGuestOperatingSystem()) {
to.setGuestOperatingSystem(adaptIn(from.getGuestOperatingSystem()));
}
if (from.isSetGuestTimeZone()) {
to.setGuestTimeZone(adaptIn(from.getGuestTimeZone()));
}
if (from.isSetHighAvailability()) {
to.setHighAvailability(adaptIn(from.getHighAvailability()));
}
if (from.isSetHost()) {
to.setHost(adaptIn(from.getHost()));
}
if (from.isSetId()) {
to.setId(from.getId());
}
if (from.isSetHref()) {
to.setHref(from.getHref());
}
if (from.isSetInitialization()) {
to.setInitialization(adaptIn(from.getInitialization()));
}
if (from.isSetInstanceType()) {
to.setInstanceType(adaptIn(from.getInstanceType()));
}
if (from.isSetIo()) {
to.setIo(adaptIn(from.getIo()));
}
if (from.isSetKatelloErrata()) {
to.setKatelloErrata(adaptIn(from.getKatelloErrata()));
}
if (from.isSetLargeIcon()) {
to.setLargeIcon(adaptIn(from.getLargeIcon()));
}
if (from.isSetMemory()) {
to.setMemory(from.getMemory());
}
if (from.isSetMemoryPolicy()) {
to.setMemoryPolicy(adaptIn(from.getMemoryPolicy()));
}
if (from.isSetMigration()) {
to.setMigration(adaptIn(from.getMigration()));
}
if (from.isSetMigrationDowntime()) {
to.setMigrationDowntime(from.getMigrationDowntime());
}
if (from.isSetName()) {
to.setName(from.getName());
}
if (from.isSetNextRunConfigurationExists()) {
to.setNextRunConfigurationExists(from.isNextRunConfigurationExists());
}
if (from.isSetNics()) {
to.setNics(adaptIn(from.getNics()));
}
if (from.isSetNumaTuneMode()) {
to.setNumaTuneMode(NumaTuneMode.fromValue(from.getNumaTuneMode()));
}
if (from.isSetOrigin()) {
to.setOrigin(from.getOrigin());
}
if (from.isSetOs()) {
to.setOs(adaptIn(from.getOs()));
}
if (from.isSetPayloads()) {
to.setPayloads(adaptIn(from.getPayloads()));
}
if (from.isSetPermissions()) {
to.setPermissions(adaptIn(from.getPermissions()));
}
if (from.isSetPlacementPolicy()) {
to.setPlacementPolicy(adaptIn(from.getPlacementPolicy()));
}
if (from.isSetQuota()) {
to.setQuota(adaptIn(from.getQuota()));
}
if (from.isSetReportedDevices()) {
to.setReportedDevices(adaptIn(from.getReportedDevices()));
}
if (from.isSetRngDevice()) {
to.setRngDevice(adaptIn(from.getRngDevice()));
}
if (from.isSetRunOnce()) {
to.setRunOnce(from.isRunOnce());
}
if (from.isSetSerialNumber()) {
to.setSerialNumber(adaptIn(from.getSerialNumber()));
}
if (from.isSetSmallIcon()) {
to.setSmallIcon(adaptIn(from.getSmallIcon()));
}
if (from.isSetSnapshots()) {
to.setSnapshots(adaptIn(from.getSnapshots()));
}
if (from.isSetSoundcardEnabled()) {
to.setSoundcardEnabled(from.isSoundcardEnabled());
}
if (from.isSetSso()) {
to.setSso(adaptIn(from.getSso()));
}
if (from.isSetStartPaused()) {
to.setStartPaused(from.isStartPaused());
}
if (from.isSetStartTime()) {
to.setStartTime(from.getStartTime());
}
if (from.isSetStateless()) {
to.setStateless(from.isStateless());
}
if (from.isSetStatistics()) {
to.setStatistics(adaptIn(from.getStatistics()));
}
V3Status status = from.getStatus();
if (status != null) {
if (status.isSetState()) {
to.setStatus(VmStatus.fromValue(status.getState()));
}
if (status.isSetDetail()) {
to.setStatusDetail(status.getDetail());
}
}
if (from.isSetStopReason()) {
to.setStopReason(from.getStopReason());
}
if (from.isSetStopTime()) {
to.setStopTime(from.getStopTime());
}
if (from.isSetStorageDomain()) {
to.setStorageDomain(adaptIn(from.getStorageDomain()));
}
if (from.isSetTags()) {
to.setTags(adaptIn(from.getTags()));
}
if (from.isSetTemplate()) {
to.setTemplate(adaptIn(from.getTemplate()));
}
if (from.isSetTimeZone()) {
to.setTimeZone(adaptIn(from.getTimeZone()));
}
if (from.isSetTunnelMigration()) {
to.setTunnelMigration(from.isTunnelMigration());
}
if (from.isSetType()) {
to.setType(VmType.fromValue(from.getType()));
}
if (from.isSetUsb()) {
to.setUsb(adaptIn(from.getUsb()));
}
if (from.isSetUseLatestTemplateVersion()) {
to.setUseLatestTemplateVersion(from.isUseLatestTemplateVersion());
}
if (from.isSetVirtioScsi()) {
to.setVirtioScsi(adaptIn(from.getVirtioScsi()));
}
if (from.isSetVmPool()) {
to.setVmPool(adaptIn(from.getVmPool()));
}
if (from.isSetWatchdogs()) {
to.setWatchdogs(adaptIn(from.getWatchdogs()));
}
// new structured "time_zone" element containing the name of the time zone and the UTC offset:
if (from.isSetTimezone() && !to.isSetTimeZone()) {
TimeZone timeZone = new TimeZone();
timeZone.setName(from.getTimezone());
to.setTimeZone(timeZone);
}
return to;
}
use of org.ovirt.engine.api.model.Vm 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);
});
}
Aggregations