示例#1
0
    @Override
    public VdcActionParametersBase getParameters(
        VM incoming, org.ovirt.engine.core.common.businessentities.VM entity) {
      VmStatic updated = getMapper(modelType, VmStatic.class).map(incoming, entity.getStaticData());

      updated.setUsbPolicy(
          VmMapper.getUsbPolicyOnUpdate(
              incoming.getUsb(),
              entity.getUsbPolicy(),
              lookupCluster(updated.getVdsGroupId()).getCompatibilityVersion()));

      VmManagementParametersBase params = new VmManagementParametersBase(updated);

      params.setApplyChangesLater(isNextRunRequested());

      if (incoming.isSetPayloads()) {
        if (incoming.isSetPayloads() && incoming.getPayloads().isSetPayload()) {
          params.setVmPayload(parent.getPayload(incoming));
        } else {
          params.setClearPayload(true);
        }
      }
      if (incoming.isSetMemoryPolicy() && incoming.getMemoryPolicy().isSetBallooning()) {
        params.setBalloonEnabled(incoming.getMemoryPolicy().isBallooning());
      }
      if (incoming.isSetConsole() && incoming.getConsole().isSetEnabled()) {
        params.setConsoleEnabled(incoming.getConsole().isEnabled());
      }
      if (incoming.isSetVirtioScsi()) {
        params.setVirtioScsiEnabled(incoming.getVirtioScsi().isEnabled());
      }
      if (incoming.isSetSoundcardEnabled()) {
        params.setSoundDeviceEnabled(incoming.isSoundcardEnabled());
      }
      if (incoming.isSetRngDevice()) {
        params.setUpdateRngDevice(true);
        params.setRngDevice(RngDeviceMapper.map(incoming.getRngDevice(), null));
      }

      DisplayHelper.setGraphicsToParams(incoming.getDisplay(), params);

      if (incoming.isSetInstanceType()
          && (incoming.getInstanceType().isSetId() || incoming.getInstanceType().isSetName())) {
        updated.setInstanceTypeId(lookupInstanceTypeId(incoming.getInstanceType()));
      } else if (incoming.isSetInstanceType()) {
        // this means that the instance type should be unset
        updated.setInstanceTypeId(null);
      }
      IconHelper.setIconToParams(incoming, params);
      return params;
    }
  private VmManagementParametersBase createUpdateVmParameters() {
    // clear non updateable fields got from config
    getVm().setExportDate(null);
    getVm().setOvfVersion(null);

    VmManagementParametersBase updateVmParams = new VmManagementParametersBase(getVm());
    updateVmParams.setUpdateWatchdog(true);
    updateVmParams.setSoundDeviceEnabled(false);
    updateVmParams.setBalloonEnabled(false);
    updateVmParams.setVirtioScsiEnabled(false);
    updateVmParams.setClearPayload(true);

    for (VmDevice device : getVm().getManagedVmDeviceMap().values()) {
      switch (device.getType()) {
        case WATCHDOG:
          updateVmParams.setWatchdog(new VmWatchdog(device));
          break;
        case SOUND:
          updateVmParams.setSoundDeviceEnabled(true);
          break;
        case BALLOON:
          updateVmParams.setBalloonEnabled(true);
          break;
        case CONTROLLER:
          if (VmDeviceType.VIRTIOSCSI.getName().equals(device.getDevice())) {
            updateVmParams.setVirtioScsiEnabled(true);
          }
          break;
        case DISK:
          if (VmPayload.isPayload(device.getSpecParams())) {
            updateVmParams.setVmPayload(
                new VmPayload(VmDeviceType.getByName(device.getDevice()), device.getSpecParams()));
          }
          break;
        case CONSOLE:
          updateVmParams.setConsoleEnabled(true);
          break;
        default:
      }
    }

    // clear these fields as these are non updatable
    getVm().getManagedVmDeviceMap().clear();
    getVm().getVmUnamagedDeviceList().clear();

    return updateVmParams;
  }