use of org.ovirt.engine.ui.frontend.AsyncQuery in project ovirt-engine by oVirt.
the class InstanceTypeManager method updateDefaultDisplayRelatedFields.
protected void updateDefaultDisplayRelatedFields(final VmBase vmBase) {
// Update display protocol selected item
final Collection<DisplayType> displayTypes = model.getDisplayType().getItems();
if (displayTypes == null || displayTypes.isEmpty()) {
return;
}
// graphics
Frontend.getInstance().runQuery(QueryType.GetGraphicsDevices, new IdQueryParameters(vmBase.getId()), new AsyncQuery<QueryReturnValue>(returnValue -> {
deactivate();
List<GraphicsDevice> graphicsDevices = returnValue.getReturnValue();
model.getIsHeadlessModeEnabled().setEntity(vmBase.getDefaultDisplayType() == DisplayType.none);
// select display protocol
// first by default
DisplayType displayProtocol = displayTypes.iterator().next();
if (displayTypes.contains(vmBase.getDefaultDisplayType())) {
// if display types contain DT of a vm, pick this one
displayProtocol = vmBase.getDefaultDisplayType();
}
maybeSetSelectedItem(model.getDisplayType(), displayProtocol);
Set<GraphicsType> graphicsTypes = new HashSet<>();
for (GraphicsDevice graphicsDevice : graphicsDevices) {
graphicsTypes.add(graphicsDevice.getGraphicsType());
}
UnitVmModel.GraphicsTypes selected = UnitVmModel.GraphicsTypes.fromGraphicsTypes(graphicsTypes);
if (selected != null && getModel().getGraphicsType().getItems().contains(selected)) {
maybeSetSelectedItem(getModel().getGraphicsType(), selected);
}
maybeSetSelectedItem(model.getNumOfMonitors(), vmBase.getNumOfMonitors());
maybeSetSelectedItem(model.getUsbPolicy(), vmBase.getUsbPolicy());
maybeSetEntity(model.getIsSmartcardEnabled(), vmBase.isSmartcardEnabled());
maybeSetSingleQxlPci(vmBase);
activate();
}));
}
use of org.ovirt.engine.ui.frontend.AsyncQuery in project ovirt-engine by oVirt.
the class InstanceTypeManager method updateAll.
/**
* First updates the list of instance types and selects the one which is supposed to be selected and then
* updates all the fields which are taken from the instance type (by calling the updateFields()).
*/
public void updateAll() {
final Guid selectedInstanceTypeId = getSelectedInstanceTypeId();
Frontend.getInstance().runQuery(QueryType.GetAllInstanceTypes, new QueryParametersBase(), new AsyncQuery<QueryReturnValue>(returnValue -> {
if (returnValue == null || !returnValue.getSucceeded()) {
return;
}
List<InstanceType> instanceTypes = new ArrayList<>();
// add this only if the user is allowed to
if (!getModel().isCreateInstanceOnly()) {
instanceTypes.add(CustomInstanceType.INSTANCE);
}
for (InstanceType instanceType : (Iterable<InstanceType>) returnValue.getReturnValue()) {
instanceTypes.add(instanceType);
}
getModel().getInstanceTypes().setItems(instanceTypes);
for (InstanceType instanceType : instanceTypes) {
if ((instanceType instanceof CustomInstanceType) && selectedInstanceTypeId == null) {
getModel().getInstanceTypes().setSelectedItem(CustomInstanceType.INSTANCE);
break;
}
if (instanceType.getId() == null || selectedInstanceTypeId == null) {
continue;
}
if (instanceType.getId().equals(selectedInstanceTypeId)) {
getModel().getInstanceTypes().setSelectedItem(instanceType);
break;
}
}
if (getModel().getInstanceTypes().getSelectedItem() instanceof CustomInstanceType) {
// detach if the instance type is "custom"
getModel().getAttachedToInstanceType().setEntity(false);
}
updateFields();
}));
}
use of org.ovirt.engine.ui.frontend.AsyncQuery in project ovirt-engine by oVirt.
the class InstanceTypeManager method updateRngDevice.
protected void updateRngDevice(final VmBase vmBase) {
if (model.getIsRngEnabled().getIsChangable() && model.getIsRngEnabled().getIsAvailable()) {
if (!isNextRunConfigurationExists()) {
Frontend.getInstance().runQuery(QueryType.GetRngDevice, new IdQueryParameters(vmBase.getId()), new AsyncQuery<QueryReturnValue>(returnValue -> {
deactivate();
List<VmDevice> rngDevices = returnValue.getReturnValue();
getModel().getIsRngEnabled().setEntity(!rngDevices.isEmpty());
if (!rngDevices.isEmpty()) {
VmRngDevice rngDevice = new VmRngDevice(rngDevices.get(0));
rngDevice.updateSourceByVersion(getModel().getCompatibilityVersion());
getModel().setRngDevice(rngDevice);
}
activate();
updateVirtioScsi(vmBase);
}));
} else {
deactivate();
VmDevice rngDevice = VmDeviceCommonUtils.findVmDeviceByGeneralType(vmBase.getManagedDeviceMap(), VmDeviceGeneralType.RNG);
getModel().getIsRngEnabled().setEntity(rngDevice != null);
if (rngDevice != null) {
getModel().setRngDevice(new VmRngDevice(rngDevice));
}
activate();
updateVirtioScsi(vmBase);
}
} else {
updateVirtioScsi(vmBase);
}
}
use of org.ovirt.engine.ui.frontend.AsyncQuery in project ovirt-engine by oVirt.
the class VmInstanceTypeManager method updateNetworkInterfaces.
private void updateNetworkInterfaces(final ProfileBehavior behavior, final List<VmNetworkInterface> argNics) {
AsyncQuery<List<VnicProfileView>> query = new AsyncQuery<>(profiles -> {
List<VnicInstanceType> vnicInstanceTypes = new ArrayList<>();
List<VmNetworkInterface> nics = (argNics == null) ? new ArrayList<VmNetworkInterface>() : argNics;
for (VmNetworkInterface nic : nics) {
final VnicInstanceType vnicInstanceType = new VnicInstanceType(nic);
vnicInstanceType.setItems(profiles);
behavior.initSelectedProfile(vnicInstanceType, vnicInstanceType.getNetworkInterface());
vnicInstanceTypes.add(vnicInstanceType);
}
getModel().getNicsWithLogicalNetworks().getVnicProfiles().setItems(profiles);
getModel().getNicsWithLogicalNetworks().setItems(vnicInstanceTypes);
getModel().getNicsWithLogicalNetworks().setSelectedItem(Linq.firstOrNull(vnicInstanceTypes));
});
behavior.initProfiles(getModel().getSelectedCluster().getId(), getModel().getSelectedDataCenter().getId(), query);
}
use of org.ovirt.engine.ui.frontend.AsyncQuery in project ovirt-engine by oVirt.
the class ExistingVmModelBehavior method initialize.
@Override
public void initialize() {
super.initialize();
toggleAutoSetVmHostname();
getModel().getVmInitEnabled().setEntity(getVm().getVmInit() != null);
getModel().getVmInitModel().init(getVm().getStaticData());
getModel().getVmType().setIsChangeable(true);
getModel().getIsSoundcardEnabled().setIsChangeable(true);
getModel().getInstanceTypes().setIsChangeable(!vm.isRunning());
getModel().getLabelList().setIsAvailable(true);
getModel().getVmId().setIsAvailable(true);
getModel().getVmId().setIsChangeable(false);
loadDataCenter();
instanceTypeManager = new ExistingVmInstanceTypeManager(getModel(), vm);
if (vm.getVmPoolId() != null) {
instanceTypeManager.setAlwaysEnabledFieldUpdate(true);
}
Frontend.getInstance().runQuery(QueryType.GetVmNumaNodesByVmId, new IdQueryParameters(vm.getId()), new AsyncQuery<QueryReturnValue>(returnValue -> {
List<VmNumaNode> nodes = returnValue.getReturnValue();
getModel().setVmNumaNodes(nodes);
getModel().updateNodeCount(nodes.size());
}));
// load dedicated host names into host names list
if (getVm().getDedicatedVmForVdsList().size() > 0) {
Frontend.getInstance().runQuery(QueryType.GetAllHostNamesPinnedToVmById, new IdQueryParameters(vm.getId()), asyncQuery((QueryReturnValue returnValue) -> setDedicatedHostsNames((List<String>) returnValue.getReturnValue())));
}
}
Aggregations