diff options
author | Manuel Bentele | 2021-04-12 10:54:57 +0200 |
---|---|---|
committer | Manuel Bentele | 2021-04-12 10:54:57 +0200 |
commit | acf39f2540affb287d6222b82fbc913f8c86d709 (patch) | |
tree | 09fc8759e560a292b2778f6ec52961e9c8208c66 | |
parent | Removed invalid symbol in function call syntax (diff) | |
download | master-sync-shared-acf39f2540affb287d6222b82fbc913f8c86d709.tar.gz master-sync-shared-acf39f2540affb287d6222b82fbc913f8c86d709.tar.xz master-sync-shared-acf39f2540affb287d6222b82fbc913f8c86d709.zip |
Fix issue in VmMetaData factory method wrt. QemuMetaData class
-rw-r--r-- | src/main/java/org/openslx/vm/QemuMetaData.java | 40 | ||||
-rw-r--r-- | src/main/java/org/openslx/vm/VboxMetaData.java | 1 | ||||
-rw-r--r-- | src/main/java/org/openslx/vm/VmMetaData.java | 32 | ||||
-rw-r--r-- | src/main/java/org/openslx/vm/VmwareMetaData.java | 2 |
4 files changed, 53 insertions, 22 deletions
diff --git a/src/main/java/org/openslx/vm/QemuMetaData.java b/src/main/java/org/openslx/vm/QemuMetaData.java index bd288a4..3209925 100644 --- a/src/main/java/org/openslx/vm/QemuMetaData.java +++ b/src/main/java/org/openslx/vm/QemuMetaData.java @@ -282,6 +282,7 @@ public class QemuMetaData extends * * @param osList list of operating systems. * @param file image file for the QEMU hypervisor. + * * @throws UnsupportedVirtualizerFormatException Libvirt XML configuration cannot be processed. */ public QemuMetaData( List<OperatingSystem> osList, File file ) throws UnsupportedVirtualizerFormatException @@ -291,17 +292,44 @@ public class QemuMetaData extends try { // read and parse Libvirt domain XML configuration document this.vmConfig = new Domain( file ); - } catch ( LibvirtXmlDocumentException e ) { - throw new UnsupportedVirtualizerFormatException( e.getLocalizedMessage() ); - } catch ( LibvirtXmlSerializationException e ) { + } catch ( LibvirtXmlDocumentException | LibvirtXmlSerializationException | LibvirtXmlValidationException e ) { throw new UnsupportedVirtualizerFormatException( e.getLocalizedMessage() ); - } catch ( LibvirtXmlValidationException e ) { + } + + // parse VM config and initialize fields of QemuMetaData class + this.parseVmConfig(); + } + + /** + * Creates new virtual machine configuration (managed by Libvirt) for the QEMU hypervisor. + * + * @param osList list of operating systems. + * @param vmContent file content for the QEMU hypervisor. + * @param length number of bytes of the file content. + * + * @throws UnsupportedVirtualizerFormatException Libvirt XML configuration cannot be processed. + */ + public QemuMetaData( List<OperatingSystem> osList, byte[] vmContent, int length ) + throws UnsupportedVirtualizerFormatException + { + super( osList ); + + try { + // read and parse Libvirt domain XML configuration document + this.vmConfig = new Domain( new String( vmContent ) ); + } catch ( LibvirtXmlDocumentException | LibvirtXmlSerializationException | LibvirtXmlValidationException e ) { throw new UnsupportedVirtualizerFormatException( e.getLocalizedMessage() ); } - // register virtual hardware models for graphical editing of virtual devices (GPU, sound, USB, ...) - this.registerVirtualHW(); + // parse VM config and initialize fields of QemuMetaData class + this.parseVmConfig(); + } + /** + * Parses Libvirt domain XML configuration to initialize QEMU metadata. + */ + private void parseVmConfig() + { // set display name of VM this.displayName = vmConfig.getName(); diff --git a/src/main/java/org/openslx/vm/VboxMetaData.java b/src/main/java/org/openslx/vm/VboxMetaData.java index a6ac14d..326291b 100644 --- a/src/main/java/org/openslx/vm/VboxMetaData.java +++ b/src/main/java/org/openslx/vm/VboxMetaData.java @@ -120,7 +120,6 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta, private void init() { - registerVirtualHW(); displayName = config.getDisplayName(); setOs( config.getOsName() ); this.isMachineSnapshot = config.isMachineSnapshot(); diff --git a/src/main/java/org/openslx/vm/VmMetaData.java b/src/main/java/org/openslx/vm/VmMetaData.java index 0be07e4..3f4a8b1 100644 --- a/src/main/java/org/openslx/vm/VmMetaData.java +++ b/src/main/java/org/openslx/vm/VmMetaData.java @@ -252,6 +252,9 @@ public abstract class VmMetaData<T, U, V, W, X> public VmMetaData( List<OperatingSystem> osList ) { this.osList = osList; + + // register virtual hardware models for graphical editing of virtual devices (GPU, sound, USB, ...) + this.registerVirtualHW(); } /** @@ -319,14 +322,15 @@ public abstract class VmMetaData<T, U, V, W, X> } try { return new QemuMetaData( osList, file ); - } catch ( Exception e ) { - LOGGER.info( "Not a Qemu file", e ); + } catch ( UnsupportedVirtualizerFormatException e ) { + LOGGER.info( "Not a Libvirt file", e ); } try { return new DockerMetaDataDummy(osList, file); } catch ( Exception e ) { LOGGER.info( "Not a tar.gz file, for docker container", e ); } + LOGGER.error( "Could not detect any known virtualizer format" ); return null; } @@ -340,29 +344,31 @@ public abstract class VmMetaData<T, U, V, W, X> * @return VmMetaData object representing the relevant parts of the given machine description * @throws IOException */ - public static VmMetaData<?, ?, ?, ?, ?> getInstance( List<OperatingSystem> osList, byte[] vmContent, int length ) throws IOException + public static VmMetaData<?, ?, ?, ?, ?> getInstance( List<OperatingSystem> osList, byte[] vmContent, int length ) + throws IOException { - Map<String, Exception> exceptions = new HashMap<>(); try { return new VmwareMetaData( osList, vmContent, length ); } catch ( UnsupportedVirtualizerFormatException e ) { - exceptions.put( "Not a VMware file", e ); + LOGGER.info( "Not a VMware file", e ); } try { return new VboxMetaData( osList, vmContent, length ); } catch ( UnsupportedVirtualizerFormatException e ) { - exceptions.put( "Not a VirtualBox file", e ); + LOGGER.info( "Not a VirtualBox file", e ); + } + try { + return new QemuMetaData( osList, vmContent, length ); + } catch ( UnsupportedVirtualizerFormatException e ) { + LOGGER.info( "Not a Libvirt file", e ); } try { - return new DockerMetaDataDummy(osList, vmContent, length); - } catch (UnsupportedVirtualizerFormatException e) { - exceptions.put( "Not tar.gz file for DockerMetaDataDummy ", e); + return new DockerMetaDataDummy( osList, vmContent, length ); + } catch ( UnsupportedVirtualizerFormatException e ) { + LOGGER.info( "Not a tar.gz file, for docker container", e ); } - // TODO QEmu -- hack above expects qcow2 file, so we can't do anything here yet + LOGGER.error( "Could not detect any known virtualizer format" ); - for ( Entry<String, Exception> e : exceptions.entrySet() ) { - LOGGER.error( e.getKey(), e.getValue() ); - } return null; } diff --git a/src/main/java/org/openslx/vm/VmwareMetaData.java b/src/main/java/org/openslx/vm/VmwareMetaData.java index 9bbe581..cebff17 100644 --- a/src/main/java/org/openslx/vm/VmwareMetaData.java +++ b/src/main/java/org/openslx/vm/VmwareMetaData.java @@ -136,8 +136,6 @@ public class VmwareMetaData extends VmMetaData<VmWareSoundCardMeta, VmWareDDAcce private void init() { - registerVirtualHW(); - for ( Entry<String, ConfigEntry> entry : config.entrySet() ) { handleLoadEntry( entry ); } |