コード例 #1
0
  private AddVmAndAttachToPoolParameters buildAddVmAndAttachToPoolParameters(
      Guid poolId, String vmName) {
    VmStatic currVm = new VmStatic(getParameters().getVmStaticData());
    currVm.setName(vmName);

    if (getParameters().getVmLargeIcon() != null) {
      final VmIconIdSizePair iconIds =
          IconUtils.ensureIconPairInDatabase(getParameters().getVmLargeIcon());
      currVm.setSmallIconId(iconIds.getSmall());
      currVm.setLargeIconId(iconIds.getLarge());
    }

    AddVmAndAttachToPoolParameters parameters =
        new AddVmAndAttachToPoolParameters(currVm, poolId, vmName, diskInfoDestinationMap);
    parameters.setSessionId(getParameters().getSessionId());
    parameters.setParentCommand(VdcActionType.AddVmPoolWithVms);
    parameters.setSoundDeviceEnabled(
        getParameters().isSoundDeviceEnabled() != null
            ? getParameters().isSoundDeviceEnabled()
            : VmType.Desktop == getParameters().getVmStaticData().getVmType());
    parameters.setConsoleEnabled(getParameters().isConsoleEnabled());
    parameters.setVirtioScsiEnabled(getParameters().isVirtioScsiEnabled());
    parameters.setBalloonEnabled(getParameters().isBalloonEnabled());

    VmRngDevice rngDevice = getParameters().getRngDevice();
    if (rngDevice != null) {
      parameters.setUpdateRngDevice(true);
      parameters.setRngDevice(rngDevice);
    }

    parameters.getGraphicsDevices().putAll(getParameters().getGraphicsDevices());

    return parameters;
  }
コード例 #2
0
 @Override
 public void addExternallyManagedVms(List<VmStatic> externalVmList) {
   for (VmStatic currVm : externalVmList) {
     AddVmParameters params = new AddVmParameters(currVm);
     VdcReturnValueBase returnValue =
         backend.runInternalAction(
             VdcActionType.AddVmFromScratch, params, ExecutionHandler.createInternalJobContext());
     if (!returnValue.getSucceeded()) {
       log.debug("Failed adding Externally managed VM '{}'", currVm.getName());
     }
   }
 }
コード例 #3
0
 protected static VM createVm() {
   VM vm = new VM();
   VmDynamic dynamic = new VmDynamic();
   VmStatic stat = new VmStatic();
   stat.setVmtGuid(Guid.newGuid());
   stat.setName("testVm");
   stat.setPriority(1);
   vm.setStaticData(stat);
   vm.setDynamicData(dynamic);
   vm.setSingleQxlPci(false);
   return vm;
 }
コード例 #4
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;
    }
コード例 #5
0
ファイル: VmsMonitoring.java プロジェクト: nirs/ovirt-engine
  protected void processExternallyManagedVms() {
    // Fetching for details from the host
    // and marking the VMs for addition
    List<String> vmsToQuery = new ArrayList<>(externalVms.size());
    for (Pair<VM, VmInternalData> pair : externalVms) {
      vmsToQuery.add(pair.getSecond().getVmDynamic().getId().toString());
    }
    if (!vmsToQuery.isEmpty()) {
      // Query VDSM for VMs info, and creating a proper VMStatic to be used when importing them
      Map[] vmsInfo = getVmInfo(vmsToQuery);
      for (Map vmInfo : vmsInfo) {
        Guid vmId = Guid.createGuidFromString((String) vmInfo.get(VdsProperties.vm_guid));
        VmStatic vmStatic = new VmStatic();
        vmStatic.setId(vmId);
        vmStatic.setCreationDate(new Date());
        vmStatic.setVdsGroupId(vdsManager.getVdsGroupId());
        String vmNameOnHost = (String) vmInfo.get(VdsProperties.vm_name);

        if (StringUtils.equals(
            Config.<String>getValue(ConfigValues.HostedEngineVmName), vmNameOnHost)) {
          // its a hosted engine VM -> import it and skip the external VM phase
          importHostedEngineVM(vmInfo);
          continue;
        } else {
          vmStatic.setName(String.format(EXTERNAL_VM_NAME_FORMAT, vmNameOnHost));
          vmStatic.setOrigin(OriginType.EXTERNAL);
        }

        vmStatic.setNumOfSockets(
            VdsBrokerObjectsBuilder.parseIntVdsProperty(vmInfo.get(VdsProperties.num_of_cpus)));
        vmStatic.setMemSizeMb(
            VdsBrokerObjectsBuilder.parseIntVdsProperty(vmInfo.get(VdsProperties.mem_size_mb)));
        vmStatic.setSingleQxlPci(false);

        externalVmsToAdd.add(vmStatic);
        log.info(
            "Importing VM '{}' as '{}', as it is running on the on Host, but does not exist in the engine.",
            vmNameOnHost,
            vmStatic.getName());
      }
    }
  }
コード例 #6
0
  /**
   * Update the given VM with the (static) data that is contained in the configuration. The {@link
   * VM#getImages()} will contain the images that were read from the configuration.
   *
   * @param vm The VM to update.
   * @param configuration The configuration to update from.
   * @return In case of a problem reading the configuration, <code>false</code>. Otherwise, <code>
   *     true</code>.
   */
  public boolean updateVmFromConfiguration(VM vm, String configuration) {

    try {
      VmStatic oldVmStatic = vm.getStaticData();
      RefObject<VM> vmRef = new RefObject<VM>();
      RefObject<ArrayList<DiskImage>> imagesRef = new RefObject<ArrayList<DiskImage>>();
      RefObject<ArrayList<VmNetworkInterface>> interfacesRef =
          new RefObject<ArrayList<VmNetworkInterface>>();
      new OvfManager().ImportVm(configuration, vmRef, imagesRef, interfacesRef);
      new VMStaticOvfLogHandler(vmRef.argvalue.getStaticData()).resetDefaults(oldVmStatic);

      vm.setStaticData(vmRef.argvalue.getStaticData());
      vm.setImages(imagesRef.argvalue);
      vm.setInterfaces(interfacesRef.argvalue);

      // These fields are not saved in the OVF, so get them from the current VM.
      vm.setdedicated_vm_for_vds(oldVmStatic.getdedicated_vm_for_vds());
      vm.setiso_path(oldVmStatic.getiso_path());
      vm.setvds_group_id(oldVmStatic.getvds_group_id());
      // The VM configuration does not hold the vds group Id.
      // It is necessary to fetch the vm static from the Db, in order to get this information
      VmStatic vmStaticFromDb = getVmStaticDao().get(vm.getId());
      if (vmStaticFromDb != null) {
        VDSGroup vdsGroup = getVdsGroupDao().get(vmStaticFromDb.getvds_group_id());
        if (vdsGroup != null) {
          vm.setvds_group_compatibility_version(vdsGroup.getcompatibility_version());
          vm.setvds_group_name(vdsGroup.getname());
          vm.setvds_group_cpu_name(vdsGroup.getcpu_name());
        }
      }
      return true;
    } catch (OvfReaderException e) {
      log.errorFormat("Failed to update VM from the configuration: {0}).", configuration, e);
      return false;
    }
  }