summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Bentele2021-05-06 11:30:01 +0200
committerManuel Bentele2021-05-06 11:30:01 +0200
commit1e42460bde25ccabf5cb7e4d3149a9e50ce2b03c (patch)
treed7578062cbbc6b8461237e11fe5e6cd0bb35c0b5
parentUpdate XML schema for VirtualBox virtualization configurations (diff)
downloadmaster-sync-shared-1e42460bde25ccabf5cb7e4d3149a9e50ce2b03c.tar.gz
master-sync-shared-1e42460bde25ccabf5cb7e4d3149a9e50ce2b03c.tar.xz
master-sync-shared-1e42460bde25ccabf5cb7e4d3149a9e50ce2b03c.zip
Optimize OS detection for Libvirt/QEMU virtualization configurations
-rw-r--r--src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java10
-rw-r--r--src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemuUtils.java100
2 files changed, 108 insertions, 2 deletions
diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java
index e844e4e..b4bc0ba 100644
--- a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java
+++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java
@@ -325,11 +325,17 @@ public class VirtualizationConfigurationQemu extends
if ( osLookup != null ) {
// operating system entry was found
// so determine OpenSLX OS name with the smallest distance to the libosinfo OS name
- final LevenshteinDistance distance = new LevenshteinDistance( 1, 1, 1 );
+ final LevenshteinDistance distance = new LevenshteinDistance( 2, 1, 1 );
int smallestDistance = Integer.MAX_VALUE;
// get name of the OS and combine it with the optional available architecture
- final String osLookupOsName = osLookup.getName() + " " + this.vmConfig.getOsArch();
+ String osLookupOsName = osLookup.getName();
+ final int osArchSize = VirtualizationConfigurationQemuUtils.getOsArchSize( this.vmConfig.getOsArch() );
+
+ if ( osArchSize > 0 ) {
+ // append architecture size in bit if information is available from the specified architecture
+ osLookupOsName += " (" + osArchSize + " Bit)";
+ }
for ( final OperatingSystem osCandidate : this.osList ) {
final int currentDistance = distance.calculateDistance( osLookupOsName, osCandidate.getOsName() );
diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemuUtils.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemuUtils.java
index 0288029..5d74d0d 100644
--- a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemuUtils.java
+++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemuUtils.java
@@ -338,4 +338,104 @@ public class VirtualizationConfigurationQemuUtils
{
return String.format( "%d.%d", version.getMajor(), version.getMinor() );
}
+
+ /**
+ * Returns the size of a given architecture {@link String}.
+ *
+ * @param osArch Libvirt/QEMU machine architecture as {@link String}.
+ * @return Size of the Libvirt/QEMU machine architecture.
+ */
+ public static int getOsArchSize( String osArch )
+ {
+ final int archSize;
+
+ if ( osArch == null || osArch.isEmpty() ) {
+ archSize = 0;
+ } else {
+ switch ( osArch ) {
+ case "alpha":
+ archSize = 64;
+ break;
+ case "armv6l":
+ archSize = 32;
+ break;
+ case "armv7l":
+ archSize = 32;
+ break;
+ case "aarch64":
+ archSize = 64;
+ break;
+ case "cris":
+ archSize = 32;
+ break;
+ case "i686":
+ archSize = 32;
+ break;
+ case "m68k":
+ archSize = 32;
+ break;
+ case "microblaze":
+ archSize = 32;
+ break;
+ case "microblazeel":
+ archSize = 32;
+ break;
+ case "mips":
+ archSize = 32;
+ break;
+ case "mipsel":
+ archSize = 32;
+ break;
+ case "mips64":
+ archSize = 64;
+ break;
+ case "mips64el":
+ archSize = 64;
+ break;
+ case "ppc":
+ archSize = 32;
+ break;
+ case "ppc64":
+ archSize = 64;
+ break;
+ case "ppc64le":
+ archSize = 64;
+ break;
+ case "riscv32":
+ archSize = 32;
+ break;
+ case "riscv64":
+ archSize = 64;
+ break;
+ case "s390x":
+ archSize = 64;
+ break;
+ case "sh4":
+ archSize = 32;
+ break;
+ case "sh4eb":
+ archSize = 64;
+ break;
+ case "sparc":
+ archSize = 32;
+ break;
+ case "sparc64":
+ archSize = 64;
+ break;
+ case "x86_64":
+ archSize = 64;
+ break;
+ case "xtensa":
+ archSize = 32;
+ break;
+ case "xtensaeb":
+ archSize = 32;
+ break;
+ default:
+ archSize = 0;
+ }
+ }
+
+ return archSize;
+ }
}