Esempio n. 1
0
  private static GraphicsDevice getCompatibleGraphics(
      VmDeviceType videoDeviceType, Version clusterVersion, VmBase vmBase) {
    GraphicsDevice graphicsDevice = null;
    GraphicsType compatibleType = null;

    OsRepository osRepository = SimpleDependencyInjector.getInstance().get(OsRepository.class);
    for (Pair<GraphicsType, DisplayType> graphicsDisplayPair :
        osRepository.getGraphicsAndDisplays(vmBase.getOsId(), clusterVersion)) {
      if (graphicsDisplayPair.getSecond().getDefaultVmDeviceType() == videoDeviceType) {
        compatibleType = graphicsDisplayPair.getFirst();

        // previously to spice+vnc, QXL was only used by spice, so prefer spice if available
        if (videoDeviceType == VmDeviceType.QXL && compatibleType == GraphicsType.SPICE) {
          break;
        }
      }
    }

    if (compatibleType != null) {
      graphicsDevice = new GraphicsDevice(compatibleType.getCorrespondingDeviceType());
      graphicsDevice.setId(new VmDeviceId(Guid.newGuid(), vmBase.getId()));
    }

    return graphicsDevice;
  }
Esempio n. 2
0
  @Test
  public void canAddVmWithVirtioScsiControllerNotSupportedOs() {
    VM vm = createVm();
    AddVmFromTemplateCommand<AddVmParameters> cmd = createVmFromTemplateCommand(vm);
    cluster = createCluster();
    vm.setClusterId(cluster.getId());

    mockStorageDomainDaoGetForStoragePool();
    mockVmTemplateDaoReturnVmTemplate();
    mockVerifyAddVM(cmd);
    mockConfig();
    mockMaxPciSlots();
    mockStorageDomainDaoGetAllStoragesForPool(20);
    mockUninterestingMethods(cmd);
    mockDisplayTypes(vm.getOs());
    mockGraphicsDevices(vm.getId());
    doReturn(true).when(cmd).checkCpuSockets();

    doReturn(cluster).when(cmd).getCluster();
    doReturn(createStoragePool()).when(cmd).getStoragePool();
    cmd.getParameters().setVirtioScsiEnabled(true);
    when(osRepository.isSoundDeviceEnabled(any(Integer.class), any(Version.class)))
        .thenReturn(true);
    when(osRepository.getArchitectureFromOS(any(Integer.class)))
        .thenReturn(ArchitectureType.x86_64);
    when(osRepository.getDiskInterfaces(any(Integer.class), any(Version.class)))
        .thenReturn(new ArrayList<>(Collections.singletonList("VirtIO")));
    mockGetAllSnapshots(cmd);

    cmd.initEffectiveCompatibilityVersion();
    ValidateTestUtils.runAndAssertValidateFailure(
        cmd, EngineMessage.ACTION_TYPE_FAILED_ILLEGAL_OS_TYPE_DOES_NOT_SUPPORT_VIRTIO_SCSI);
  }
 @Test
 public void validateFailedGuestOsIsNotSupported() {
   mockInterfaceList();
   VM vm = mockVmStatusUp();
   vm.setVmOs(15); // rhel3x64
   createVirtIODisk();
   when(osRepository.getOsName(15)).thenReturn("RHEL3x64");
   when(osRepository.getDiskHotpluggableInterfaces(any(Integer.class), any(Version.class)))
       .thenReturn(Collections.emptySet());
   ValidateTestUtils.runAndAssertValidateFailure(
       command, EngineMessage.ACTION_TYPE_FAILED_GUEST_OS_VERSION_IS_NOT_SUPPORTED);
 }
