summaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
authorVictor Mocanu2018-03-28 12:28:12 +0200
committerVictor Mocanu2018-03-28 12:28:12 +0200
commitc79bc135bde56ca184e2552bb9d68578e4796ce3 (patch)
tree30d31add480ca9812d384772e46012be9fd62c1a /src/main/java/org
parent[vbox] ensure <hardware/> has a uuid (diff)
downloadmaster-sync-shared-c79bc135bde56ca184e2552bb9d68578e4796ce3.tar.gz
master-sync-shared-c79bc135bde56ca184e2552bb9d68578e4796ce3.tar.xz
master-sync-shared-c79bc135bde56ca184e2552bb9d68578e4796ce3.zip
[VBox] added new, more elegant way to add placeholders
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/openslx/util/vm/VboxConfig.java68
-rw-r--r--src/main/java/org/openslx/util/vm/VboxMetaData.java14
2 files changed, 52 insertions, 30 deletions
diff --git a/src/main/java/org/openslx/util/vm/VboxConfig.java b/src/main/java/org/openslx/util/vm/VboxConfig.java
index eab20cb..63367e0 100644
--- a/src/main/java/org/openslx/util/vm/VboxConfig.java
+++ b/src/main/java/org/openslx/util/vm/VboxConfig.java
@@ -53,6 +53,27 @@ public class VboxConfig
// a black list of sorts of tags that need to be removed from the .vbox file
private static String[] blackList = { "HID", "USB", "ExtraData", "Adapter", "GuestProperties", "LPT", "StorageController", "FloppyImages", "DVDImages", "AttachedDevice" };
+ public static enum PlaceHolder
+ {
+ FLOPPYUUID("%OpenSLX_FloppyUUID%"),
+ FLOPPYLOCATION("%OpenSLX_Floppy_Location%"),
+ CPU("%OpenSLX_CPU%"),
+ MEMORY("%OpenSLX_MEMORY%"),
+ MACHINEUUID("%OpenSLX_MUUID%"),
+ NETWORKMAC("%OpenSLX_Networkcard_MACAddress%"),
+ HDDLOCATION("%OpenSLX_HDD_Location%"),
+ HDDUUID("%OpenSLX_HDDUUID_");
+ private final String holderName;
+ private PlaceHolder(String name)
+ {
+ this.holderName = name;
+ }
+
+ public String holderName()
+ {
+ return holderName;
+ }
+ }
/**
* constructor with input xml file
* used to set the doc variable of this class when creating vm
@@ -144,7 +165,7 @@ public class VboxConfig
}
private void ensureHardwareUuid() throws XPathExpressionException {
- NodeList hwNodes = findANode( "Hardware" );
+ NodeList hwNodes = findNodes( "Hardware" );
int count = hwNodes.getLength();
// we will need the machine uuid, so get it
String machineUuid = xPath.compile( "/VirtualBox/Machine/@uuid" ).evaluate( this.doc );
@@ -179,10 +200,11 @@ public class VboxConfig
*/
private boolean checkForPlaceholders()
{
- NodeList hdds = findANode( "HardDisk" );
+ NodeList hdds = findNodes( "HardDisk" );
for ( int i = 0; i < hdds.getLength(); i++ ) {
Element hdd = (Element)hdds.item( i );
- if ( hdd.getAttribute( "location" ).equals( "#OpenSLX_HDD_place_holder" ) ) {
+ // TODO
+ if ( hdd.getAttribute( "location" ).equals( PlaceHolder.HDDLOCATION.holderName() ) ) {
return true;
}
}
@@ -260,34 +282,34 @@ public class VboxConfig
public void addPlaceHolders()
{
// placeholder for the MACAddress
- changeAttribute( "Adapter", "MACAddress", "#OpenSLX_Networkcard_MACAddress_place_holder" );
+ changeAttribute( "Adapter", "MACAddress", PlaceHolder.NETWORKMAC.holderName() );
// placeholder for the machine uuid
- changeAttribute( "Machine", "uuid", "#OpenSLX_MUUID_place_holder" );
+ changeAttribute( "Machine", "uuid", PlaceHolder.MACHINEUUID.holderName() );
// placeholder for the location of the virtual hdd
- changeAttribute( "HardDisk", "location", "#OpenSLX_HDD_place_holder" );
+ changeAttribute( "HardDisk", "location", PlaceHolder.HDDLOCATION.holderName() );
// placeholder for the memory
- changeAttribute( "Memory", "RAMSize", "#OpenSLX_MEMORY_place_holder" );
+ changeAttribute( "Memory", "RAMSize", PlaceHolder.MEMORY.holderName() );
// placeholder for the CPU
- changeAttribute( "CPU", "count", "#OpenSLX_CPU_place_holder" );
+ changeAttribute( "CPU", "count", PlaceHolder.CPU.holderName() );
// add placeholder for the uuid of the virtual harddrive.
// must be added on 2 positions...in the HardDisk tag and the attachedDevice tag
// first find the uuid
- NodeList hdds = findANode( "HardDisk" );
+ NodeList hdds = findNodes( "HardDisk" );
for ( int i = 0; i < hdds.getLength(); i++ ) {
- Element hdd = (Element)findANode( "HardDisk" ).item( i );
+ Element hdd = (Element)findNodes( "HardDisk" ).item( i );
String uuid = hdd.getAttribute( "uuid" );
- hdd.setAttribute( "uuid", "#OpenSLX_HDDUUID_" + i + "_placeholder" );
- NodeList images = findANode( "Image" );
+ hdd.setAttribute( "uuid", PlaceHolder.HDDUUID.holderName() + i + "%" );
+ NodeList images = findNodes( "Image" );
Element image;
for ( int j = 0; j < images.getLength(); j++ ) {
if ( ( (Element)images.item( j ) ).getAttribute( "uuid" ).equals( uuid ) ) {
image = (Element)images.item( j );
- image.setAttribute( "uuid", "#OpenSLX_HDDUUID_" + i + "_placeholder" );
+ image.setAttribute( "uuid", PlaceHolder.HDDUUID.holderName() + i + "%" );
break;
}
}
@@ -295,14 +317,14 @@ public class VboxConfig
}
/**
- * Function used to find a node in the document
- * Function returnes a NodeList of Nodes...not just a Node...even when the wanted Node a single
- * Node is you get a NodeList with just one element
+ * Function used to find nodes in the document
+ * Function returnes a NodeList of Nodes...not just a Node...even when the wanted Node is a single
+ * Node, you get a NodeList with just one element
*
* @param targetTag as String
* @return nodes as NodeList
*/
- public NodeList findANode( String targetTag )
+ public NodeList findNodes( String targetTag )
{
String path = ".//" + targetTag;
XPathExpression expr;
@@ -318,7 +340,7 @@ public class VboxConfig
}
/**
- * Function uses the findANode function to narrow down the wanted node using 1 attribute and
+ * Function uses the findNodes function to narrow down the wanted node using 1 attribute and
* its value
*
* @param targetTag
@@ -326,11 +348,11 @@ public class VboxConfig
* @param value0
* @return
*/
- public Node findANode( String targetTag, String targetAttr0, String value0 )
+ public Node findNode( String targetTag, String targetAttr0, String value0 )
{
Node returnNode = null;
- NodeList foundNodes = findANode( targetTag );
+ NodeList foundNodes = findNodes( targetTag );
for ( int i = 0; i < foundNodes.getLength(); i++ ) {
Element node = (Element)foundNodes.item( i );
@@ -367,7 +389,7 @@ public class VboxConfig
*/
public void changeAttribute( String targetTag, String targetAttr, String newValue, String refAttr, String refVal )
{
- NodeList nodes = findANode( targetTag );
+ NodeList nodes = findNodes( targetTag );
for ( int i = 0; i < nodes.getLength(); i++ ) {
Element element = (Element)nodes.item( i );
@@ -409,7 +431,7 @@ public class VboxConfig
public Node addNewNode( String nameOfParent, String nameOfnewNode, boolean oneLiner, String refAttr, String refVal )
{
Node parent = null;
- NodeList posibleParents = findANode( nameOfParent );
+ NodeList posibleParents = findNodes( nameOfParent );
Element newNode;
try {
if ( posibleParents.getLength() > 1 ) {
@@ -470,7 +492,7 @@ public class VboxConfig
*/
public void disableUsb()
{
- Node usb = findANode( "USB" ).item( 0 );
+ Node usb = findNodes( "USB" ).item( 0 );
removeNode( usb );
}
diff --git a/src/main/java/org/openslx/util/vm/VboxMetaData.java b/src/main/java/org/openslx/util/vm/VboxMetaData.java
index 01a4970..3aa7491 100644
--- a/src/main/java/org/openslx/util/vm/VboxMetaData.java
+++ b/src/main/java/org/openslx/util/vm/VboxMetaData.java
@@ -227,7 +227,7 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta,
public void addFloppy( int index, String image, boolean readOnly )
{
- Node somenode = config.findANode( "StorageController", "name", "Floppy" );
+ Node somenode = config.findNode( "StorageController", "name", "Floppy" );
if ( somenode == null ) {
Element controller = (Element)config.addNewNode( "StorageControllers", "StorageController", false );
controller.setAttribute( "name", "Floppy" );
@@ -246,11 +246,11 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta,
attachedDev = (Element)config.addNewNode( "StorageController", "AttachedDevice", false, "name", "Floppy" );
Element imageTag = (Element)config.addNewNode( "AttachedDevice", "Image", true, "type", "Floppy" );
- imageTag.setAttribute( "uuid", "#OpenSLX_FloppyUUID_place_holder" );
+ imageTag.setAttribute( "uuid", VboxConfig.PlaceHolder.FLOPPYUUID.holderName() );
config.addNewNode( "MediaRegistry", "FloppyImages", false );
Element floppyImageTag = (Element)config.addNewNode( "FloppyImages", "Image", true );
- floppyImageTag.setAttribute( "uuid", "#OpenSLX_FloppyUUID_place_holder" );
- floppyImageTag.setAttribute( "location", "#OpenSLX_FloppyImageLocation_place_holder" );
+ floppyImageTag.setAttribute( "uuid", VboxConfig.PlaceHolder.FLOPPYUUID.holderName() );
+ floppyImageTag.setAttribute( "location", VboxConfig.PlaceHolder.FLOPPYLOCATION.holderName() );
}
attachedDev.setAttribute( "type", "Floppy" );
@@ -286,7 +286,7 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta,
{
// initialize here to type None to avoid all null pointer exceptions thrown for unknown user written sound cards
VmMetaData.SoundCardType returnsct = VmMetaData.SoundCardType.NONE;
- Element x = (Element)config.findANode( "AudioAdapter" ).item( 0 );
+ Element x = (Element)config.findNodes( "AudioAdapter" ).item( 0 );
if ( !x.hasAttribute( "enabled" ) || ( x.hasAttribute( "enabled" ) && x.getAttribute( "enabled" ).equals( "false" ) ) ) {
return returnsct;
} else {
@@ -320,7 +320,7 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta,
public VmMetaData.DDAcceleration getDDAcceleration()
{
VmMetaData.DDAcceleration returndda = null;
- Element x = (Element)config.findANode( "Display" ).item( 0 );
+ Element x = (Element)config.findNodes( "Display" ).item( 0 );
if ( x.hasAttribute( "accelerate3D" ) ) {
if ( x.getAttribute( "accelerate3D" ).equals( "true" ) ) {
returndda = VmMetaData.DDAcceleration.ON;
@@ -365,7 +365,7 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta,
public VmMetaData.EthernetDevType getEthernetDevType( int cardIndex )
{
VmMetaData.EthernetDevType returnedt = VmMetaData.EthernetDevType.NONE;
- Element x = (Element)config.findANode( "Adapter" ).item( 0 );
+ Element x = (Element)config.findNodes( "Adapter" ).item( 0 );
if ( !x.hasAttribute( "enabled" ) || ( x.hasAttribute( "enabled" ) && x.getAttribute( "enabled" ).equals( "false" ) ) ) {
return returnedt;
} else {