diff options
author | Victor Mocanu | 2018-03-28 12:28:12 +0200 |
---|---|---|
committer | Victor Mocanu | 2018-03-28 12:28:12 +0200 |
commit | c79bc135bde56ca184e2552bb9d68578e4796ce3 (patch) | |
tree | 30d31add480ca9812d384772e46012be9fd62c1a /src/main/java/org/openslx/util/vm/VboxConfig.java | |
parent | [vbox] ensure <hardware/> has a uuid (diff) | |
download | master-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/openslx/util/vm/VboxConfig.java')
-rw-r--r-- | src/main/java/org/openslx/util/vm/VboxConfig.java | 68 |
1 files changed, 45 insertions, 23 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 ); } |