Esempio n. 4
0
 @Override
 protected void readOsSection(XmlNode section) {
   _vmTemplate.setId(new Guid(section.attributes.get("ovf:id").getValue()));
   XmlNode node = section.SelectSingleNode("Description");
   if (node != null) {
     int osId = osRepository.getOsIdByUniqueName(node.innerText);
     _vmTemplate.setOsId(osId);
     _vmTemplate.setClusterArch(osRepository.getArchitectureFromOS(osId));
   } else {
     _vmTemplate.setClusterArch(ArchitectureType.undefined);
   }
 }
  @Before
  public void setUp() {
    mockVds();
    mockVmDevice(false);

    doReturn(snapshotsValidator).when(command).getSnapshotsValidator();
    doReturn(ValidationResult.VALID).when(snapshotsValidator).vmNotDuringSnapshot(any(Guid.class));
    doReturn(ValidationResult.VALID).when(snapshotsValidator).vmNotInPreview(any(Guid.class));

    doReturn(storageDomainValidator)
        .when(command)
        .getStorageDomainValidator(any(StorageDomain.class));
    doReturn(ValidationResult.VALID).when(storageDomainValidator).isDomainExistAndActive();

    doReturn(new ArrayList<>()).when(diskVmElementDao).getAllForVm(vmId);
    doReturn(diskValidator).when(command).getDiskValidator(disk);
    doReturn(diskVmElementValidator)
        .when(command)
        .getDiskVmElementValidator(any(Disk.class), any(DiskVmElement.class));
    doReturn(ValidationResult.VALID).when(diskValidator).isDiskExists();
    doReturn(ValidationResult.VALID).when(diskValidator).isDiskAttachedToVm(vm);

    when(osRepository.getDiskHotpluggableInterfaces(any(Integer.class), any(Version.class)))
        .thenReturn(new HashSet<>(DISK_HOTPLUGGABLE_INTERFACES));
    SimpleDependencyInjector.getInstance().bind(VmDeviceUtils.class, vmDeviceUtils);
  }
  protected void mockInterfaceList() {
    SimpleDependencyInjector.getInstance().bind(OsRepository.class, osRepository);

    ArrayList<String> diskInterfaces =
        new ArrayList<>(Arrays.asList(new String[] {"IDE", "VirtIO", "VirtIO_SCSI"}));

    when(osRepository.getDiskInterfaces(anyInt(), any(Version.class))).thenReturn(diskInterfaces);
  }
 @Test
 public void validateFailedVirtIODisk() throws Exception {
   mockVmStatusUp();
   mockInterfaceList();
   when(osRepository.getOsName(0)).thenReturn("RHEL6");
   createNotVirtIODisk();
   ValidateTestUtils.runAndAssertValidateFailure(
       command, EngineMessage.HOT_PLUG_IDE_DISK_IS_NOT_SUPPORTED);
 }
Esempio n. 8
0
 private void mockDisplayTypes(int osId) {
   Map<Integer, Map<Version, List<Pair<GraphicsType, DisplayType>>>> displayTypeMap =
       new HashMap<>();
   displayTypeMap.put(osId, new HashMap<>());
   displayTypeMap
       .get(osId)
       .put(null, Collections.singletonList(new Pair<>(GraphicsType.SPICE, DisplayType.qxl)));
   when(osRepository.getGraphicsAndDisplays()).thenReturn(displayTypeMap);
 }
Esempio n. 9
0
  private void mockOsRepositoryGraphics(
      int osId, Version ver, Pair<GraphicsType, DisplayType> supportedGraphicsAndDisplay) {
    Map<Version, List<Pair<GraphicsType, DisplayType>>> value = new HashMap<>();
    value.put(ver, Collections.singletonList(supportedGraphicsAndDisplay));

    Map<Integer, Map<Version, List<Pair<GraphicsType, DisplayType>>>> g = new HashMap<>();
    g.put(osId, value);
    when(osRepository.getGraphicsAndDisplays()).thenReturn(g);
  }
 protected void runAddAndVerify(
     VmNic iface,
     boolean reserveExistingMac,
     VerificationMode addMacVerification,
     int osId,
     Version version) {
   OsRepository osRepository = mock(OsRepository.class);
   when(vmInterfaceManager.getOsRepository()).thenReturn(osRepository);
   when(osRepository.hasNicHotplugSupport(any(Integer.class), any(Version.class)))
       .thenReturn(true);
   vmInterfaceManager.add(
       iface, NoOpCompensationContext.getInstance(), reserveExistingMac, osId, version);
   if (reserveExistingMac) {
     verify(macPoolManagerStrategy, times(1)).forceAddMac((iface.getMacAddress()));
   } else {
     verifyZeroInteractions(macPoolManagerStrategy);
   }
   verifyAddDelegatedCorrectly(iface, addMacVerification);
 }
Esempio n. 11
0
  @Test
  public void refuseSoundDeviceOnPPC() {
    AddVmCommand<AddVmParameters> cmd = setupCanAddPpcTest();
    cmd.getParameters().setSoundDeviceEnabled(true);
    when(osRepository.isSoundDeviceEnabled(
            cmd.getParameters().getVm().getVmOsId(), cmd.getCluster().getCompatibilityVersion()))
        .thenReturn(false);

    ValidateTestUtils.runAndAssertValidateFailure(
        cmd, EngineMessage.SOUND_DEVICE_REQUESTED_ON_NOT_SUPPORTED_ARCH);
  }
  private String getTimeZoneForVm(VM vm) {
    if (!StringUtils.isEmpty(vm.getTimeZone())) {
      return vm.getTimeZone();
    }

    // else fallback to engine config default for given OS type
    if (osRepository.isWindows(vm.getOs())) {
      return Config.<String>getValue(ConfigValues.DefaultWindowsTimeZone);
    } else {
      return "Etc/GMT";
    }
  }
