summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorVictor Mocanu2017-10-06 16:05:34 +0200
committerVictor Mocanu2017-10-06 16:05:34 +0200
commit64138d179bf0d9d2a0a1bd288ed91609293a0c7d (patch)
tree5b28be69b3f3e29a7faed2626d3f5b05f1613e12 /src/main
parent[VBox] improved the create new tag and insert attribute functions (diff)
downloadmaster-sync-shared-64138d179bf0d9d2a0a1bd288ed91609293a0c7d.tar.gz
master-sync-shared-64138d179bf0d9d2a0a1bd288ed91609293a0c7d.tar.xz
master-sync-shared-64138d179bf0d9d2a0a1bd288ed91609293a0c7d.zip
[VBox] added new uuid when downloading vm from server
uuid is now writen in the vdi too
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/openslx/util/vm/DiskImage.java3
-rw-r--r--src/main/java/org/openslx/util/vm/VboxConfig.java10
-rw-r--r--src/main/java/org/openslx/util/vm/VboxMetaData.java71
-rw-r--r--src/main/java/org/openslx/util/vm/VmMetaData.java72
-rw-r--r--src/main/java/org/openslx/util/vm/VmwareConfig.java35
-rw-r--r--src/main/java/org/openslx/util/vm/VmwareMetaData.java53
6 files changed, 159 insertions, 85 deletions
diff --git a/src/main/java/org/openslx/util/vm/DiskImage.java b/src/main/java/org/openslx/util/vm/DiskImage.java
index 7590c6d..a721bd7 100644
--- a/src/main/java/org/openslx/util/vm/DiskImage.java
+++ b/src/main/java/org/openslx/util/vm/DiskImage.java
@@ -8,9 +8,9 @@ import java.io.RandomAccessFile;
import org.openslx.bwlp.thrift.iface.Virtualizer;
import org.openslx.util.Util;
+
public class DiskImage
{
-
/**
* Big endian representation of the 4 bytes 'KDMV'
*/
@@ -101,6 +101,7 @@ public class DiskImage
this.subFormat = "";
this.hwVersion = 0;
return;
+
}
}
throw new UnknownImageFormatException();
diff --git a/src/main/java/org/openslx/util/vm/VboxConfig.java b/src/main/java/org/openslx/util/vm/VboxConfig.java
index a7c0e00..76c4e12 100644
--- a/src/main/java/org/openslx/util/vm/VboxConfig.java
+++ b/src/main/java/org/openslx/util/vm/VboxConfig.java
@@ -5,15 +5,10 @@ import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
-import java.util.Map;
-import java.util.TreeMap;
-import javax.annotation.processing.ProcessingEnvironment;
-import javax.swing.plaf.basic.BasicToolBarUI.DockingListener;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.soap.Text;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
@@ -25,12 +20,7 @@ import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
-import org.apache.commons.logging.Log;
import org.apache.log4j.Logger;
-import org.apache.log4j.varia.StringMatchFilter;
-import org.junit.runners.ParentRunner;
-import org.openslx.util.vm.VmwareConfig.ConfigEntry;
-import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
diff --git a/src/main/java/org/openslx/util/vm/VboxMetaData.java b/src/main/java/org/openslx/util/vm/VboxMetaData.java
index 60e760a..40f9f4d 100644
--- a/src/main/java/org/openslx/util/vm/VboxMetaData.java
+++ b/src/main/java/org/openslx/util/vm/VboxMetaData.java
@@ -2,10 +2,11 @@ package org.openslx.util.vm;
import java.io.File;
import java.io.IOException;
+import java.io.RandomAccessFile;
import java.nio.charset.StandardCharsets;
import java.util.List;
+import java.util.UUID;
-import javax.print.attribute.standard.PrinterMessageFromOperator;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
@@ -15,11 +16,8 @@ import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.log4j.Logger;
-import org.apache.log4j.rewrite.ReflectionRewritePolicy;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.bwlp.thrift.iface.Virtualizer;
-import org.w3c.dom.Node;
-
public class VboxMetaData extends VmMetaData
{
@@ -43,7 +41,7 @@ public class VboxMetaData extends VmMetaData
this.config = new VboxConfig( vmContent, length );
setTypeOf();
init();
-
+
}
private void init()
@@ -100,9 +98,58 @@ public class VboxMetaData extends VmMetaData
}
@Override
- public boolean addHddTemplate( String diskImagePath, String hddMode, String redoDir )
+ public boolean addHddTemplate( String diskImage, String hddMode, String redoDir ) {
+ config.changeAttribute( "HardDisk", "location", diskImage );
+ return true;
+ }
+
+ @Override
+ public boolean addHddTemplate( File diskImage, String hddMode, String redoDir )
{
+ String diskImagePath = diskImage.getName();
config.changeAttribute( "HardDisk", "location", diskImagePath );
+
+ UUID newuuid = UUID.randomUUID();
+ LOGGER.debug( newuuid );
+
+ // patching the new uuid in the vbox config file here
+ String vboxUUid = "{" + newuuid.toString() + "}";
+ config.changeAttribute( "HardDisk", "uuid", vboxUUid );
+ config.changeAttribute( "Image", "uuid", vboxUUid );
+
+ Long longl = newuuid.getLeastSignificantBits();
+ Long longr = newuuid.getMostSignificantBits();
+
+ byte l56 = (byte) (longl >>> 56);
+ byte l48 = (byte) (longl >>> 48);
+ byte l40 = (byte) (longl >>> 40);
+ byte l32 = (byte) (longl >>> 32);
+ byte l24 = (byte) (longl >>> 24);
+ byte l16 = (byte) (longl >>> 16);
+ byte l8 = (byte) (longl >>> 8);
+ byte l0 = (byte) (longl >>> 0);
+
+ // switcharoo next 4
+ byte r56 = (byte) (longr >>> 32);
+ byte r48 = (byte) (longr >>> 40);
+ byte r40 = (byte) (longr >>> 48);
+ byte r32 = (byte) (longr >>> 56);
+ // switcharoo next 2
+ byte r24 = (byte) (longr >>> 16);
+ byte r16 = (byte) (longr >>> 24);
+ // switcharoo next 2
+ byte r8 = (byte) (longr >>> 0);
+ byte r0 = (byte) (longr >>> 8);
+
+ byte[] bytesToWrite = {r56, r48, r40, r32, r24, r16, r8, r0, l56, l48, l40, l32, l24, l16, l8, l0};
+
+ try( RandomAccessFile file = new RandomAccessFile( diskImage, "rw" ) ) {
+
+ file.seek( 392 );
+ file.write( bytesToWrite, 0, 16 );
+ } catch (Exception e) {
+ LOGGER.warn( "could not patch new uuid in the vdi", e );
+ }
return true;
}
@@ -112,8 +159,9 @@ public class VboxMetaData extends VmMetaData
config.addNewNode( "Adapter", "NAT", false );
return true;
}
-
- public void reWrite() {
+
+ public void reWrite()
+ {
try {
WriteToFile();
} catch ( TransformerFactoryConfigurationError | TransformerException e ) {
@@ -121,11 +169,12 @@ public class VboxMetaData extends VmMetaData
e.printStackTrace();
}
}
+
@Override
public void setOs( String vendorOsId )
{
// TODO Auto-generated method stub
-
+
}
@Override
@@ -145,11 +194,11 @@ public class VboxMetaData extends VmMetaData
@Override
public void addFloppy( int index, String image, boolean readOnly )
{
-
+
if ( image == null ) {
} else {
}
-
+
}
@Override
diff --git a/src/main/java/org/openslx/util/vm/VmMetaData.java b/src/main/java/org/openslx/util/vm/VmMetaData.java
index 27b0983..2636581 100644
--- a/src/main/java/org/openslx/util/vm/VmMetaData.java
+++ b/src/main/java/org/openslx/util/vm/VmMetaData.java
@@ -8,10 +8,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
-import javax.print.attribute.standard.PrinterMessageFromOperator;
-import javax.swing.JOptionPane;
-
-import org.apache.log4j.FileAppender;
import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.bwlp.thrift.iface.Virtualizer;
@@ -27,12 +23,14 @@ public abstract class VmMetaData
* Helper types
*/
- public static enum TypeOf {
+ public static enum TypeOf
+ {
VMX,
VBOX;
}
-
+
public static TypeOf typeOf = null;
+
public static enum DriveBusType
{
SCSI,
@@ -126,7 +124,6 @@ public abstract class VmMetaData
protected final void setOs( String virtId, String virtOsId )
{
OperatingSystem lazyMatch = null;
- boolean x = false;
for ( OperatingSystem os : osList ) {
if ( os.getVirtualizerOsId() == null )
continue;
@@ -135,77 +132,75 @@ public abstract class VmMetaData
continue;
if ( entry.getKey().equals( virtId ) ) {
this.os = os;
- x = true;
return;
} else {
lazyMatch = os;
}
}
}
-
- /*if(!x) {
- //LOGGER.debug( "os with " + virtId + " " + virtOsId + " is not in list");
- }*/
this.os = lazyMatch;
}
-
+
public abstract void reWrite();
+
public abstract Virtualizer getVirtualizer();
-
- public abstract void enableUsb(boolean enabled);
-
+
+ public abstract void enableUsb( boolean enabled );
+
/**
* Apply config options that are desired when locally editing a VM.
* for vmware, this disables automatic DPI scaling of the guest.
*/
public abstract void applySettingsForLocalEdit();
-
+
// meta object needed when reading vm from file
- public static VmMetaData getInstance(List<OperatingSystem> osList, File file) throws IOException {
+ public static VmMetaData getInstance( List<OperatingSystem> osList, File file ) throws IOException
+ {
VmMetaData meta = null;
try {
- meta = new VmwareMetaData(osList, file);
+ meta = new VmwareMetaData( osList, file );
} catch ( UnsupportedVirtualizerFormatException e ) {
- LOGGER.debug( "datei war nicht .vmx; versuche mit VBox");
+ LOGGER.debug( "datei war nicht .vmx; versuche mit VBox" );
try {
- meta = new VboxMetaData(osList, file);
- }
- catch (UnsupportedVirtualizerFormatException ex) {
- LOGGER.debug( "datei war nicht .vbox; unterbrochen!" , ex);
+ meta = new VboxMetaData( osList, file );
+ } catch ( UnsupportedVirtualizerFormatException ex ) {
+ LOGGER.debug( "datei war nicht .vbox; unterbrochen!", ex );
// TODO ok so or throw new IOException?
}
}
- if (meta != null) {
+ if ( meta != null ) {
return meta;
}
return null;
}
-
+
// meta object needed when reading from configarray
- 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
+ {
+
VmMetaData meta = null;
try {
meta = new VmwareMetaData( osList, vmContent, length );
- } catch (UnsupportedVirtualizerFormatException e) {
+ } catch ( UnsupportedVirtualizerFormatException e ) {
LOGGER.debug( "machine Description entspricht nicht vmx format; versuche mit VBox" );
try {
meta = new VboxMetaData( osList, vmContent, length );
- } catch (UnsupportedVirtualizerFormatException ex) {
- LOGGER.debug( "machine Description entspricht nicht vbox format ); unterbrochen!", ex);
+ } catch ( UnsupportedVirtualizerFormatException ex ) {
+ LOGGER.debug( "machine Description entspricht nicht vbox format ); unterbrochen!", ex );
}
- if (meta != null) {
+ if ( meta != null ) {
return meta;
}
return null;
}
-
+
return null;
}
+ public abstract boolean addHddTemplate( File diskImage, String hddMode, String redoDir );
public abstract boolean addHddTemplate( String diskImagePath, String hddMode, String redoDir );
-
+
public abstract boolean addDefaultNat();
public abstract void setOs( String vendorOsId );
@@ -217,10 +212,11 @@ public abstract class VmMetaData
public abstract void addFloppy( int index, String image, boolean readOnly );
public abstract boolean addCdrom( String image );
-
- public abstract void setTypeOf ( );
-
- public TypeOf getTypeOf () {
+
+ public abstract void setTypeOf();
+
+ public TypeOf getTypeOf()
+ {
return typeOf;
}
}
diff --git a/src/main/java/org/openslx/util/vm/VmwareConfig.java b/src/main/java/org/openslx/util/vm/VmwareConfig.java
index 38db8a8..ab180e0 100644
--- a/src/main/java/org/openslx/util/vm/VmwareConfig.java
+++ b/src/main/java/org/openslx/util/vm/VmwareConfig.java
@@ -74,7 +74,7 @@ public class VmwareConfig
}
// function is used for both .vmx and .vmdk files
- private void init( byte[] vmxContent, int length) throws UnsupportedVirtualizerFormatException
+ private void init( byte[] vmxContent, int length ) throws UnsupportedVirtualizerFormatException
{
try {
boolean isValid = false;
@@ -82,31 +82,32 @@ public class VmwareConfig
String line;
while ( ( line = reader.readLine() ) != null ) {
KeyValuePair entry = parse( line );
-
-
+
if ( entry != null ) {
// TODO ask Simon which key is best for the check
- if ( entry.key.equals("virtualHW.version") || entry.key.equals("ddb.virtualHWVersion")) {
+ if ( entry.key.equals( "virtualHW.version" ) || entry.key.equals( "ddb.virtualHWVersion" ) ) {
isValid = true;
- }
- set( entry.key, unescape( entry.value ) );
+ }
+ set( entry.key, unescape( entry.value ) );
}
}
- if (!isValid) {
- throw new UnsupportedVirtualizerFormatException("not Vmware image format");
+ if ( !isValid ) {
+ throw new UnsupportedVirtualizerFormatException( "not Vmware image format" );
}
} catch ( IOException e ) {
LOGGER.warn( "Exception when loading vmx from byte array (how!?)", e );
}
}
- public static BufferedReader getVmxReader( byte[] vmxContent, int length ) throws IOException {
- Charset cs = getCharset(vmxContent, length);
+ public static BufferedReader getVmxReader( byte[] vmxContent, int length ) throws IOException
+ {
+ Charset cs = getCharset( vmxContent, length );
return new BufferedReader( new InputStreamReader( new ByteArrayInputStream( vmxContent, 0, length ), cs ) );
}
- public static Charset getCharset( byte[] vmxContent, int length ) {
+ public static Charset getCharset( byte[] vmxContent, int length )
+ {
String csName = detectCharset( new ByteArrayInputStream( vmxContent, 0, length ) );
Charset cs = null;
try {
@@ -156,10 +157,8 @@ public class VmwareConfig
return entries.entrySet();
}
- private static final Pattern settingMatcher1 = Pattern.compile( "^\\s*(#?[a-z0-9\\.\\:_]+)\\s*=\\s*\"(.*)\"\\s*$",
- Pattern.CASE_INSENSITIVE );
- private static final Pattern settingMatcher2 = Pattern.compile( "^\\s*(#?[a-z0-9\\.\\:_]+)\\s*=\\s*([^\"]*)\\s*$",
- Pattern.CASE_INSENSITIVE );
+ private static final Pattern settingMatcher1 = Pattern.compile( "^\\s*(#?[a-z0-9\\.\\:_]+)\\s*=\\s*\"(.*)\"\\s*$", Pattern.CASE_INSENSITIVE );
+ private static final Pattern settingMatcher2 = Pattern.compile( "^\\s*(#?[a-z0-9\\.\\:_]+)\\s*=\\s*([^\"]*)\\s*$", Pattern.CASE_INSENSITIVE );
private static KeyValuePair parse( String line )
{
@@ -170,8 +169,7 @@ public class VmwareConfig
if ( !matcher.matches() ) {
return null;
}
- return new KeyValuePair(
- matcher.group( 1 ), matcher.group( 2 ) );
+ return new KeyValuePair( matcher.group( 1 ), matcher.group( 2 ) );
}
@@ -213,8 +211,7 @@ public class VmwareConfig
StringBuilder sb = new StringBuilder( 300 );
for ( Entry<String, ConfigEntry> entry : entries.entrySet() ) {
ConfigEntry value = entry.getValue();
- if ( ( !filteredRequired || value.forFiltered ) &&
- ( !generatedRequired || value.forGenerated ) ) {
+ if ( ( !filteredRequired || value.forFiltered ) && ( !generatedRequired || value.forGenerated ) ) {
sb.append( entry.getKey() );
sb.append( " = \"" );
sb.append( value.getEscaped() );
diff --git a/src/main/java/org/openslx/util/vm/VmwareMetaData.java b/src/main/java/org/openslx/util/vm/VmwareMetaData.java
index 4a5266c..48bbe79 100644
--- a/src/main/java/org/openslx/util/vm/VmwareMetaData.java
+++ b/src/main/java/org/openslx/util/vm/VmwareMetaData.java
@@ -1,6 +1,5 @@
package org.openslx.util.vm;
-import java.io.Console;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -11,13 +10,10 @@ import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import javax.sql.ConnectionEventListener;
-
import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.bwlp.thrift.iface.Virtualizer;
import org.openslx.util.Util;
-import org.openslx.util.vm.VmMetaData.TypeOf;
import org.openslx.util.vm.VmwareConfig.ConfigEntry;
public class VmwareMetaData extends VmMetaData
@@ -172,7 +168,52 @@ public class VmwareMetaData extends VmMetaData
device.present = Boolean.parseBoolean( value );
}
}
+
+ @Override
+ public boolean addHddTemplate( File diskImage, String hddMode, String redoDir) {
+ String diskImagePath = diskImage.getName();
+ DriveBusType bus;
+ try {
+ bus = DriveBusType.valueOf( config.get( "#SLX_HDD_BUS" ) );
+ } catch ( Exception e ) {
+ LOGGER.warn( "Unknown bus type: " + config.get( "#SLX_HDD_BUS" ) + ". Cannot add hdd config." );
+ return false;
+ }
+ String chipset = config.get( "#SLX_HDD_CHIP" );
+ String prefix;
+ switch ( bus ) {
+ case IDE:
+ prefix = "ide0:0";
+ addFiltered( "ide0.present", "TRUE" );
+ break;
+ case SATA:
+ // Cannot happen?... use lsisas1068
+ case SCSI:
+ prefix = "scsi0:0";
+ addFiltered( "scsi0.present", "TRUE" );
+ if ( chipset != null ) {
+ addFiltered( "scsi0.virtualDev", chipset );
+ }
+ break;
+ default:
+ LOGGER.warn( "Unknown HDD bus type: " + bus.toString() );
+ return false;
+ }
+ // Gen
+ addFiltered( prefix + ".present", "TRUE" );
+ addFiltered( prefix + ".deviceType", "disk" );
+ addFiltered( prefix + ".fileName", diskImagePath );
+ if ( hddMode != null ) {
+ addFiltered( prefix + ".mode", hddMode );
+ addFiltered( prefix + ".redo", "" );
+ addFiltered( prefix + ".redoLogDir", redoDir );
+ }
+ config.remove( "#SLX_HDD_BUS" );
+ config.remove( "#SLX_HDD_CHIP" );
+ return true;
+ }
+ @Override
public boolean addHddTemplate( String diskImagePath, String hddMode, String redoDir )
{
DriveBusType bus;
@@ -555,7 +596,7 @@ public class VmwareMetaData extends VmMetaData
}
return EthernetDevType.AUTO;
}
-
+
@Override
public void setTypeOf()
{
@@ -566,6 +607,6 @@ public class VmwareMetaData extends VmMetaData
public void reWrite()
{
// TODO Auto-generated method stub
-
+
}
}