From 8deb5e4ec522b0e6ae8548ba1a3abc72eb85f4f3 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 25 Apr 2018 12:18:55 +0200 Subject: [vbox] more refactoring Keep for now, booting from the HDD should be forced in run-virt. Also note that virtualbox only allows controller named Floppy, SATA, IDE, SCSI etc. multiple entries with the same name are ignored (the first one takes precedence). Controller named differently are just ignored. Upon shutdown, virtualbox cleans it up from the xml. So assuming the uploader actually started and shut the machine down, we can be safe to assume that controller nodes are unique. Nevertheless we try to at least log these cases, to debug those corner cases should they occur. Thanks for reading that far :P --- .../java/org/openslx/util/vm/VboxMetaData.java | 92 ++++++++++++++-------- 1 file changed, 60 insertions(+), 32 deletions(-) (limited to 'src/main/java/org/openslx/util/vm/VboxMetaData.java') diff --git a/src/main/java/org/openslx/util/vm/VboxMetaData.java b/src/main/java/org/openslx/util/vm/VboxMetaData.java index f7378be..c3f0a43 100644 --- a/src/main/java/org/openslx/util/vm/VboxMetaData.java +++ b/src/main/java/org/openslx/util/vm/VboxMetaData.java @@ -101,8 +101,6 @@ public class VboxMetaData extends VmMetaData to floppy device." ); + return; + } + floppyController.setAttribute( "name", "Floppy" ); + floppyController.setAttribute( "type", "I82078" ); + floppyController.setAttribute( "PortCount", "1" ); + floppyController.setAttribute( "useHostIOCache", "true" ); + floppyController.setAttribute( "Bootable", "false" ); } + // virtualbox only allows one controller per type + if ( matches.getLength() > 1 ) { + LOGGER.error( "Multiple floppy controllers detected, this should never happen! " ); + return; + } + // so if we had any matches, we know we have exactly one + if ( floppyController == null ) + floppyController = (Element)matches.item( 0 ); + + // add the floppy device + Element floppyDevice = (Element)config.addNewNode( floppyController, "AttachedDevice" ); + if ( floppyDevice == null ) { + LOGGER.error( "Failed to add to floppy device." ); + return; + } + floppyDevice.setAttribute( "type", "Floppy" ); + floppyDevice.setAttribute( "hotpluggable", "false" ); + floppyDevice.setAttribute( "port", "0" ); + floppyDevice.setAttribute( "device", Integer.toString( index ) ); - Element attachedDev = (Element)config.addNewNode( "/VirtualBox/Machine/StorageControllers/StorageController[@name='Floppy']", "AttachedDevice" ); - attachedDev.setAttribute( "type", "Floppy" ); - attachedDev.setAttribute( "hotpluggable", "false" ); - attachedDev.setAttribute( "port", "0" ); - attachedDev.setAttribute( "device", Integer.toString( index ) ); - - // now add the image to it, if one was given + // finally add the image to it, if one was given if ( image != null ) { - Element imageTag = (Element)config.addNewNode( "/VirtualBox/Machine/StorageControllers/StorageController[@name='Floppy']", "Image" ); - imageTag.setAttribute( "uuid", VboxConfig.PlaceHolder.FLOPPYUUID.toString() ); - config.addNewNode( "/VirtualBox/Machine/MediaRegistry", "FloppyImages" ); - Element floppyImageTag = (Element)config.addNewNode( "/VirtualBox/Machine/MediaRegistry/FloppyImages", "Image" ); - floppyImageTag.setAttribute( "uuid", VboxConfig.PlaceHolder.FLOPPYUUID.toString() ); - floppyImageTag.setAttribute( "location", VboxConfig.PlaceHolder.FLOPPYLOCATION.toString() ); + Element floppyImage = (Element)config.addNewNode( floppyDevice, "Image" ); + if ( floppyImage == null ) { + LOGGER.error( "Failed to add to floppy device." ); + return; + } + floppyImage.setAttribute( "uuid", VboxConfig.PlaceHolder.FLOPPYUUID.toString() ); + // register the image in the media registry + Element floppyImages = (Element)config.addNewNode( "/VirtualBox/Machine/MediaRegistry", "FloppyImages" ); + if ( floppyImages == null ) { + LOGGER.error( "Failed to add to media registry." ); + return; + } + Element floppyImageReg = (Element)config.addNewNode( "/VirtualBox/Machine/MediaRegistry/FloppyImages", "Image" ); + if ( floppyImageReg == null ) { + LOGGER.error( "Failed to add to floppy images in the media registry." ); + return; + } + floppyImageReg.setAttribute( "uuid", VboxConfig.PlaceHolder.FLOPPYUUID.toString() ); + floppyImageReg.setAttribute( "location", VboxConfig.PlaceHolder.FLOPPYLOCATION.toString() ); } } @Override public boolean addCdrom( String image ) { + // TODO - done in run-virt currently return false; } @Override public boolean addCpuCoreCount( int nrOfCores ) { - config.changeAttribute( "/VirtualBox/Machine/Hardware/CPU", "count", Integer.toString( nrOfCores ) ); - return true; + return config.changeAttribute( "/VirtualBox/Machine/Hardware/CPU", "count", Integer.toString( nrOfCores ) ); } @Override -- cgit v1.2.3-55-g7522