Esempio n. 13
0
 private void setDeviceByResource(XmlNode node, VmDevice vmDevice) {
   int resourceType = getResourceType(node, OvfProperties.VMD_RESOURCE_TYPE);
   int resourceSubType = getResourceType(node, OvfProperties.VMD_SUB_RESOURCE_TYPE);
   if (resourceSubType == -1) {
     // we need special handling for Monitor to define it as vnc or spice
     if (Integer.parseInt(OvfHardware.Monitor) == resourceType) {
       // if default display type is defined in the ovf, set the video device that is suitable for
       // it
       if (defaultDisplayType != null) {
         vmDevice.setDevice(defaultDisplayType.getDefaultVmDeviceType().getName());
       } else {
         // get number of monitors from VirtualQuantity in OVF
         if (selectSingleNode(node, OvfProperties.VMD_VIRTUAL_QUANTITY, _xmlNS) != null
             && !StringUtils.isEmpty(
                 selectSingleNode(node, OvfProperties.VMD_VIRTUAL_QUANTITY, _xmlNS).innerText)) {
           int virtualQuantity =
               Integer.parseInt(
                   selectSingleNode(node, OvfProperties.VMD_VIRTUAL_QUANTITY, _xmlNS).innerText);
           if (virtualQuantity > 1) {
             vmDevice.setDevice(VmDeviceType.QXL.getName());
           } else {
             // get first supported display device
             List<Pair<GraphicsType, DisplayType>> supportedGraphicsAndDisplays =
                 osRepository.getGraphicsAndDisplays(vmBase.getOsId(), new Version(getVersion()));
             if (!supportedGraphicsAndDisplays.isEmpty()) {
               DisplayType firstDisplayType = supportedGraphicsAndDisplays.get(0).getSecond();
               vmDevice.setDevice(firstDisplayType.getDefaultVmDeviceType().getName());
             } else {
               vmDevice.setDevice(VmDeviceType.QXL.getName());
             }
           }
         } else { // default to spice if quantity not found
           vmDevice.setDevice(VmDeviceType.QXL.getName());
         }
       }
     } else {
       vmDevice.setDevice(VmDeviceType.getoVirtDevice(resourceType).getName());
     }
   } else if (Integer.parseInt(OvfHardware.Network) == resourceType) {
     // handle interfaces with different sub types : we have 0-5 as the VmInterfaceType enum
     VmInterfaceType nicType = VmInterfaceType.forValue(resourceSubType);
     if (nicType != null) {
       if (nicType == VmInterfaceType.pciPassthrough) {
         vmDevice.setDevice(VmDeviceType.HOST_DEVICE.getName());
       } else {
         vmDevice.setDevice(VmDeviceType.BRIDGE.getName());
       }
     } else {
       vmDevice.setDevice(VmDeviceType.getoVirtDevice(resourceType).getName());
     }
   }
 }
Esempio n. 14
0
 @Test
 public void isVirtioScsiEnabledDefaultedToTrue() {
   AddVmCommand<AddVmParameters> cmd = setupCanAddVmTests(0);
   Cluster cluster = createCluster();
   doReturn(cluster).when(cmd).getCluster();
   cmd.getParameters().getVm().setClusterId(cluster.getId());
   cmd.initEffectiveCompatibilityVersion();
   when(osRepository.getDiskInterfaces(any(Integer.class), any(Version.class)))
       .thenReturn(new ArrayList<>(Collections.singletonList("VirtIO_SCSI")));
   assertTrue(
       "isVirtioScsiEnabled hasn't been defaulted to true on cluster >= 3.3.",
       cmd.isVirtioScsiEnabled());
 }
Esempio n. 15
0
  private void addDefaultGraphicsDevice() {
    VmDevice device =
        VmDeviceCommonUtils.findVmDeviceByGeneralType(
            vmBase.getManagedDeviceMap(), VmDeviceGeneralType.GRAPHICS);
    if (device != null) {
      return;
    }

    List<Pair<GraphicsType, DisplayType>> graphicsAndDisplays =
        osRepository.getGraphicsAndDisplays(vmBase.getOsId(), new Version(getVersion()));
    GraphicsType graphicsType =
        vmBase.getDefaultDisplayType() == DisplayType.cirrus
            ? GraphicsType.VNC
            : GraphicsType.SPICE;
    GraphicsType supportedGraphicsType = null;
    for (Pair<GraphicsType, DisplayType> pair : graphicsAndDisplays) {
      if (pair.getSecond() == vmBase.getDefaultDisplayType()) {
        if (pair.getFirst() == graphicsType) {
          supportedGraphicsType = graphicsType;
          break;
        }
        if (supportedGraphicsType == null) {
          supportedGraphicsType = pair.getFirst();
        }
      }
    }
    if (supportedGraphicsType != null) {
      device = new GraphicsDevice(supportedGraphicsType.getCorrespondingDeviceType());
      device.setId(new VmDeviceId(Guid.newGuid(), vmBase.getId()));
      addManagedVmDevice(device);
    } else {
      log.warn(
          "Cannot find any graphics type for display type {} supported by OS {} in compatibility version {}",
          vmBase.getDefaultDisplayType().name(),
          osRepository.getOsName(vmBase.getOsId()),
          getVersion());
    }
  }
Esempio n. 16
0
  @Test
  public void testUnsupportedCpus() {
    // prepare a command to pass validate
    VM vm = createVm();
    vm.setVmOs(OsRepository.DEFAULT_X86_OS);
    cluster = createCluster();
    vm.setClusterId(cluster.getId());
    when(clusterDao.get(cluster.getId())).thenReturn(cluster);

    AddVmFromTemplateCommand<AddVmParameters> cmd = createVmFromTemplateCommand(vm);

    mockStorageDomainDaoGetForStoragePool();
    mockVmTemplateDaoReturnVmTemplate();
    mockVerifyAddVM(cmd);
    mockConfig();
    mockMaxPciSlots();
    mockStorageDomainDaoGetAllStoragesForPool(20);
    mockDisplayTypes(vm.getOs());
    mockUninterestingMethods(cmd);
    mockGetAllSnapshots(cmd);
    when(osRepository.getArchitectureFromOS(0)).thenReturn(ArchitectureType.x86_64);
    doReturn(createStoragePool()).when(cmd).getStoragePool();

    // prepare the mock values
    Map<Pair<Integer, Version>, Set<String>> unsupported = new HashMap<>();
    Set<String> value = new HashSet<>();
    value.add(CPU_ID);
    unsupported.put(new Pair<>(vm.getVmOsId(), cluster.getCompatibilityVersion()), value);

    when(osRepository.isCpuSupported(vm.getVmOsId(), cluster.getCompatibilityVersion(), CPU_ID))
        .thenReturn(false);
    when(osRepository.getUnsupportedCpus()).thenReturn(unsupported);

    ValidateTestUtils.runAndAssertValidateFailure(
        cmd, EngineMessage.CPU_TYPE_UNSUPPORTED_FOR_THE_GUEST_OS);
  }
  protected void buildVmTimeZone() {
    // get vm timezone
    String timeZone = getTimeZoneForVm(vm);

    String javaZoneId = null;
    if (osRepository.isWindows(vm.getOs())) {
      // convert to java & calculate offset
      javaZoneId = WindowsJavaTimezoneMapping.windowsToJava.get(timeZone);
    } else {
      javaZoneId = timeZone;
    }

    int offset = 0;
    if (javaZoneId != null) {
      offset = (TimeZone.getTimeZone(javaZoneId).getOffset(new Date().getTime()) / 1000);
    }
    createInfo.put(VdsProperties.utc_diff, "" + offset);
  }
  @Test
  public void testLunDiskWithSgioCanBeAdded() {
    LunDisk disk = createISCSILunDisk();
    disk.setDiskInterface(DiskInterface.VirtIO_SCSI);
    disk.setSgio(ScsiGenericIO.UNFILTERED);

    AddDiskParameters parameters = createParameters();
    parameters.setDiskInfo(disk);
    initializeCommand(Guid.newGuid(), parameters);

    VM vm = mockVm();
    vm.setVdsGroupCompatibilityVersion(Version.v3_3);
    mockMaxPciSlots();

    when(osRepository.getDiskInterfaces(any(Integer.class), any(Version.class)))
        .thenReturn(new ArrayList<>(Arrays.asList("VirtIO_SCSI")));

    DiskValidator diskValidator = spyDiskValidator(disk);
    doReturn(true).when(diskValidator).isVirtioScsiControllerAttached(any(Guid.class));

    mockInterfaceList();

    CanDoActionTestUtils.runAndAssertCanDoActionSuccess(command);
  }
  @Test
  public void testVirtIoScsiNotSupportedByOs() {
    DiskImage disk = createVirtIoScsiDiskImage();
    AddDiskParameters parameters = createParameters();
    parameters.setDiskInfo(disk);

    Guid storageId = Guid.newGuid();
    initializeCommand(storageId, parameters);
    mockStorageDomain(storageId);
    mockStoragePoolIsoMap();

    VM vm = mockVm();
    vm.setVdsGroupCompatibilityVersion(Version.v3_3);
    mockMaxPciSlots();

    when(osRepository.getDiskInterfaces(any(Integer.class), any(Version.class)))
        .thenReturn(new ArrayList<>(Arrays.asList("VirtIO")));

    DiskValidator diskValidator = spyDiskValidator(disk);
    doReturn(true).when(diskValidator).isVirtioScsiControllerAttached(any(Guid.class));

    CanDoActionTestUtils.runAndAssertCanDoActionFailure(
        command, EngineMessage.ACTION_TYPE_FAILED_GUEST_OS_VERSION_IS_NOT_SUPPORTED);
  }
  protected void mockInterfaceList() {
    ArrayList<String> diskInterfaces =
        new ArrayList<>(Arrays.asList(new String[] {"IDE", "VirtIO", "VirtIO_SCSI"}));

    when(osRepository.getDiskInterfaces(anyInt(), any(Version.class))).thenReturn(diskInterfaces);
  }
  protected void buildVmProperties() {
    createInfo.put(VdsProperties.vm_guid, vm.getId().toString());
    createInfo.put(VdsProperties.vm_name, vm.getName());
    createInfo.put(VdsProperties.mem_size_mb, vm.getVmMemSizeMb());
    createInfo.put(VdsProperties.mem_guaranteed_size_mb, vm.getMinAllocatedMem());
    createInfo.put(VdsProperties.smartcardEnabled, Boolean.toString(vm.isSmartcardEnabled()));
    createInfo.put(VdsProperties.num_of_cpus, String.valueOf(vm.getNumOfCpus()));
    if (Config.<Boolean>getValue(ConfigValues.SendSMPOnRunVm)) {
      createInfo.put(VdsProperties.cores_per_socket, (Integer.toString(vm.getCpuPerSocket())));
      if (FeatureSupported.supportedInConfig(
          ConfigValues.HotPlugCpuSupported,
          vm.getVdsGroupCompatibilityVersion(),
          vm.getClusterArch())) {
        createInfo.put(
            VdsProperties.max_number_of_cpus,
            String.valueOf(
                Config.<Integer>getValue(
                    ConfigValues.MaxNumOfVmCpus, vm.getVdsGroupCompatibilityVersion().getValue())));
      }
    }
    final String compatibilityVersion = vm.getVdsGroupCompatibilityVersion().toString();
    addCpuPinning(compatibilityVersion);
    createInfo.put(VdsProperties.emulatedMachine, getVdsGroup().getEmulatedMachine());
    // send cipher suite and spice secure channels parameters only if ssl
    // enabled.
    if (Config.<Boolean>getValue(ConfigValues.SSLEnabled)) {
      createInfo.put(
          VdsProperties.spiceSslCipherSuite, Config.<String>getValue(ConfigValues.CipherSuite));
      createInfo.put(
          VdsProperties.SpiceSecureChannels,
          Config.<String>getValue(ConfigValues.SpiceSecureChannels, compatibilityVersion));
    }
    createInfo.put(VdsProperties.kvmEnable, vm.getKvmEnable().toString().toLowerCase());
    createInfo.put(VdsProperties.acpiEnable, vm.getAcpiEnable().toString().toLowerCase());

    createInfo.put(
        VdsProperties.Custom,
        VmPropertiesUtils.getInstance()
            .getVMProperties(vm.getVdsGroupCompatibilityVersion(), vm.getStaticData()));
    createInfo.put(VdsProperties.vm_type, "kvm"); // "qemu", "kvm"
    if (vm.isRunAndPause()) {
      createInfo.put(VdsProperties.launch_paused_param, "true");
    }
    if (vm.isUseHostCpuFlags()) {
      createInfo.put(VdsProperties.cpuType, "hostPassthrough");
    } else if (vm.getVdsGroupCpuFlagsData() != null) {
      createInfo.put(VdsProperties.cpuType, vm.getVdsGroupCpuFlagsData());
    }
    createInfo.put(VdsProperties.niceLevel, String.valueOf(vm.getNiceLevel()));
    if (vm.getCpuShares() > 0) {
      createInfo.put(VdsProperties.cpuShares, String.valueOf(vm.getCpuShares()));
    }
    if (!StringUtils.isEmpty(vm.getHibernationVolHandle())) {
      createInfo.put(VdsProperties.hiberVolHandle, vm.getHibernationVolHandle());
    }

    String keyboardLayout = vm.getDynamicData().getVncKeyboardLayout();
    if (keyboardLayout == null) {
      keyboardLayout = vm.getDefaultVncKeyboardLayout();
      if (keyboardLayout == null) {
        keyboardLayout = Config.<String>getValue(ConfigValues.VncKeyboardLayout);
      }
    }

    createInfo.put(VdsProperties.KeyboardLayout, keyboardLayout);
    if (osRepository.isLinux(vm.getVmOsId())) {
      createInfo.put(VdsProperties.PitReinjection, "false");
    }

    if (vm.getDisplayType() == DisplayType.vnc) {
      createInfo.put(VdsProperties.TabletEnable, "true");
    }
    createInfo.put(
        VdsProperties.transparent_huge_pages, vm.isTransparentHugePages() ? "true" : "false");
  }
Esempio n. 22
0
 protected void mockOsRepository() {
   SimpleDependencyInjector.getInstance().bind(OsRepository.class, osRepository);
   VmHandler.init();
   when(osRepository.isWindows(0)).thenReturn(true);
   when(osRepository.isCpuSupported(anyInt(), any(Version.class), anyString())).thenReturn(true);
 }
Esempio n. 23
0
  protected void readGeneralData() {
    XmlNode content = selectSingleNode(_document, "//*/Content");
    XmlNode node;
    vmBase.setVmInit(new VmInit());

    // set ovf version to the ovf object
    vmBase.setOvfVersion(getVersion());

    node = selectSingleNode(content, OvfProperties.DESCRIPTION);
    if (node != null) {
      vmBase.setDescription(node.innerText);
    }

    node = selectSingleNode(content, OvfProperties.COMMENT);
    if (node != null) {
      vmBase.setComment(node.innerText);
    }

    node = selectSingleNode(content, OvfProperties.DOMAIN);
    if (node != null) {
      vmBase.getVmInit().setDomain(node.innerText);
    }

    node = selectSingleNode(content, OvfProperties.CREATION_DATE);
    if (node != null) {
      Date creationDate = OvfParser.utcDateStringToLocaDate(node.innerText);
      if (creationDate != null) {
        vmBase.setCreationDate(creationDate);
      }
    }

    node = selectSingleNode(content, OvfProperties.EXPORT_DATE);
    if (node != null) {
      Date exportDate = OvfParser.utcDateStringToLocaDate(node.innerText);
      if (exportDate != null) {
        vmBase.setExportDate(exportDate);
      }
    }

    node = selectSingleNode(content, OvfProperties.DEFAULT_BOOT_SEQUENCE);
    if (node != null) {
      if (!StringUtils.isEmpty(node.innerText)) {
        vmBase.setDefaultBootSequence(BootSequence.forValue(Integer.parseInt(node.innerText)));
      }
    }

    node = selectSingleNode(content, OvfProperties.INITRD_URL);
    if (node != null) {
      if (!StringUtils.isEmpty(node.innerText)) {
        vmBase.setInitrdUrl(node.innerText);
      }
    }

    node = selectSingleNode(content, OvfProperties.KERNEL_URL);
    if (node != null) {
      if (!StringUtils.isEmpty(node.innerText)) {
        vmBase.setKernelUrl(node.innerText);
      }
    }

    node = selectSingleNode(content, OvfProperties.KERNEL_PARAMS);
    if (node != null) {
      if (!StringUtils.isEmpty(node.innerText)) {
        vmBase.setKernelParams(node.innerText);
      }
    }

    node = selectSingleNode(content, OvfProperties.GENERATION);
    if (node != null) {
      vmBase.setDbGeneration(Long.parseLong(node.innerText));
    } else {
      vmBase.setDbGeneration(1L);
    }

    node = selectSingleNode(content, OvfProperties.CUSTOM_COMPATIBILITY_VERSION);
    if (node != null) {
      vmBase.setCustomCompatibilityVersion(new Version(node.innerText));
    }

    Version originVersion = new Version(getVersion()); // the originating ENGINE version
    node = selectSingleNode(content, OvfProperties.CLUSTER_COMPATIBILITY_VERSION);
    if (node != null) {
      originVersion = new Version(node.innerText);
    }
    vmBase.setClusterCompatibilityVersionOrigin(originVersion);

    // Note: the fetching of 'default display type' should happen before reading
    // the hardware section
    node = selectSingleNode(content, getDefaultDisplayTypeStringRepresentation());
    if (node != null) {
      if (!StringUtils.isEmpty(node.innerText)) {
        vmBase.setDefaultDisplayType(DisplayType.forValue(Integer.parseInt(node.innerText)));
      }
    }

    XmlNodeList list = selectNodes(content, "Section");

    if (list != null) {
      // The Os need to be read before the hardware
      node = getNode(list, "xsi:type", "ovf:OperatingSystemSection_Type");
      if (node != null) {
        readOsSection(node);
        if (!osRepository.isLinux(vmBase.getOsId())
            || vmBase.getDefaultDisplayType() != DisplayType.qxl) {
          vmBase.setSingleQxlPci(false);
        }
      }

      node = getNode(list, "xsi:type", "ovf:VirtualHardwareSection_Type");
      if (node != null) {
        readHardwareSection(node);
      }

      node = getNode(list, "xsi:type", "ovf:SnapshotsSection_Type");
      if (node != null) {
        readSnapshotsSection(node);
      }
    }

    // after reading the hardware section, if graphics device is still absent, add a default one
    addDefaultGraphicsDevice();
    // if boot order is not set, figure out some default based on the set of bootable disks
    setDefaultBootDevice();

    // due to dependency on vmBase.getOsId() must be read AFTER readOsSection
    node = selectSingleNode(content, OvfProperties.TIMEZONE);
    if (node != null && StringUtils.isNotEmpty(node.innerText)) {
      vmBase.setTimeZone(node.innerText);
    } else {
      if (osRepository.isWindows(vmBase.getOsId())) {
        vmBase.setTimeZone(Config.<String>getValue(ConfigValues.DefaultWindowsTimeZone));
      } else {
        vmBase.setTimeZone(Config.<String>getValue(ConfigValues.DefaultGeneralTimeZone));
      }
    }

    node = selectSingleNode(content, OvfProperties.ORIGIN);
    if (node != null) {
      if (!StringUtils.isEmpty(node.innerText)) {
        vmBase.setOrigin(OriginType.forValue(Integer.parseInt(node.innerText)));
      }
    }

    node = selectSingleNode(content, OvfProperties.VM_TYPE);
    if (node != null) {
      if (!StringUtils.isEmpty(node.innerText)) {
        vmBase.setVmType(VmType.forValue(Integer.parseInt(node.innerText)));
      }
    }

    node = selectSingleNode(content, OvfProperties.IS_SMARTCARD_ENABLED);
    if (node != null) {
      if (!StringUtils.isEmpty(node.innerText)) {
        vmBase.setSmartcardEnabled(Boolean.parseBoolean(node.innerText));
      }
    }

    node = selectSingleNode(content, OvfProperties.NUM_OF_IOTHREADS);
    if (node != null) {
      if (!StringUtils.isEmpty(node.innerText)) {
        vmBase.setNumOfIoThreads(Integer.parseInt(node.innerText));
      }
    }

    node = selectSingleNode(content, OvfProperties.DELETE_PROTECTED);
    if (node != null) {
      if (!StringUtils.isEmpty(node.innerText)) {
        vmBase.setDeleteProtected(Boolean.parseBoolean(node.innerText));
      }
    }

    node = selectSingleNode(content, OvfProperties.SSO_METHOD);
    if (node != null) {
      if (!StringUtils.isEmpty(node.innerText)) {
        vmBase.setSsoMethod(SsoMethod.fromString(node.innerText));
      }
    }

    node = selectSingleNode(content, OvfProperties.TUNNEL_MIGRATION);
    if (node != null) {
      if (!StringUtils.isEmpty(node.innerText)) {
        vmBase.setTunnelMigration(Boolean.parseBoolean(node.innerText));
      }
    }

    node = selectSingleNode(content, OvfProperties.VNC_KEYBOARD_LAYOUT);
    if (node != null) {
      if (!StringUtils.isEmpty(node.innerText)) {
        vmBase.setVncKeyboardLayout(node.innerText);
      }
    }

    node = selectSingleNode(content, OvfProperties.MIN_ALLOCATED_MEMORY);
    if (node != null) {
      if (StringUtils.isNotEmpty(node.innerText)) {
        vmBase.setMinAllocatedMem(Integer.parseInt(node.innerText));
      }
    }

    node = selectSingleNode(content, OvfProperties.IS_STATELESS);
    if (node != null) {
      if (StringUtils.isNotEmpty(node.innerText)) {
        vmBase.setStateless(Boolean.parseBoolean(node.innerText));
      }
    }

    node = selectSingleNode(content, OvfProperties.IS_RUN_AND_PAUSE);
    if (node != null) {
      if (StringUtils.isNotEmpty(node.innerText)) {
        vmBase.setRunAndPause(Boolean.parseBoolean(node.innerText));
      }
    }

    node = selectSingleNode(content, OvfProperties.CREATED_BY_USER_ID);
    if (node != null) {
      if (StringUtils.isNotEmpty(node.innerText)) {
        vmBase.setCreatedByUserId(Guid.createGuidFromString(node.innerText));
      }
    }

    node = selectSingleNode(content, OvfProperties.MIGRATION_DOWNTIME);
    if (node != null) {
      if (StringUtils.isNotEmpty(node.innerText)) {
        vmBase.setMigrationDowntime(Integer.parseInt(node.innerText));
      }
    }

    node = selectSingleNode(content, OvfProperties.MIGRATION_SUPPORT);
    if (node != null) {
      if (StringUtils.isNotEmpty(node.innerText)) {
        MigrationSupport migrationSupport =
            MigrationSupport.forValue(Integer.parseInt(node.innerText));
        vmBase.setMigrationSupport(migrationSupport);
      }
    }

    // TODO dedicated to multiple hosts
    readDedicatedHostsList();

    node = selectSingleNode(content, OvfProperties.SERIAL_NUMBER_POLICY);
    if (node != null) {
      if (StringUtils.isNotEmpty(node.innerText)) {
        vmBase.setSerialNumberPolicy(SerialNumberPolicy.forValue(Integer.parseInt(node.innerText)));
      }
    }

    node = selectSingleNode(content, OvfProperties.CUSTOM_SERIAL_NUMBER);
    if (node != null) {
      if (StringUtils.isNotEmpty(node.innerText)) {
        vmBase.setCustomSerialNumber(node.innerText);
      }
    }

    node = selectSingleNode(content, OvfProperties.AUTO_STARTUP);
    if (node != null) {
      vmBase.setAutoStartup(Boolean.parseBoolean(node.innerText));
    }

    node = selectSingleNode(content, OvfProperties.PRIORITY);
    if (node != null) {
      vmBase.setPriority(Integer.parseInt(node.innerText));
    }

    node = selectSingleNode(content, OvfProperties.IS_BOOT_MENU_ENABLED);
    if (node != null) {
      vmBase.setBootMenuEnabled(Boolean.parseBoolean(node.innerText));
    }

    node = selectSingleNode(content, OvfProperties.IS_SPICE_FILE_TRANSFER_ENABLED);
    if (node != null) {
      vmBase.setSpiceFileTransferEnabled(Boolean.parseBoolean(node.innerText));
    }

    node = selectSingleNode(content, OvfProperties.IS_SPICE_COPY_PASTE_ENABLED);
    if (node != null) {
      vmBase.setSpiceCopyPasteEnabled(Boolean.parseBoolean(node.innerText));
    }

    node = selectSingleNode(content, OvfProperties.ALLOW_CONSOLE_RECONNECT);
    if (node != null) {
      vmBase.setAllowConsoleReconnect(Boolean.parseBoolean(node.innerText));
    }

    node = selectSingleNode(content, OvfProperties.IS_AUTO_CONVERGE);
    if (node != null) {
      if (StringUtils.isNotEmpty(node.innerText)) {
        vmBase.setAutoConverge(Boolean.parseBoolean(node.innerText));
      }
    }

    node = selectSingleNode(content, OvfProperties.IS_MIGRATE_COMPRESSED);
    if (node != null) {
      if (StringUtils.isNotEmpty(node.innerText)) {
        vmBase.setMigrateCompressed(Boolean.parseBoolean(node.innerText));
      }
    }

    node = selectSingleNode(content, OvfProperties.MIGRATION_POLICY_ID);
    if (node != null) {
      if (StringUtils.isNotEmpty(node.innerText)) {
        vmBase.setMigrationPolicyId(Guid.createGuidFromString(node.innerText));
      }
    }

    node = selectSingleNode(content, OvfProperties.CUSTOM_EMULATED_MACHINE);
    if (node != null) {
      if (StringUtils.isNotEmpty(node.innerText)) {
        vmBase.setCustomEmulatedMachine(node.innerText);
      }
    }

    node = selectSingleNode(content, OvfProperties.CUSTOM_CPU_NAME);
    if (node != null) {
      if (StringUtils.isNotEmpty(node.innerText)) {
        vmBase.setCustomCpuName(node.innerText);
      }
    }

    node = selectSingleNode(content, OvfProperties.PREDEFINED_PROPERTIES);
    if (node != null) {
      if (StringUtils.isNotEmpty(node.innerText)) {
        vmBase.setPredefinedProperties(node.innerText);
      }
    }

    node = selectSingleNode(content, OvfProperties.USER_DEFINED_PROPERTIES);
    if (node != null) {
      if (StringUtils.isNotEmpty(node.innerText)) {
        vmBase.setUserDefinedProperties(node.innerText);
      }
    }

    node = selectSingleNode(content, OvfProperties.MAX_MEMORY_SIZE_MB);
    if (node != null) {
      if (StringUtils.isNotEmpty(node.innerText)) {
        vmBase.setMaxMemorySizeMb(Integer.parseInt(node.innerText));
      }
    }

    vmBase.setCustomProperties(
        VmPropertiesUtils.getInstance()
            .customProperties(vmBase.getPredefinedProperties(), vmBase.getUserDefinedProperties()));

    node = selectSingleNode(content, OvfProperties.VM_LEASE);
    if (node != null) {
      if (StringUtils.isNotEmpty(node.innerText)) {
        vmBase.setLeaseStorageDomainId(new Guid(node.innerText));
      }
    }

    readGeneralData(content);

    readVmInit(content);
  }